Đăng ký Đăng nhập

Tài liệu Lập trình trên chip 18f4550

.DOCX
17
506
129

Mô tả:

Lập trình chip 18f4550 Lập trình đọc chân RB0 ngắắt config fosc=HSPLL_HS config PLLDIV = 5 config CPUDIV = OSC4_PLL6 config PB config BOR = OFF config LIP = OFF config WDT = OFF include "18f4550.inc" include org .0 goto BATDAU org .8 got xulingat org .30 BATDAU bcf OSCCON, 1 bcf OSCCON, 0; movlw b'11010000' movwf INTCON; movlw b'00000000' movwf INTCON2; bcf TRISB,0; bcf TRISD, 2; lap goto lap xulingat btfss LATD,2 goto thietlap1 bcf LATD, 2 goto thoat thietlap1 bsf LATD2 thoat call delay1s retfie ;========= delay1s MOVLW 0x15 MOVWF TMP2 MOVLW 0x0CB ;203 DEC MOVWF TMP2 MOVLW 0x0EC ;236 DEC MOVWF TMP1 MOVLW 0x85 ;133 DEC MOVWF TMP0 DECFSZ TMP0,F GOTO $-1 DECFSZ TMP1,F GOTO $-3 DECFSZ TMP2,F GOTO $-5 return end lập trình chip đọc dữ liệu từ cổng B config BOR = of config LVP = of config WDI = of config PBADEN = of config FOSC = HSPLL_HS config PLLDIV = 5 config CPUDIV = OSC4_PLL6 include "p18f4550" org .0 goto batdau org .30 ;xay dung chuong trinh con tre bcf OSCCON ,1 bcf OSCCON ,0 ;cpu dao dong primiry bcf INTCON 2,7 bcf TRISD ,7 bsf TRISB ,0 lap btfsc POSTB, 0 bsf LATB, 7 call tre bcf LATB, 7 call tre goto lap and lập trình điềều khiển ti vi sony config WDT = of ; tat dong ho watch dog config bor = of ; khong reset khi nguon giam config FOSC = HSPLL_HS config PLLDIV = 5 ; dau vao 20Mhz config CPUDIV = OSC4_PLL6; toc do 96/6=16 config PBADEN = OFF ; chan PB0-PB4 la I/O digital config LVP = of ; tat che do nap dien ap thap include "P18F4550.INC" biendem equ 0x20 ; bien dem lenh equ 0x21 ; lenh mathietbi equ 0x22 ; du lieu TMP1 equ 0x23 TMP0 equ 0x24 org .0 goto batdau org 0x08 goto xulingat org .30 batdau bcf OSCCON,0,1 bcf OSCCON,1,1 BsF TRISB,0 ; chân PB0 là vào du lieu movlw .0 movwf TRISD ;cong D ra du lieu movlw .0 movwf INTCON2 ; bit7=0( kéo các chân cong B lên 1) bit6=0 (ngat INT0 boi suon am) movlw b'11010000' ; cho phép ngat INT0 movwf INTCON ;cho phép ngat INT0 movlw .255 movwf LATD lapvotan goto lapvotan ;---------------------------------xulingat movlw .3 movwf biendem ; bien dem wait call delay750 BTFSC PORTB,0 ; bo qua lenh tiep theo neu PORTB0=0 goto thoat decfsz biendem,1 goto wait ;................. xong bit dong bo movlw .7 movwf biendem lap7lan doiduongl BTFSS PORTB,0 ; bo qua lenh tiep theo neu PORTB0=1 goto doiduongl doiaml BTFSC PORTB,0 goto doiaml call delay750 bcf STATUS,0 ; xoa co C ,co C la bit 0 cua STATUS BTFSS PORTB,0 bsf STATUS,0 ; thiet lap co C=1 neu PORTB0=1 RRCF lenh,1 ; dich phai dua co C vao lenh decfsz biendem,1 goto lap7lan bcf STATUS,0 RRCF lenh,1 ;.................... lay xong ma lenh movlw .5 movwf biendem lap5lan doiduongdtb BTFSS PORTB,0 ; bo qua lenh tiep theo neu PORTB0=1 goto doiduongdtb doiamdtb BTFSC PORTB,0 goto doiamdtb call delay750 bcf STATUS,0 ; xoa co C ,co C la bit 0 cua STATUS BTFSS PORTB,0 bsf STATUS,0 ; thiet lap co C=1 neu PORTB0=1 RRCF mathietbi,1 ; dich phai dua co C vao lenh decfsz biendem,1 goto lap5lan BCF STATUS,0 RRCF mathietbi,1 BCF STATUS,0 RRCF mathietbi,1 BCF STATUS,0 RRCF mathietbi,1 ;.......................... lay xong du lieu call dieukhien thoat bcf INTCON ,1 ; xoa co ngat RETFIE ;---------------------------delay750 ; tre 800 micro giay tu Fcpu=16Mhz <=>2996+4 T MOVLW 0x04 ;4 DEC MOVWF TMP1 MOVLW 0x0E3 ;227 DEC MOVWF TMP0 lap DECFSZ TMP0,F GOTO lap DECFSZ TMP1,F GOTO lap return ;-----------------------------------dieukhien movlw .1 CPFSEQ mathietbi goto ketthuc call hienthi ketthuc return ;====================== hienthi ;dung cho bai tiep theo cac bai tuong tu movlw .20 cpfseq lenh goto ketthucht call phudinhrd2 ketthucht return ;========================= phudinhrd2 btfss LATD,2 GOTO LEN1 BCF LATD,2 GOTO THOATPD LEN1 BSF LATD,2 THOATPD movlw .255 movwf biendem laptre CALL delay750 ; goi tre decfsz biendem,1 goto laptre return end lập trình điềều khiển ti vi sony bottons config WDT = of ; tat dong ho watch dog config bor = of ; khong reset khi nguon giam config FOSC = HSPLL_HS config PLLDIV = 5 ; dau vao 20Mhz config CPUDIV = OSC4_PLL6; toc do 96/6=16 config PBADEN = OFF ; chan PB0-PB4 la I/O digital config LVP = of ; tat che do nap dien ap thap include "P18F4550.INC" biendem equ 0x20 ; bien dem lenh equ 0x21 ; lenh mathietbi equ 0x22 ; du lieu TMP1 equ 0x23 TMP0 equ 0x24 org .0 goto batdau org 0x08 goto xulingat org .30 batdau bcf OSCCON,0,1 bcf OSCCON,1,1 BsF TRISB,0 ; chân PB0 là vào du lieu movlw .0 movwf TRISD ;cong D ra du lieu movlw .0 movwf INTCON2 ; bit7=0( kéo các chân cong B lên 1) bit6=0 (ngat INT0 boi suon am) movlw b'11010000' ; cho phép ngat INT0 movwf INTCON ;cho phép ngat INT0 movlw .255 movwf LATD lapvotan goto lapvotan ;---------------------------------xulingat movlw .3 movwf biendem ; bien dem wait call delay240 BTFSC PORTB,0 ; bo qua lenh tiep theo neu PORTB0=0 goto thoat decfsz biendem,1 goto wait ;................. xong bit dong bo movlw .7 movwf biendem lap7lan doiduongl BTFSS PORTB,0 ; bo qua lenh tiep theo neu PORTB0=1 goto doiduongl doiaml BTFSC PORTB,0 goto doiaml call delay240 bcf STATUS,0 ; xoa co C ,co C la bit 0 cua STATUS BTFSS PORTB,0 bsf STATUS,0 ; thiet lap co C=1 neu PORTB0=1 RRCF lenh,1 ; dich phai dua co C vao lenh decfsz biendem,1 goto lap7lan bcf STATUS,0 RRCF lenh,1 ;.................... lay xong ma lenh movlw .5 movwf biendem lap5lan doiduongdtb BTFSS PORTB,0 ; bo qua lenh tiep theo neu PORTB0=1 goto doiduongdtb doiamdtb BTFSC PORTB,0 goto doiamdtb call delay240 bcf STATUS,0 ; xoa co C ,co C la bit 0 cua STATUS BTFSS PORTB,0 bsf STATUS,0 ; thiet lap co C=1 neu PORTB0=1 RRCF mathietbi,1 ; dich phai dua co C vao lenh decfsz biendem,1 goto lap5lan BCF STATUS,0 RRCF mathietbi,1 BCF STATUS,0 RRCF mathietbi,1 BCF STATUS,0 RRCF mathietbi,1 ;.......................... lay xong du lieu call dieukhien thoat call tre bcf INTCON ,1 ; xoa co ngat RETFIE ;---------------------------delay240 ; tre 800 micro giay tu Fcpu=16Mhz <=>2996+4 T MOVLW 0x04 ;4 DEC MOVWF TMP1 MOVLW 0x0E3 ;227 DEC MOVWF TMP0 lap DECFSZ TMP0,F GOTO lap DECFSZ TMP1,F GOTO lap return ;-----------------------------------dieukhien movlw .1 CPFSEQ mathietbi goto ketthuc call hienthi ketthuc return ;====================== hienthi movlw .21 ; 21 la gia tri phim power cpfseq lenh goto sosanh_mute call xuli_power goto ketthucht sosanh_mute movlw .20 ; 20 la gia tri phim Mute cpfseq lenh goto sosanh_input call xuli_mute goto ketthucht sosanh_input movlw .37 ; 37 la gia tri phim Input cpfseq lenh goto ketthucht call xuli_input ketthucht return ;========================== xuli_power BCF TRISD,7 ; chan RD7 huong ra du lieu btfss LATD,7 GOTO LEN1_RD7 BCF LATD,7 GOTO THOATPD7 LEN1_RD7 BSF LATD,7 THOATPD7 return ;========================= xuli_mute BCF TRISD,7 ; chan RD7 huong ra du lieu bcf LATD,7 return ;========================== xuli_input BCF TRISD,7 ; chan RD7 huong ra du lieu bsf LATD,7 return ;========================== phudinhrd2 btfss LATD,2 GOTO LEN1 BCF LATD,2 GOTO THOATPD LEN1 BSF LATD,2 THOATPD return ;=========================== tre movlw .255 movwf biendem laptre CALL delay240 CALL delay240 CALL delay240 CALL delay240 CALL delay240 decfsz biendem,1 goto laptre return end 17
- Xem thêm -

Tài liệu liên quan