Học liệu

Điều khiển nơron cho động cơ không chỗi than

  • 13/01/2021
  • Học liệu

# include <msp430F2011.h>
; khai bao bien
START EQU BIT0
STOP EQU BIT1
THUAN EQU BIT2
NGHICH EQU BIT3
NHANH EQU BIT4
CHAM EQU BIT5
LED1 EQU BIT6
LED2 EQU BIT7
DELAYBT EQU 5000
DELAYNHANH EQU 6500
DELAYCHAM EQU 3500
; ----------------------------------

RSEG CODE
Reset:
;--------------------------------------
mov.w #WDTPW| WDTHOLD ,& WDTCTL
bis.b #LED1|LED2 ,&P1DIR
; -----quet phim ----------
QUETPHIM:
bit.b #START ,&P1IN
jz quaybinhthuong
JMP QUETPHIM

;-------------------------------------------------

;===============================quay binh thuong
quaybinhthuong:
BIC.B #LED2, &P1OUT
clr.w R1
delaybt1:

inc.w R1
cmp.w #DELAYBT,R1
jne delaybt1
bis.b #LED1,&P1OUT ; led1 sang sau delaybt

clr.w R1
delaybt2:
inc.w R1
cmp.w #DELAYBT,R1
jne delaybt2
bic.b #LED1,&P1OUT ; led2 tat sau delaybt
;------------kiem tra phim--------------
bit.b #STOP, &P1IN ; stop
jz ngung
bit.b #CHAM, &P1IN ; cham bt
jz quaychambt
bit.b #NHANH , &P1IN ; nhanh bt
jz quaynhanhbt
bit.b #NGHICH , P1IN
jz quaynghichbt ;nghich bt
jmp quaybinhthuong

;============================quay chambt
quaychambt:
BIC.B #LED2, &P1OUT
clr.w R1
delaycham1:

inc.w R1
cmp.w #DELAYNHANH,R1
jne delaycham1
bis.b #LED1,&P1OUT

clr.w R1
delaycham2:
inc.w R1
cmp.w #DELAYCHAM,R1
jne delaycham2
bic.b #LED1,&P1OUT
;----------------------------------kiem tra phim
bit.b #STOP ,&P1IN
jz ngung
bit.b #NHANH , &P1IN
jz quaynhanhbt
bit.b #NGHICH, &P1IN
jz quaynghichcham

jmp quaychambt


;=========================================quay nhanh bt
quaynhanhbt:
BIC.B #LED2, &P1OUT
clr.w R1
delaynhanh1:

inc.w R1
cmp.w #DELAYCHAM,R1
jne delaynhanh1
bis.b #LED1,&P1OUT

clr.w R1
delaynhanh2:
inc.w R1
cmp.w #DELAYNHANH,R1
jne delaynhanh2
bic.b #LED1,&P1OUT
;------------------------------kiem tra phim
bit.b #START ,&P1IN
jz quaybinhthuong
bit.b #STOP ,&P1IN
jz ngung
bit.b #CHAM , &P1IN
jz quaychambt
bit.b #NGHICH ,&P1IN
jz quaynghichnhanh
jmp quaynhanhbt

;==============================quay nghich binh thuong
quaynghichbt:
BIC.B #LED1, &P1OUT
clr.w R1
delaynghichbt1:

inc.w R1
cmp.w #DELAYBT,R1
jne delaynghichbt1
bis.b #LED2,&P1OUT ; led1 sang sau delaybt

clr.w R1
delaynghichbt2:
inc.w R1
cmp.w #DELAYBT,R1
jne delaynghichbt2
bic.b #LED2,&P1OUT ; led2 tat sau delaybt
;------------kiem tra phim--------------
bit.b #STOP, &P1IN ; stop
jz ngung
bit.b #CHAM, &P1IN ; cham bt
jz quaynghichcham
bit.b #NHANH , &P1IN ; nhanh bt
jz quaynghichnhanh
bit.b #THUAN , P1IN
jz quaybinhthuong ;nghich bt
jmp quaynghichbt

;============================== quay nghich cham
quaynghichcham:
BIC.B #LED1, &P1OUT
clr.w R1
delaynghichcham1:

inc.w R1
cmp.w #DELAYNHANH,R1
jne delaynghichcham1
bis.b #LED2,&P1OUT

clr.w R1
delaynghichcham2:
inc.w R1
cmp.w #DELAYCHAM,R1
jne delaynghichcham2
bic.b #LED2,&P1OUT
;----------------------------------kiem tra phim
bit.b #THUAN ,&P1IN
jz quaychambt
bit.b #STOP ,&P1IN
jz ngung
bit.b #NHANH , &P1IN
jz quaynghichnhanh
bit.b #CHAM, &P1IN
jz quaynghichbt

jmp quaynghichcham
;================================quay nghich nhanh
quaynghichnhanh:
BIC.B #LED1, &P1OUT
clr.w R1
delaynghichnhanh1:

inc.w R1
cmp.w #DELAYCHAM,R1
jne delaynghichnhanh1
bis.b #LED2,&P1OUT

clr.w R1
delaynghichnhanh2:
inc.w R1
cmp.w #DELAYNHANH,R1
jne delaynghichnhanh2
bic.b #LED2,&P1OUT
;------------------------------kiem tra phim
bit.b #THUAN ,&P1IN
jz quaynhanhbt
bit.b #STOP ,&P1IN
jz ngung
bit.b #CHAM , &P1IN
jz quaynghichbt

jmp quaynghichnhanh


;===============================NHAN NGUNG

ngung:
bic.b #LED1|LED2, &P1OUT
JMP QUETPHIM

 

;------------------------------
RSEG RESET
DW Reset
END

Các tin khác