EM78P153程序范例
扫描二维码
随时随地手机看文章
芯片为EM78P153
;P64,P65接晶振,振荡模式为4MHz晶振
;看门狗关,指令周期为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
;********************表格转换子程序程序******************
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
;**********************表格转换程序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
;**********************表格转换程序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
;*********************接收数据**********************
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
;*********************发送数据**********************
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;调用码表转换子程序
MOVCODE3,A
REP:
CALLTRANSMIT_DATA
BSPORT6,OUTPUT
CALLJUDGE_REPEAT_CODE;扫描引导码是否在重复?
JBSFLAG,LEAD
JMPSCAN_LEAD_CODE
JBCFLAG,REPEAT
JMPREP;引导码是重复,继续扫描
JMPRECEIVE_DATA_PROCEE;引导码不重复,去接收新数据
;****************引导码的检测子程序*****************
JUDGE_START_CODE:
CLRCOUNTER;清计数器
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
;****************接收数据子程序**********************
RECEIVE_DATA:
MOVA,@8
MOVCOUNTER,A
MOVA,@0B00100000
CONTW;停止记数
CONTINUE_1:
JBSPORT6,INPUT
JMPCONTINUE_1
CLRTCC
MOVA,@0B00000100
CONTW;TCC开始记数
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;停止记数
RET
HH:
BCPSW,C
RLCTEMPCODE
JMPCONTINUE_1
;****************发送数据子程序**********************
TRANSMIT_DATA:
MOVA,@4
MOVCOUNTER,A
MOVA,USER_CODE;@0B10010000;发送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
;***************发送数据"1"子程序********************
SEND_CODE_1:
MOVA,@0B00100000
CONTW;停止记数
MOVA,@0B00000001;允许TCC中断
IOWIOCF0
MOVA,@35;引导脉冲的预置值
MOVTCC,A
MOVA,@0B00000001;选择预分频比为1:4
CONTW
BCPORT6,OUTPUT
WAIT_1:
JBSRF,TCIF
JMPWAIT_1
MOVA,@0B00100000
CONTW;停止记数
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;停止记数
RET
;***************发送数据"0"子程序********************
SEND_CODE_0:
MOVA,@0B00100000
CONTW;停止记数
MOVA,@0B00000001;允许TCC中断
IOWIOCF0
MOVA,@35;引导脉冲的预置值
MOVTCC,A
MOVA,@0B00000001;选择预分频比为1:4
CONTW
BCPORT6,OUTPUT
WAIT_3:
JBSRF,TCIF
JMPWAIT_3
MOVA,@0B00100000
CONTW;停止记数
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;停止记数
RET
;****************重复码的检测子程序******************
JUDGE_REPEAT_CODE:
CLRCOUNTER;清计数器
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;清计数器
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