include
COUNT EQU 20H
COUNT1 EQU 21H
COUNT2 EQU 22H
ADDRES EQU 23H
SENDBUF EQU 24H ;存键值
TXBUF EQU 25H
MM EQU 26H ;10MS DELAY
NN EQU 27H
AA EQU 28H ; DELAY1
BB EQU 29H
TVDATA EQU 2AH
;=============================
ORG 10H
START
BSF STATUS,RP0
MOVLW B’11111111’ ;RA4频道下翻
MOVWF TRISA
MOVLW B’00000001’
MOVWF TRISB ;RB0频道上翻 RB1 LED
MOVLW B’11111110’
MOVWF TRISC ;RC0 红外输出
BCF STATUS,RP0
BCF PORTC,0 ;红外输出口
BSF PORTB,1 ;复位时RB1 LED闪二下,表示工作正常。
CALL DELAY1
BCF PORTB,1
CALL DELAY1
BSF PORTB,1
CALL DELAY1
BCF PORTB,1
CALL DELAY1
;================键扫描=================
MAIN
BTFSS PORTB,0 ;RB0频道上翻
GOTO SCHUP ;PORTB常态是高电平,低电平有键按下。
BTFSS PORTA,4 ;RA4频道下翻
GOTO SCHDOWN
GOTO MAIN
;==========频道上翻=============
SCHUP CALL DELAY ;键去抖
BTFSC PORTB,0
GOTO MAIN
BTFSS PORTB,0 ;键释放?
GOTO $-1
BSF PORTB,1
;
MOVLW B’00110100’ ;TV ADRESS(写入自己的彩电地址码)
MOVWF ADDRES
MOVLW B’00000001’ ;TV DATA
MOVWF TVDATA
CALL SEND ;发送一次红外信号
MOVLW B’00110100’ ;TV ADRESS
MOVWF ADDRES
MOVLW B’00000001’ ;TV DATA
MOVWF TVDATA
CALL SEND ;发送一次红外信号
GOTO MAIN
;==========频道下翻=============
SCHDOWN CALL DELAY ;键去抖
BTFSC PORTA,4
GOTO MAIN
BTFSS PORTA,4 ;键释放?
GOTO $-1
BSF PORTA,4
;
MOVLW B’00110100’ ;TV ADRESS
MOVWF ADDRES
MOVLW B’00000010’ ;TV DATA
MOVWF TVDATA
CALL SEND ;发送一次红外信号
MOVLW B’00110100’ ;TV ADRESS
MOVWF ADDRES
MOVLW B’00000010’ ;TV DATA
MOVWF TVDATA
CALL SEND ;发送一次红外信号
GOTO MAIN
;=======发送8.07mS+4.0MS组成的头码=========== (一般是9MS+4.5MS)
SEND MOVLW 0XFF
CALL POUSE
MOVLW 0X34
CALL POUSE
;4.0MS
MOVLW 0XC8
CALL DELAY2
;=========发送地址===========
MOVF ADDRES,0
CALL TVADDRESS
;========中间插一断560uS+4MS低===============
MOVLW 0X14
CALL POUSE
MOVLW 0XC8
CALL DELAY2
;=========发送数据===========
MOVF TVDATA,0
CALL TVADDRESS
;===结尾560US POUSE+22.7MS低电平======
MOVLW 0X13
CALL POUSE
BCF PORTC,0
CALL DELAY ;3MS
CALL DELAY ;3MS
CALL DELAY ;3MS
CALL DELAY ;3MS
CALL DELAY ;3MS
CALL DELAY ;3MS
CALL DELAY ;3MS
RETURN
;===========560uS 高38K频===============
POUSE MOVWF COUNT ;560uS=0X14
K38 BSF PORTC,0 ;(0XFF+ 0X34)*26.9=8.07mS
NOP ;(0XFF+ 0X4E)*26.9=9mS
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTC,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNT,1
GOTO K38
RETURN
;===============发送TV地址和数据码==================
TVADDRESS MOVWF TXBUF ;注意PC示波器先收到的是低位!!!
MOVLW 0X08
MOVWF COUNT1
TLP BTFSC TXBUF,0 ;地址码为0就发0,为1就发1。
GOTO IDONE
;==========TV 发送0子程序============
MOVLW 0X14
MOVWF COUNT ; 560uS
TVZERO BSF PORTC,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTC,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNT,1
GOTO TVZERO
;
BCF PORTC,0
MOVLW 0X7D
MOVWF COUNT2 ;480uS
L0TLP NOP
DECFSZ COUNT2,1
GOTO L0TLP
;---------------
GOTO GUR
IDONE
;==========TV 发送1子程序============
;560uS+1.43mS
MOVLW 0X14
MOVWF COUNT ;560uS
TVONE BSF PORTC,0 ;红外输出口
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTC,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNT,1
GOTO TVONE
;-------
BCF PORTC,0
MOVLW 0X7D
MOVWF COUNT2 ;1.48mS
L1TLP NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNT2,1
GOTO L1TLP
NOP
NOP
NOP
NOP
NOP
NOP
;-----------------
GUR RRF TXBUF,1
DECFSZ COUNT1,1 ;共8次。
GOTO TLP
RETURN
;
;=========== 3ms键去抖 =============
DELAY MOVLW 0X04
MOVWF MM
DY1 MOVLW 0XFF
MOVWF NN
DY2 DECFSZ NN
GOTO DY2
DECFSZ MM
GOTO DY1
RETURN
;=========== LED闪延时 =============
DELAY1 MOVLW 0XFF
MOVWF AA
DYA1 MOVLW 0XFF
MOVWF BB
DYA2 DECFSZ BB
GOTO DYA2
DECFSZ AA
GOTO DYA1
RETURN
;============ 20us*X ================
DELAY2 MOVWF COUNT2 ;0XC8=20us*200=4.0ms
TOPL NOP ;0XE1=20us*225=4.5ms
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ COUNT2,1
GOTO TOPL
RETURN
;=============================
END