A falleaf hoac cac cao thu ve PIC thanh lap dien dan nay thuc su la mot dien dan co ich cho nhung nguoi yeu thich lap trinh VDK. Cam on cac ban rat nhieu, da tu lau minh am tham hoc mot minh theo cac ban va cung lam duoc mot so viec nho khi su dung PIC. Minh la nguoi moi hoc PIC va dang dung PIC de lap trinh cho robot tu dong . Nhung trong qua trinh vua lam vua hoc den gio moi tich luy duoc chut "von lieng " de co the tham gia cung dien dan voi muc dich hoc hoi anh em.
Minh dang lap trinh voi 16F877A, ban dau robot cua minh chay bam duong thi rat tot va on dinh, tuy nhien nhung doan dem vach cua minh no van chua nhan duoc, co luc thi chi 1 vach dau no da cua roi. Mong anh em tren dien dan kiem tra giup.
Phan cung cua minh su dung 6 led thu noi toi cong portA, (nam tren vach trang ='1')
RB0 - noi dong co phai
RB1 - dao chieu dong co phai
RB2 - dong co trai
RB3 - dao chieu dong co trai
Bam duong su dung hai bit RA2,RA3 nam tren vach trang.
Dem vach su dung hai bit RA0 va RA5
Do dong co cua minh toc do thap nen ko can dieu xung van bam duong tot
So vach can dem =4;
Day la chuong trinh cua minh:
Code:
///////////////////////////////////////////////////////////////////////////////////////
TITLE "test bam duong cua phai01.asm"
processor 16f877a ;identify processor 16F877A
include <p16f877a.inc> ;header file
;thuc hien: navy
;configuration Intialize
__CONFIG _CP_OFF&_WDT_OFF&_BODEN_OFF&_PWRTE_ON&_XT_OSC&_WRT_OFF&_LVP_OFF&_CPD_OFF&_DEBUG_OFF
count1 equ 0x20
count2 equ 0x21
count3 equ 0x22
vach_ngang_1 equ 0x23
;here start program
org 0x0000
goto start
start
movlw d'4' ;vach_ngang_1 = 4
movwf vach_ngang_1
bcf STATUS,RP1
bsf STATUS,RP0 ; select Bank1
clrf TRISB ; initialize portB = output
bcf STATUS,RP0 ; select Bank0
movlw b'00000101'
movwf PORTB ; set PORTB<2,0> bits drive robot forward
clrf PORTA ; clear latch PORTA
bsf STATUS,RP0 ; select Bank1
movlw b'00000110'
movwf ADCON1 ; disable A/D converter
movlw b'00111111' ; initialize portA is input_pin
movwf TRISA
call di_thang_1
call cua_phai_1
di_thang_1
bcf STATUS,RP1
bcf STATUS,RP0 ; select Bank0
btfss PORTA,2
call lech_trai_1
btfss PORTA,3
call lech_phai_1
btfss PORTA,0
goto thoat ;
btfss PORTA,5
goto thoat
decfsz vach_ngang_1,1 ;default result in vach_ngang_1
goto thoat
goto di_thang_1
thoat
return
lech_trai_1
bcf STATUS,RP1 ;select Bank0
bcf STATUS,RP0
bcf PORTB,0
call delay_10ms
btfss PORTA,2 ;Test bit sensor 02
goto lech_trai_1
return
lech_phai_1
bcf STATUS,RP1
bcf STATUS,RP0 ; select Bank0
bcf PORTB,2
call delay_10ms
btfss PORTA,3 ;Test bit sensor 03
goto lech_phai_1
return
cua_phai_1
bcf STATUS,RP1
bcf STATUS,RP0
bsf PORTB,1
btfss PORTA,0
goto cua_phai_1
call delay_phai1
return
delay_10ms
movlw d'10'
movwf count1
d1
movlw d'199'
movlw count2
movlw d'1'
movwf count3
delay_0
decfsz count2,1
goto $+2
decfsz count3,1
goto delay_0
decfsz count1,1
goto d1
return
delay_phai1
movlw d'50'
movwf count1
d1
movlw d'199'
movlw count2
movlw d'1'
movwf count3
delay_0
decfsz count2,1
goto $+2
decfsz count3,1
goto delay_0
decfsz count1,1
btfsc PORTA,0
goto delay_phai1
btfss PORTA,2
goto delay_phai1
goto $+2
goto d1
return
end
Bay gio minh muon su dung TIMER0 de dem vach nhung khoi tao va chuong trinh ngat phai viet nhu the nao ? Cac ban co the giup minh viet mot doan su dung Timer0 de dem vach duoc ko( Dem trong luc van chay thang)? Mong !