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
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 = off ; tat dong ho watch dog
config bor = off ; 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 = off ; tat che do nap dien ap thap
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
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
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
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
;======================
;=========================
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