;芯片為EM78P153
;P64,P65接晶振,振蕩模式為4MHz晶振
;看門狗關(guān),指令周期為2個CLOCK,P63為復(fù)位腳
;*******************IO口的定義*********************
PORT6 EQU 0X06
IOC60 EQU 0X06
;**************特殊功能寄存器的定義******************
TCCEQU 0X01
PC EQU 0X02
PSW EQU 0X03
IOCD0 EQU 0X0D
IOCE0 EQU 0X0E
IOCF0 EQU 0X0F
RF EQU 0X0F
;***************用戶自定義的寄存器*******************
COUNTER EQU 0X10
CODE1 EQU 0X11
CODE2 EQU 0X12
CODE3 EQU 0X13
CODE4 EQU 0X14
LP_CNT0 EQU 0X15
LP_CNT1 EQU 0X16
TEMP EQU 0X17
TEMPCODE EQU 0X18
REPEAT_COUNTER EQU 0X19
SEND_DATA EQU 0X1A
USER_CODE EQU 0X1B
FLAG EQU 0X1C
;*******************FLAG位定義**********************
C EQU 0
Z EQU 2
TCIF EQU 0
LEAD EQU 0
REPEAT EQU 1
INPUT EQU 1
OUTPUT EQU 0
ORG 0X000
NOP
NOP
NOP
NOP
JMP 0X50
;********************表格轉(zhuǎn)換子程序程序******************
TABLE_CONVER:
CLR TEMP
TABLE_CONVER_1:
MOV A,TEMP
CALL TABLE_CONVERSION_IN
BC PSW,Z
XOR A,CODE3
JBC PSW,Z
JMP EXIT_5
INC TEMP
JMP TABLE_CONVER_1
EXIT_5:
CALL TABLE_CONVERSION_OUT
RET
;**********************表格轉(zhuǎn)換程序IN*********************
TABLE_CONVERSION_IN:
ADD PC,A
RETL 0XD0 ;KEY_1
RETL 0X58 ;KEY_2
RETL 0XD8 ;KEY_3
RETL 0X90 ;KEY_4
RETL 0X18 ;KEY_5
RETL 0X98 ;KEY_6
RETL 0XE0 ;KEY_7
RETL 0X68 ;KEY_8
RETL 0XE8 ;KEY_9
RETL 0X28 ;KEY_0
RETL 0X20 ;KEY_3D
RETL 0XA0 ;KEY_MUTE
RETL 0X40 ;KEY_VOCAL
RETL 0XE2 ;KEY_VOL+
RETL 0XA2 ;KEY_VOL-
RETL 0X52 ;KEY_TUNE FWD
RETL 0X22 ;KEY_TUNE REV
RETL 0X12 ;KEY_STOP
RETL 0X80 ;KEY_
RETL 0X02 ;KEY_OK
RETL 0XF0 ;KEY_TUNER
RETL 0X78 ;KEY_AM/FM
RETL 0XF8 ;KEY_SAVE
RETL 0X50 ;KEY_AUDIO
;**********************表格轉(zhuǎn)換程序OUT*********************
TABLE_CONVERSION_OUT:
MOV A,TEMP
ADD PC,A
RETL 0X35 ;KEY_1
RETL 0X2D ;KEY_2
RETL 0X25 ;KEY_3
RETL 0X1D ;KEY_4
RETL 0X34 ;KEY_5
RETL 0X2C ;KEY_6
RETL 0X24 ;KEY_7
RETL 0X1C ;KEY_8
RETL 0X33 ;KEY_9
RETL 0X2B ;KEY_0
RETL 0X10 ;KEY_3D
RETL 0X18 ;KEY_MUTE
RETL 0X11 ;KEY_VOCAL
RETL 0X16 ;KEY_VOL+
RETL 0X15 ;KEY_VOL-
RETL 0X28 ;KEY_TUNE FWD
RETL 0X2A ;KEY_TUNE REV
RETL 0X22 ;KEY_STOP
RETL 0X31 ;KEY_
RETL 0X29 ;KEY_OK
RETL 0X2E ;KEY_TUNER
RETL 0X20 ;KEY_AUX-1
RETL 0X23 ;KEY_AUX-2
RETL 0X17 ;KEY_DVD
ORG 0X050
MAIN:
;*********************初始化寄存器**********************
MOV A,@0B00000000
IOW IOCE0
MOV A,@0B11111101
IOW IOCD0
MOV A,@0B00000010
IOW IOC60
MOV A,@0B00000001
MOV PORT6,A
MOV A,@0B00000001
IOW IOCF0
CLR FLAG
CLR TEMPCODE
CLR COUNTER
CLR CODE1
CLR CODE2
CLR CODE3
CLR CODE4
MOV A,@0B10010000
MOV USER_CODE,A
;*********************掃描引導(dǎo)碼**********************
SCAN_LEAD_CODE:
JBC PORT6,INPUT
JMP SCAN_LEAD_CODE
CLR FLAG
CLR REPEAT_COUNTER
CLR TEMPCODE
CALL JUDGE_START_CODE
JBS FLAG,LEAD
JMP SCAN_LEAD_CODE
;*********************接收數(shù)據(jù)**********************
RECEIVE_DATA_PROCEE:
CLR TEMPCODE
CALL RECEIVE_DATA
MOV A,TEMPCODE
MOV CODE1,A
MOV A,@0 ;判斷用戶碼是否是00
BC PSW,Z
XOR A,CODE1
JBS PSW,Z
JMP SCAN_LEAD_CODE
CLR TEMPCODE
CALL RECEIVE_DATA
MOV A,TEMPCODE
MOV CODE2,A
MOV A,@0XFF ;判斷用戶碼是否是FF
BC PSW,Z
XOR A,CODE2
JBS PSW,Z
JMP SCAN_LEAD_CODE
CLR TEMPCODE
CALL RECEIVE_DATA
MOV A,TEMPCODE
MOV CODE3,A
CLR TEMPCODE
CALL RECEIVE_DATA
MOV A,TEMPCODE
MOV CODE4,A
CLR FLAG
;*********************發(fā)送數(shù)據(jù)**********************
SEND_DATA_PROCEE:
JBS USER_CODE,6 ;ST碼的次高位反相
JMP COM_1 ;=0
JMP COM_2 ;=1
COM_1:
BS USER_CODE,6
JMP VVV
COM_2:
BC USER_CODE,6
JMP VVV
VVV:
CALL TABLE_CONVER ;調(diào)用碼表轉(zhuǎn)換子程序
MOV CODE3,A
REP:
CALL TRANSMIT_DATA
BS PORT6,OUTPUT
CALL JUDGE_REPEAT_CODE ;掃描引導(dǎo)碼是否在重復(fù)?
JBS FLAG,LEAD
JMP SCAN_LEAD_CODE
JBC FLAG,REPEAT
JMP REP ;引導(dǎo)碼是重復(fù),繼續(xù)掃描
JMP RECEIVE_DATA_PROCEE ;引導(dǎo)碼不重復(fù),去接收新數(shù)據(jù)
;****************引導(dǎo)碼的檢測子程序*****************
JUDGE_START_CODE:
CLR COUNTER ;清計數(shù)器
JUDGE_START_CODE_0:
JBC PORT6,INPUT
JMP NO_HIGH
CALL DELAY0.5MS
JBC PORT6,INPUT
JMP NO_HIGH
INC COUNTER
JMP JUDGE_START_CODE_0
NO_HIGH:
MOV A,COUNTER
BC PSW,C
SUB A,@20 ;20-A
JBS PSW,C
JMP EXIT_0 ;C=1,COUNTER>20
MOV A,COUNTER
BC PSW,C
SUB A,@16 ;16-A
JBC PSW,C
JMP EXIT_0 ;C=0,COUNTER250
JBC PORT6,INPUT
JMP CONTINUE_2
MOV A,TCC
MOV TEMP,A
BC PSW,C
SUB A,@60;142
JBC PSW,C
JMP X1 ;C=1,TCC60
X1:
BC TEMPCODE,0
JMP EXIT_1
X2:
BS TEMPCODE,0
JMP EXIT_1
EXIT_1:
DJZ COUNTER
JMP HH
MOV A,@0B00100000
CONTW ;停止記數(shù)
RET
HH:
BC PSW,C
RLC TEMPCODE
JMP CONTINUE_1
;****************發(fā)送數(shù)據(jù)子程序**********************
TRANSMIT_DATA:
MOV A,@4
MOV COUNTER,A
MOV A,USER_CODE ;@0B10010000 ;發(fā)送ST的用戶碼
MOV SEND_DATA,A
CYCLE_1:
JBS SEND_DATA,7
JMP SEND_P_0
JMP SEND_P_1
SEND_P_1:
CALL SEND_CODE_1
JMP EXIT_3
SEND_P_0:
CALL SEND_CODE_0
JMP EXIT_3
EXIT_3:
RLC SEND_DATA
DJZ COUNTER
JMP CYCLE_1
MOV A,@8
MOV COUNTER,A
MOV A,CODE3
MOV SEND_DATA,A
RLC SEND_DATA
CYCLE_2:
JBS SEND_DATA,7
JMP SEND_Q_0
JMP SEND_Q_1
SEND_Q_1:
CALL SEND_CODE_1
JMP EXIT_4
SEND_Q_0:
CALL SEND_CODE_0
JMP EXIT_4
EXIT_4:
RLC SEND_DATA
DJZ COUNTER
JMP CYCLE_2
RET
;***************發(fā)送數(shù)據(jù)"1"子程序********************
SEND_CODE_1:
MOV A,@0B00100000
CONTW ;停止記數(shù)
MOV A,@0B00000001 ;允許TCC中斷
IOW IOCF0
MOV A,@35 ;引導(dǎo)脈沖的預(yù)置值
MOV TCC,A
MOV A,@0B00000001 ;選擇預(yù)分頻比為1:4
CONTW
BC PORT6,OUTPUT
WAIT_1:
JBS RF,TCIF
JMP WAIT_1
MOV A,@0B00100000
CONTW ;停止記數(shù)
BC RF,TCIF
MOV A,@32 ;代碼"1"的預(yù)置值
MOV TCC,A
MOV A,@0B00000101 ;選擇預(yù)分頻比為1:64
CONTW
BS PORT6,OUTPUT
WAIT_2:
JBS RF,TCIF
JMP WAIT_2
BC RF,TCIF
MOV A,@0B00100000
CONTW ;停止記數(shù)
RET
;***************發(fā)送數(shù)據(jù)"0"子程序********************
SEND_CODE_0:
MOV A,@0B00100000
CONTW ;停止記數(shù)
MOV A,@0B00000001 ;允許TCC中斷
IOW IOCF0
MOV A,@35 ;引導(dǎo)脈沖的預(yù)置值
MOV TCC,A
MOV A,@0B00000001 ;選擇預(yù)分頻比為1:4
CONTW
BC PORT6,OUTPUT
WAIT_3:
JBS RF,TCIF
JMP WAIT_3
MOV A,@0B00100000
CONTW ;停止記數(shù)
BC RF,TCIF
MOV A,@114 ;代碼"0"的預(yù)置值
MOV TCC,A
MOV A,@0B00000101 ;選擇預(yù)分頻比為1:64
CONTW
BS PORT6,OUTPUT
WAIT_4:
JBS RF,TCIF
JMP WAIT_4
NOP
BC RF,TCIF
MOV A,@0B00100000
CONTW ;停止記數(shù)
RET
;****************重復(fù)碼的檢測子程序******************
JUDGE_REPEAT_CODE:
CLR COUNTER ;清計數(shù)器
CLR FLAG
JUDGE_REPEAT_CODE_0:
JBC PORT6,INPUT
JMP JUDGE_REPEAT_CODE_0
SS:
JBC PORT6,INPUT
JMP JUDGE_REPEAT_CODE_1
CALL DELAY0.5MS
JBC PORT6,INPUT
JMP JUDGE_REPEAT_CODE_1
INC COUNTER
JMP SS
JUDGE_REPEAT_CODE_1:
MOV A,COUNTER
BC PSW,C
SUB A,@20 ;20-A
JBS PSW,C
JMP EXIT_2 ;C=1,COUNTER>20
MOV A,COUNTER
BC PSW,C
SUB A,@16 ;16-A
JBC PSW,C
JMP EXIT_2 ;C=0,COUNTER7
JMP YES_REPEAT ;C=1,COUNTER
發(fā)布評論請先 登錄
相關(guān)推薦
評論