;1)按下SB1后进行全频道电视节目自动搜索
;2)在自动搜索中先以步进值为250Khz进行快速搜索
;3)收到台后以31.25KHZ为步进值进行微调;调谐准确后自动存储;可存储
127个频道
;4)节目搜索存储完毕和每次开机均自动播放最低频道的节目
;5)按动SB2一次节目升一个频道,按动SB3一次节目降一个频道;按住SB2或
SB3不放;频道连续升或降
;6)节目降到最低频道后自动返回最高频道;节目升到最高频道后自动返回最
低频道
;----------------------------------------------------------
LIST P=16F84A
RADIX HEX
__CONFIG H'FFF9'
;----------------------------------------------------------
PORTB EQU 06H
TRISB EQU 86H
PORTA EQU 05H
TRISA EQU 85H
STATUS EQU 03H
OPTION_REG EQU 81H
WDATA EQU 20H ;写数据寄存器
COUNT EQU 21H ;读写循环计数器
RDATA EQU 22H ;读数据寄存器
C1 EQU 23H ;5MS延时计数器
C2 EQU 24H ;5MS延时计数器
DB1 EQU 25H
DB2 EQU 26H
CB EQU 27H
PB EQU 28H
TEMP EQU 29H
DB1T EQU 30H
DB2T EQU 31H
DIZHI24 EQU 32H
SHUJU24 EQU 33H
C3 EQU 34H
ZERO EQU 35H
#DEFINE SDA TRISA,0 ;数据线
#DEFINE SCL TRISA,1 ;时钟线
#DEFINE SDAI PORTA,0 ;数据输入口
;*****************主程序********************
ORG 000H
BSF STATUS,5 ;寄存器、端口初始化
MOVLW 0XFF
MOVWF TRISA
MOVLW 0XEF
MOVWF TRISB
BCF STATUS,5
CLRF PORTA
CLRF PORTB
;------------播放第一个台位的电视节目--------------
ST MOVLW 0CAH ;CB初始化
MOVWF CB
MOVLW 0A0H ;PB初始化
MOVWF PB
CLRF DIZHI24 ;程序运行后先读出存储器00H、01H中
的数据
CALL R24
MOVF RDATA,0
MOVWF DB1
BSF STATUS,0 ;波段判断
MOVF DB1,0
SUBLW 18H
BTFSC STATUS,0
GOTO PBT34
MOVLW 90H ;为0切换到Vh段
MOVWF PB
PBT34 BSF STATUS,0 ;波段判断
MOVF DB1,0
SUBLW 3EH
BTFSC STATUS,0
GOTO WRITEI
MOVLW 30H ;为0切换到U段
MOVWF PB
WRITEI INCF DIZHI24,1
CALL R24
MOVF RDATA,0
MOVWF DB2
CALL WTUN ;播放第一个频道的节目
CALL T1S
;------------开关判断--------------
SWT BTFSS PORTA,2 ;开关SB1判断
GOTO KT
BTFSS PORTA,3 ;开关SB2判断
GOTO CHUP
BTFSS PORTA,4 ;开关SB3判断
GOTO CHDOWN
GOTO SWT
;*************频道上升子程序***************
CHUP BTFSC PORTA,3 ;频道升
GOTO SWT
CALL T5MS
BTFSC PORTA,3
GOTO SWT
CUP INCF DIZHI24,1 ;读出存储器中DB1的数据
CALL R24
MOVF RDATA,0
MOVWF DB1
BCF STATUS,2
MOVLW 0FFH ;读出的值为0FFH时证明CH升到最高返
回初始化程序
SUBWF DB1,0
BTFSC STATUS,2
GOTO ST
BSF STATUS,0 ;波段判断
MOVF DB1,0
SUBLW 18H
BTFSC STATUS,0
GOTO PBT24
MOVLW 90H ;为0切换到Vh段
MOVWF PB
PBT24 BSF STATUS,0 ;波段判断
MOVF DB1,0
SUBLW 3EH
BTFSC STATUS,0
GOTO WRITE
MOVLW 30H ;为0切换到U段
MOVWF PB
WRITE INCF DIZHI24,1 ;读出存储器中DB2的数据
CALL R24
MOVF RDATA,0
MOVWF DB2
CALL WTUN ;播放DB1,DB2数据对应频道的节目
CHUPT BTFSS PORTA,3
GOTO LIANXUUP
CALL T5MS
BTFSS PORTA,3
GOTO CHUPT
GOTO SWT
LIANXUUP CALL T1S ;连续升开关判断
BTFSC PORTA,3
GOTO CHUPT
GOTO CUP
;*************频道下降子程序***************
CHDOWN BTFSC PORTA,4 ;频道降
GOTO SWT
CALL T5MS
BTFSC PORTA,4
GOTO SWT
CDOWN BCF STATUS,2
MOVLW 01H ;地址为1证明CH降到最低
SUBWF DIZHI24,0
BTFSS STATUS,2
GOTO JIAN
DECF DIZHI24,1
JIA INCF DIZHI24,1 ;地址累加直到找到0FFH标记
INCF DIZHI24,1
CALL R24
MOVF RDATA,0
MOVWF DB1
BCF STATUS,2
MOVLW 0FFH ;读出的值为0FFH时证明找到了频道最
高位置
SUBWF DB1,0
BTFSS STATUS,2
GOTO JIA
INCF DIZHI24,1
JIAN MOVLW 0A0H
MOVWF PB
DECF DIZHI24,1
DECF DIZHI24,1
DECF DIZHI24,1
CALL R24
MOVF RDATA,0
MOVWF DB1
BSF STATUS,0
MOVF DB1,0
SUBLW 18H
BTFSC STATUS,0
GOTO PBT24D
MOVLW 90H ;为0切换到Vh段
MOVWF PB
PBT24D BSF STATUS,0
MOVF DB1,0
SUBLW 3EH
BTFSC STATUS,0
GOTO WRITED
MOVLW 30H ;为0切换到U段
MOVWF PB
WRITED INCF DIZHI24,1
CALL R24
MOVF RDATA,0
MOVWF DB2
CALL WTUN
CHDOWNT BTFSS PORTA,4
GOTO LIANXUDOWN
CALL T5MS
BTFSS PORTA,4
GOTO CHDOWNT
GOTO SWT
LIANXUDOWN CALL T1S ;连续降开关判断
BTFSC PORTA,4
GOTO CHDOWNT
GOTO CDOWN
;*************自动搜索子程序***************
KT BSF PORTB,4
MOVLW 0BH ;从1频道开始搜索
MOVWF DB1
MOVLW 08H
MOVWF DB2
MOVLW 0CAH
MOVWF CB
MOVLW 0A0H
MOVWF PB
CLRF DIZHI24
LKT1
BTFSC PORTA,2
GOTO LKT1
CALL T5MS
BTFSC PORTA,2
GOTO LKT1
CHJ BCF STATUS,0
MOVLW 08H
ADDWF DB2,1 ;以频率250khz为步进值增加
BTFSC STATUS,0 ;判断有没有进位,0无进位
INCF DB1,1
;---------------------------------------
LKT2 ;开关释放判断
BTFSS PORTA,2
GOTO LKT2
CALL T5MS
BTFSS PORTA,2
GOTO LKT2
;---------------------------------------
CALL WTUN ;写频道数据
CALL RTUN ;读频道数据
;---------------------------------------
BCF STATUS,2 ;判断频率是否偏离+62.5
MOVLW 0FBH
SUBWF ZERO,0
BTFSS STATUS,2
GOTO N1
GOTO WEITIAO
;--------------频率微调子程序--------------------------
WEITIAO
BCF STATUS,2
INCF DB2,1 ;以31.25KHZ进行微调
BTFSC STATUS,2
INCF DB1,1
;---------------------------------------
BSF STATUS,0
MOVF DB1,0
SUBLW 70H
BTFSC STATUS,0
GOTO PBT1
CLRF ZERO
MOVLW 0FFH
MOVWF SHUJU24 ;搜索频率超过57频道后做0FFH标记
CALL W24
BCF PORTB,4
GOTO ST ;频率超过57频道回到初始化1频道并停
止搜索
;----------------------------------------
PBT1 BSF STATUS,0
MOVF DB1,0
SUBLW 18H
BTFSC STATUS,0
GOTO PBT2
MOVLW 90H ;为0切换到Vh段
MOVWF PB
;---------------------------------------
PBT2
BSF STATUS,0
MOVF DB1,0
SUBLW 3EH
BTFSC STATUS,0
GOTO W2
MOVLW 30H ;为0切换到U段
MOVWF PB
;--------------------------------------------
W2 CALL WTUN
CALL RTUN
;---------------------------------------
N1 BCF STATUS,2
MOVLW 0FAH
SUBWF ZERO,0
BTFSS STATUS,2 ;判断运算是否为0为0则选台准确恢
GOTO WEITIAO
MOVF DB1,0
MOVWF SHUJU24
CALL W24 ;将DB1值存入存储器
INCF DIZHI24,1
MOVF DB2,0
MOVWF SHUJU24
CALL W24 ;将DB2值存入存储器
INCF DIZHI24,1
GOTO CHJ ;选台准确跳至CHJ继续搜索
;************写24C存储器数据子程序************
W24 CALL KAISHI
MOVLW 0A0H
MOVWF WDATA
CALL XIESHU
MOVF DIZHI24,0
MOVWF WDATA
CALL XIESHU
MOVF SHUJU24,0
MOVWF WDATA
CALL XIESHU
CALL JIESHU
CALL T5MS
CALL T5MS
RETURN
;************读24C存储器数据子程序************
R24 CALL KAISHI
MOVLW 0A0H
MOVWF WDATA
CALL XIESHU
MOVF DIZHI24,0
MOVWF WDATA
CALL XIESHU
CALL KAISHI
MOVLW 0A1H
MOVWF WDATA
CALL XIESHU
CALL RD24
CALL JIESHU
RETURN
;************写高频头数据子程序************
WTUN CALL KAISHI ;调用I2C通信的起始信号
;----------------------------------------
MOVLW 0xC2 ;高频头地址为0xC2
MOVWF WDATA
CALL XIESHU ;调用I2C通信子程序写入数据
;----------------------------------------
MOVF DB1,0 ;送DB1字节数据
MOVWF WDATA
CALL XIESHU ;写入数据
;----------------------------------------
MOVF DB2,0 ;送DB2字节数据
MOVWF WDATA
CALL XIESHU ;写入数据
;------------------------------------------
MOVF CB,0 ;送CB字节数据
MOVWF WDATA
CALL XIESHU ;写入数据
;-------------------------------------------
MOVF PB,0 ;送PB字节数据
MOVWF WDATA
CALL XIESHU ;写入数据
;--------------------------------------------
CALL JIESHU ;调用I2C通信的停止信号
RETURN
;*************读高频头数据子程序*******************
RTUN CALL T5MS
CALL T5MS
CALL T5MS
CALL T5MS
CALL KAISHI
;--------------------------------------------
MOVLW 0XC3
MOVWF WDATA
CALL XIESHU
;------------------------------------------
CALL RD
CALL JIESHU
MOVF RDATA,0
MOVWF ZERO
RETURN
;**************I2C通信子程序******************
KAISHI
CLRF PORTA
BSF STATUS,5
BSF SDA
BSF SCL
BCF SDA
CALL T5US
BCF SCL
BCF STATUS,5
RETURN
;--------------写数据--------------
XIESHU
MOVLW .8
MOVWF COUNT
LP BTFSS WDATA,7
GOTO W0
BSF STATUS,5 ;写1
BSF SDA
BSF SCL
CALL T5US
BCF SCL
BCF STATUS,5
GOTO LP1
W0 BSF STATUS,5 ;写0
BCF SDA
BSF SCL
CALL T5US
BCF SCL
BCF STATUS,5
LP1 RLF WDATA,1
DECFSZ COUNT,1
GOTO LP
;--------------写应答检测--------------
ACKT
BSF STATUS,5
BSF SDA
CALL T5US
BSF SCL
BCF STATUS,5
TEST BTFSC SDAI
GOTO TEST
BSF STATUS,5
BCF SCL
BCF SDA
BCF STATUS,5
RETURN
;--------------停止--------------
JIESHU
BSF STATUS,5
BSF SCL
CALL T5US
BSF SDA
BCF STATUS,5
RETURN
;----------------IIC读数据-------------------
RD CLRF RDATA
MOVLW .8
MOVWF COUNT
LR BSF STATUS,5
BSF SDA
BSF SCL
BCF STATUS,5
ZY RLF RDATA,1
BTFSS SDAI
GOTO RD0
BSF RDATA,0 ;读1
GOTO HT
RD0 BCF RDATA,0 ;读0
HT BSF STATUS,5
BCF SCL
BCF STATUS,5
DECFSZ COUNT,1
GOTO LR
;------------------读应答-------------------
CALL T5US
BSF STATUS,5
BCF SDA
BSF SCL
CALL T5US
BCF SCL
BCF STATUS,5
RETURN
;**********读24C数据专用I2C通信子程序***********
RD24 CLRF RDATA
MOVLW .8
MOVWF COUNT
LR24 BSF STATUS,5
BSF SDA
BSF SCL
BCF STATUS,5
ZY24 RLF RDATA,1
BTFSS SDAI
GOTO RD024
BSF RDATA,0 ;读1
GOTO HT24
RD024 BCF RDATA,0 ;读0
HT24 BSF STATUS,5
BCF SCL
BCF STATUS,5
DECFSZ COUNT,1
GOTO LR24
;-------------------------------------
CALL T5US
BSF STATUS,5
BSF SDA
BSF SCL
CALL T5US
BCF SCL
BCF STATUS,5
RETURN
;***************5US延时子程序*****************
T5US
NOP
NOP
NOP
RETURN
;***************5MS延时子程序******************
T5MS
MOVLW .7
MOVWF C1
JS1 MOVLW .255
MOVWF C2
JS2 DECFSZ C2,1
GOTO JS2
DECFSZ C1,1
GOTO JS1
RETURN
;*****************1秒延时子程序*****************
T1S MOVLW .5
MOVWF C3
JS23 MOVLW .255
MOVWF C1
JS21 MOVLW .255
MOVWF C2
JS22 DECFSZ C2,1
GOTO JS22
DECFSZ C1,1
GOTO JS21
DECFSZ C3
GOTO JS23
RETURN
END
文章评论(0条评论)
登录后参与讨论