![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#2 |
Nhập môn đệ tử
Tham gia ngày: Dec 2009
Bài gửi: 6
: |
bạn làm đèn giao thông hả . mình có chương trình cho bạn tham khảo nè
processor 16f877a #include <p16f877a.inc> __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC &_LVP_OFF cblock 20h dem tam1 tam2 chuc1 chuc2 donvi1 donvi2 huong1 huong2 xanh1 xanh2 do bien bien1 bien2 endc ;xxxxxxxxxxxxxxxxxxxxxxxxx bcf STATUS,6 bcf STATUS,5 clrf PORTB clrf PORTC clrf PORTD clrf PORTE bsf STATUS,5 clrf TRISB clrf TRISC clrf TRISA clrf TRISE bsf TRISD,0 bsf TRISD,1 bsf TRISD,2 bsf TRISD,3 bsf TRISD,4 bsf TRISD,5 bsf TRISD,6 bsf TRISD,7 bcf STATUS,5 macdinh call dk movlw d'15' movwf huong1 movlw d'20' movwf huong2 main movf huong1,w movwf xanh1 movf huong2,w movwf xanh2 xl call dk movlw d'100001' movwf PORTA movlw d'5' addwf xanh1,0 movwf do movf xanh1,0 call hextobcd movf do,0 call hextobcd1 call hienthi call delay xl1 call dk decfsz xanh1 goto xl movlw B'100010' movwf PORTA xl2 call dk decfsz do goto xl3 goto batdauhuong2 xl3 call dk movf do,0 call hextobcd call hextobcd1 call hienthi call delay goto xl2 batdauhuong2 call dk clrf PORTA movlw d'001100' movwf PORTA movlw d'5' addwf xanh2,0 movwf do movf xanh2,0 call hextobcd1 movf do,0 call hextobcd call hienthi call delay ct call dk decfsz xanh2 goto batdauhuong2 ct2 call dk movlw b'010100' movwf PORTA decfsz do goto ct3 goto main ct3 call dk movf do,0 call hextobcd call hextobcd1 call hienthi call delay goto ct2 hextobcd clrf chuc1 movwf tam1 bcd movlw d'10' subwf tam1,0 btfss STATUS,C goto bcd1 incf chuc1,1 movwf tam1 goto bcd bcd1 movf tam1,0 movwf donvi1 return hextobcd1 clrf chuc2 movwf tam2 bcd2 movlw d'10' subwf tam2,0 btfss STATUS,C goto bcd3 incf chuc2,1 movwf tam2 goto bcd2 bcd3 movf tam2,0 movwf donvi2 return hienthi movf donvi1,0 swapf chuc1,1 iorwf chuc1,0 movwf PORTB ht movf donvi2,0 swapf chuc2,1 iorwf chuc2,0 movwf PORTC return dk btfsc PORTD,0 goto dktay btfsc PORTD,2 goto dktanggiam btfsc PORTD,7 goto choptatvang btfsc PORTD,6 goto xelua return dktay movlw 0xff movwf PORTC movwf PORTB btfss PORTD,1 goto h1 goto h2 h1 movlw b'100001' movwf PORTA btfss PORTD,0 goto main goto dk h2 movlw d'001100' movwf PORTA btfss PORTD,0 goto main goto dk dktanggiam movlw 0x00 movwf PORTA movlw d'90' movwf huong1 movwf huong2 btfss PORTD,5 goto kttanggiam goto kttanggiam1 kttanggiam movf huong1,0 call hextobcd call hienthi movlw 0xff movwf PORTC chuyenhuong btfss PORTD,2 goto main btfsc PORTD,3 goto bdtang btfsc PORTD,4 goto bdgiam btfss PORTD,5 goto chuyenhuong goto kttanggiam1 bdtang btfsc PORTD,3 goto bdtang incf huong1 movf huong1,0 xorlw d'95' btfss STATUS,Z goto chuatran tran movlw d'0' movwf huong1 movf huong1,0 call hextobcd call hienthi movlw 0xff movwf PORTC btfss PORTD,5 goto chuyenhuong goto kttanggiam1 chuatran movf huong1,0 call hextobcd call hienthi movlw 0xff movwf PORTC btfss PORTD,2 goto main btfsc PORTD,4 goto bdgiam btfss PORTD,5 goto chuyenhuong goto kttanggiam1 bdgiam btfsc PORTD,4 goto bdgiam decf huong1 movf huong1,0 xorlw d'0' btfss STATUS,Z goto chuatran1 tran1 movlw d'1' movwf huong1 movf huong1,0 call hextobcd call hienthi movlw 0xff movwf PORTC movf huong1,0 movwf huong1 btfss PORTD,5 goto chuyenhuong goto kttanggiam1 chuatran1 movf huong1,0 call hextobcd call hienthi movlw 0xff movwf PORTC btfss PORTD,2 goto main btfss PORTD,5 goto chuyenhuong goto kttanggiam1 kttanggiam1 movf huong2,0 call hextobcd1 call hienthi movlw 0xff movwf PORTB chuyenhuong1 btfss PORTD,2 goto main btfsc PORTD,3 goto bdtang1 btfsc PORTD,4 goto bdgiam1 btfss PORTD,5 goto kttanggiam goto chuyenhuong1 bdtang1 btfsc PORTD,3 goto bdtang1 incf huong2 movf huong2,0 xorlw d'95' btfss STATUS,Z goto chuatran2 tran2 movlw d'0' movwf huong2 movf huong2,0 call hextobcd1 call hienthi movlw 0xff movwf PORTB btfss PORTD,5 goto kttanggiam goto chuyenhuong1 chuatran2 movf huong2,0 call hextobcd1 call hienthi movlw 0xff movwf PORTB btfss PORTD,2 goto main btfsc PORTD,4 goto bdgiam1 btfss PORTD,5 goto kttanggiam goto chuyenhuong1 bdgiam1 btfsc PORTD,4 goto bdgiam1 decf huong2 movlw d'0' xorwf huong2 btfss STATUS,Z goto chuatran3 tran3 movlw d'1' movwf huong2 movf huong2,0 call hextobcd1 call hienthi movlw 0xff movwf PORTB movf huong2,0 movwf huong2 btfss PORTD,5 goto kttanggiam goto chuyenhuong1 chuatran3 movf huong2,0 call hextobcd1 call hienthi movlw 0xff movwf PORTB btfss PORTD,2 goto main btfss PORTD,5 goto kttanggiam goto chuyenhuong1 choptatvang movlw 0xff movwf PORTB movwf PORTC call delay movlw b'010010' movwf PORTA call delay movlw d'000000' movwf PORTA btfss PORTD,7 goto main goto choptatvang xelua movlw 0xff movwf PORTB movwf PORTC bsf PORTE,0 movlw b'000100' movwf PORTA btfss PORTD,6 goto main goto xelua delay bcf STATUS,5 movlw b'00000000' movwf T1CON movlw d'20' movwf dem delay1 movlw b'00111100' movwf TMR1H movlw b'10101111' movwf TMR1L bsf T1CON,0 delay2 btfss PIR1,0 goto delay2 bcf PIR1,0 decfsz dem,f goto delay1 return end |
![]() |
![]() |
|
|