芯片為EM78P153
;P64,P65接晶振,振蕩模式為4MHz晶振
;看門狗關(guān),指令周期為2個CLOCK,P63為復位腳
;*******************IO口的定義*********************
PORT6EQU0X06
IOC60EQU0X06
;**************特殊功能寄存器的定義******************
TCCEQU0X01
PCEQU0X02
PSWEQU0X03
IOCD0EQU0X0D
IOCE0EQU0X0E
IOCF0EQU0X0F
RFEQU0X0F
;***************用戶自定義的寄存器*******************
COUNTEREQU0X10
CODE1EQU0X11
CODE2EQU0X12
CODE3EQU0X13
CODE4EQU0X14
LP_CNT0EQU0X15
LP_CNT1EQU0X16
TEMPEQU0X17
TEMPCODEEQU0X18
REPEAT_COUNTEREQU0X19
SEND_DATAEQU0X1A
USER_CODEEQU0X1B
FLAGEQU0X1C
;*******************FLAG位定義**********************
CEQU0
ZEQU2
TCIFEQU0
LEADEQU0
REPEATEQU1
INPUTEQU1
OUTPUTEQU0
ORG0X000
NOP
NOP
NOP
NOP
JMP0X50
;********************表格轉(zhuǎn)換子程序程序******************
TABLE_CONVER:
CLRTEMP
TABLE_CONVER_1:
MOVA,TEMP
CALLTABLE_CONVERSION_IN
BCPSW,Z
XORA,CODE3
JBCPSW,Z
JMPEXIT_5
INCTEMP
JMPTABLE_CONVER_1
EXIT_5:
CALLTABLE_CONVERSION_OUT
RET
;**********************表格轉(zhuǎn)換程序IN*********************
TABLE_CONVERSION_IN:
ADDPC,A
RETL0XD0;KEY_1
RETL0X58;KEY_2
RETL0XD8;KEY_3
RETL0X90;KEY_4
RETL0X18;KEY_5
RETL0X98;KEY_6
RETL0XE0;KEY_7
RETL0X68;KEY_8
RETL0XE8;KEY_9
RETL0X28;KEY_0
RETL0X20;KEY_3D
RETL0XA0;KEY_MUTE
RETL0X40;KEY_VOCAL
RETL0XE2;KEY_VOL+
RETL0XA2;KEY_VOL-
RETL0X52;KEY_TUNEFWD
RETL0X22;KEY_TUNEREV
RETL0X12;KEY_STOP
RETL0X80;KEY_<|
RETL0X82;KEY_|>
RETL0X02;KEY_OK
RETL0XF0;KEY_TUNER
RETL0X78;KEY_AM/FM
RETL0XF8;KEY_SAVE
RETL0X50;KEY_AUDIO
;**********************表格轉(zhuǎn)換程序OUT*********************
TABLE_CONVERSION_OUT:
MOVA,TEMP
ADDPC,A
RETL0X35;KEY_1
RETL0X2D;KEY_2
RETL0X25;KEY_3
RETL0X1D;KEY_4
RETL0X34;KEY_5
RETL0X2C;KEY_6
RETL0X24;KEY_7
RETL0X1C;KEY_8
RETL0X33;KEY_9
RETL0X2B;KEY_0
RETL0X10;KEY_3D
RETL0X18;KEY_MUTE
RETL0X11;KEY_VOCAL
RETL0X16;KEY_VOL+
RETL0X15;KEY_VOL-
RETL0X28;KEY_TUNEFWD
RETL0X2A;KEY_TUNEREV
RETL0X22;KEY_STOP
RETL0X31;KEY_<|
RETL0X21;KEY_|>
RETL0X29;KEY_OK
RETL0X2E;KEY_TUNER
RETL0X20;KEY_AUX-1
RETL0X23;KEY_AUX-2
RETL0X17;KEY_DVD
ORG0X050
MAIN:
;*********************初始化寄存器**********************
MOVA,@0B00000000
IOWIOCE0
MOVA,@0B11111101
IOWIOCD0
MOVA,@0B00000010
IOWIOC60
MOVA,@0B00000001
MOVPORT6,A
MOVA,@0B00000001
IOWIOCF0
CLRFLAG
CLRTEMPCODE
CLRCOUNTER
CLRCODE1
CLRCODE2
CLRCODE3
CLRCODE4
MOVA,@0B10010000
MOVUSER_CODE,A
;*********************掃描引導碼**********************
SCAN_LEAD_CODE:
JBCPORT6,INPUT
JMPSCAN_LEAD_CODE
CLRFLAG
CLRREPEAT_COUNTER
CLRTEMPCODE
CALLJUDGE_START_CODE
JBSFLAG,LEAD
JMPSCAN_LEAD_CODE
;*********************接收數(shù)據(jù)**********************
RECEIVE_DATA_PROCEE:
CLRTEMPCODE
CALLRECEIVE_DATA
MOVA,TEMPCODE
MOVCODE1,A
MOVA,@0;判斷用戶碼是否是00
BCPSW,Z
XORA,CODE1
JBSPSW,Z
JMPSCAN_LEAD_CODE
CLRTEMPCODE
CALLRECEIVE_DATA
MOVA,TEMPCODE
MOVCODE2,A
MOVA,@0XFF;判斷用戶碼是否是FF
BCPSW,Z
XORA,CODE2
JBSPSW,Z
JMPSCAN_LEAD_CODE
CLRTEMPCODE
CALLRECEIVE_DATA
MOVA,TEMPCODE
MOVCODE3,A
CLRTEMPCODE
CALLRECEIVE_DATA
MOVA,TEMPCODE
MOVCODE4,A
CLRFLAG
;*********************發(fā)送數(shù)據(jù)**********************
SEND_DATA_PROCEE:
JBSUSER_CODE,6;ST碼的次高位反相
JMPCOM_1;=0
JMPCOM_2;=1
COM_1:
BSUSER_CODE,6
JMPVVV
COM_2:
BCUSER_CODE,6
JMPVVV
VVV:
CALLTABLE_CONVER;調(diào)用碼表轉(zhuǎn)換子程序
MOVCODE3,A
REP:
CALLTRANSMIT_DATA
BSPORT6,OUTPUT
CALLJUDGE_REPEAT_CODE;掃描引導碼是否在重復?
JBSFLAG,LEAD
JMPSCAN_LEAD_CODE
JBCFLAG,REPEAT
JMPREP;引導碼是重復,繼續(xù)掃描
JMPRECEIVE_DATA_PROCEE;引導碼不重復,去接收新數(shù)據(jù)
;****************引導碼的檢測子程序*****************
JUDGE_START_CODE:
CLRCOUNTER;清計數(shù)器
JUDGE_START_CODE_0:
JBCPORT6,INPUT
JMPNO_HIGH
CALLDELAY0.5MS
JBCPORT6,INPUT
JMPNO_HIGH
INCCOUNTER
JMPJUDGE_START_CODE_0
NO_HIGH:
MOVA,COUNTER
BCPSW,C
SUBA,@20;20-A
JBSPSW,C
JMPEXIT_0;C=1,COUNTER>20
MOVA,COUNTER
BCPSW,C
SUBA,@16;16-A
JBCPSW,C
JMPEXIT_0;C=0,COUNTER<16
BSFLAG,LEAD
EXIT_0:
JBCPORT6,INPUT
JMPEXIT_0
INCREPEAT_COUNTER
RET
;****************接收數(shù)據(jù)子程序**********************
RECEIVE_DATA:
MOVA,@8
MOVCOUNTER,A
MOVA,@0B00100000
CONTW;停止記數(shù)
CONTINUE_1:
JBSPORT6,INPUT
JMPCONTINUE_1
CLRTCC
MOVA,@0B00000100
CONTW;TCC開始記數(shù)
CONTINUE_2:
MOVA,TCC
MOVTEMP,A
BCPSW,C
SUBA,@250
JBSPSW,C
JMPSCAN_LEAD_CODE;C=0,TCC>250
JBCPORT6,INPUT
JMPCONTINUE_2
MOVA,TCC
MOVTEMP,A
BCPSW,C
SUBA,@60;142
JBCPSW,C
JMPX1;C=1,TCC<60
JMPX2;C=0,TCC>60
X1:
BCTEMPCODE,0
JMPEXIT_1
X2:
BSTEMPCODE,0
JMPEXIT_1
EXIT_1:
DJZCOUNTER
JMPHH
MOVA,@0B00100000
CONTW;停止記數(shù)
RET
HH:
BCPSW,C
RLCTEMPCODE
JMPCONTINUE_1
;****************發(fā)送數(shù)據(jù)子程序**********************
TRANSMIT_DATA:
MOVA,@4
MOVCOUNTER,A
MOVA,USER_CODE;@0B10010000;發(fā)送ST的用戶碼
MOVSEND_DATA,A
CYCLE_1:
JBSSEND_DATA,7
JMPSEND_P_0
JMPSEND_P_1
SEND_P_1:
CALLSEND_CODE_1
JMPEXIT_3
SEND_P_0:
CALLSEND_CODE_0
JMPEXIT_3
EXIT_3:
RLCSEND_DATA
DJZCOUNTER
JMPCYCLE_1
MOVA,@8
MOVCOUNTER,A
MOVA,CODE3
MOVSEND_DATA,A
RLCSEND_DATA
CYCLE_2:
JBSSEND_DATA,7
JMPSEND_Q_0
JMPSEND_Q_1
SEND_Q_1:
CALLSEND_CODE_1
JMPEXIT_4
SEND_Q_0:
CALLSEND_CODE_0
JMPEXIT_4
EXIT_4:
RLCSEND_DATA
DJZCOUNTER
JMPCYCLE_2
RET
;***************發(fā)送數(shù)據(jù)"1"子程序********************
SEND_CODE_1:
MOVA,@0B00100000
CONTW;停止記數(shù)
MOVA,@0B00000001;允許TCC中斷
IOWIOCF0
MOVA,@35;引導脈沖的預置值
MOVTCC,A
MOVA,@0B00000001;選擇預分頻比為1:4
CONTW
BCPORT6,OUTPUT
WAIT_1:
JBSRF,TCIF
JMPWAIT_1
MOVA,@0B00100000
CONTW;停止記數(shù)
BCRF,TCIF
MOVA,@32;代碼"1"的預置值
MOVTCC,A
MOVA,@0B00000101;選擇預分頻比為1:64
CONTW
BSPORT6,OUTPUT
WAIT_2:
JBSRF,TCIF
JMPWAIT_2
BCRF,TCIF
MOVA,@0B00100000
CONTW;停止記數(shù)
RET
;***************發(fā)送數(shù)據(jù)"0"子程序********************
SEND_CODE_0:
MOVA,@0B00100000
CONTW;停止記數(shù)
MOVA,@0B00000001;允許TCC中斷
IOWIOCF0
MOVA,@35;引導脈沖的預置值
MOVTCC,A
MOVA,@0B00000001;選擇預分頻比為1:4
CONTW
BCPORT6,OUTPUT
WAIT_3:
JBSRF,TCIF
JMPWAIT_3
MOVA,@0B00100000
CONTW;停止記數(shù)
BCRF,TCIF
MOVA,@114;代碼"0"的預置值
MOVTCC,A
MOVA,@0B00000101;選擇預分頻比為1:64
CONTW
BSPORT6,OUTPUT
WAIT_4:
JBSRF,TCIF
JMPWAIT_4
NOP
BCRF,TCIF
MOVA,@0B00100000
CONTW;停止記數(shù)
RET
;****************重復碼的檢測子程序******************
JUDGE_REPEAT_CODE:
CLRCOUNTER;清計數(shù)器
CLRFLAG
JUDGE_REPEAT_CODE_0:
JBCPORT6,INPUT
JMPJUDGE_REPEAT_CODE_0
SS:
JBCPORT6,INPUT
JMPJUDGE_REPEAT_CODE_1
CALLDELAY0.5MS
JBCPORT6,INPUT
JMPJUDGE_REPEAT_CODE_1
INCCOUNTER
JMPSS
JUDGE_REPEAT_CODE_1:
MOVA,COUNTER
BCPSW,C
SUBA,@20;20-A
JBSPSW,C
JMPEXIT_2;C=1,COUNTER>20
MOVA,COUNTER
BCPSW,C
SUBA,@16;16-A
JBCPSW,C
JMPEXIT_2;C=0,COUNTER<16
BSFLAG,LEAD
JMPJUDGE_REPEAT_CODE_2
EXIT_2:
RET
JUDGE_REPEAT_CODE_2:
CLRCOUNTER;清計數(shù)器
JUDGE_REPEAT_CODE_3:
JBSPORT6,INPUT
JMPJUDGE_REPEAT_CODE_4
CALLDELAY0.5MS
JBSPORT6,INPUT
JMPJUDGE_REPEAT_CODE_4
INCCOUNTER
JMPJUDGE_REPEAT_CODE_3
JUDGE_REPEAT_CODE_4:
MOVA,COUNTER
BCPSW,C
SUBA,@7;7-A
JBSPSW,C
JMPNO_REPEAT;C=0,COUNTER>7
JMPYES_REPEAT;C=1,COUNTER<7
NO_REPEAT:
BCFLAG,REPEAT
CLRREPEAT_COUNTER
RET
YES_REPEAT:
BSFLAG,REPEAT
INCREPEAT_COUNTER
RET
;****************延時0.5mS子程序*********************
DELAY0.5MS:
MOVA,@2
MOVLP_CNT0,A
DELAY0.5MS_1:
MOVA,@82
MOVLP_CNT1,A
DELAY0.5MS_2:
NOP
NOP
NOP
DJZLP_CNT1
JMPDELAY0.5MS_2
DJZLP_CNT0
JMPDELAY0.5MS_1
RET