em78p153驱动1602源程序
扫描二维码
随时随地手机看文章
芯片为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
RETL0XD0KEY_1
RETL0X58KEY_2
RETL0XD8KEY_3
RETL0X90KEY_4
RETL0X18KEY_5
RETL0X98KEY_6
RETL0XE0KEY_7
RETL0X68KEY_8
RETL0XE8KEY_9
RETL0X28KEY_0
RETL0X20KEY_3D
RETL0XA0KEY_MUTE
RETL0X40KEY_VOCAL
RETL0XE2KEY_VOL+
RETL0XA2KEY_VOL-
RETL0X52KEY_TUNEFWD
RETL0X22KEY_TUNEREV
RETL0X12KEY_STOP
RETL0X80KEY_<|
RETL0X82KEY_|>
RETL0X02KEY_OK
RETL0XF0KEY_TUNER
RETL0X78KEY_AM/FM
RETL0XF8KEY_SAVE
RETL0X50KEY_AUDIO
**********************表格转换程序OUT*********************
TABLE_CONVERSION_OUT:
MOVA,TEMP
ADDPC,A
RETL0X35KEY_1
RETL0X2DKEY_2
RETL0X25KEY_3
RETL0X1DKEY_4
RETL0X34KEY_5
RETL0X2CKEY_6
RETL0X24KEY_7
RETL0X1CKEY_8
RETL0X33KEY_9
RETL0X2BKEY_0
RETL0X10KEY_3D
RETL0X18KEY_MUTE
RETL0X11KEY_VOCAL
RETL0X16KEY_VOL+
RETL0X15KEY_VOL-
RETL0X28KEY_TUNEFWD
RETL0X2AKEY_TUNEREV
RETL0X22KEY_STOP
RETL0X31KEY_<|
RETL0X21KEY_|>
RETL0X29KEY_OK
RETL0X2EKEY_TUNER
RETL0X20KEY_AUX-1
RETL0X23KEY_AUX-2
RETL0X17KEY_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,6ST码的次高位反相
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,@2020-A
JBSPSW,C
JMPEXIT_0C=1,COUNTER>20
MOVA,COUNTER
BCPSW,C
SUBA,@1616-A
JBCPSW,C
JMPEXIT_0C=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
CONTWTCC开始记数
CONTINUE_2:
MOVA,TCC
MOVTEMP,A
BCPSW,C
SUBA,@250
JBSPSW,C
JMPSCAN_LEAD_CODEC=0,TCC>250
JBCPORT6,INPUT
JMPCONTINUE_2
MOVA,TCC
MOVTEMP,A
BCPSW,C
SUBA,@60142
JBCPSW,C
JMPX1C=1,TCC<60
JMPX2C=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,@2020-A
JBSPSW,C
JMPEXIT_2C=1,COUNTER>20
MOVA,COUNTER
BCPSW,C
SUBA,@1616-A
JBCPSW,C
JMPEXIT_2C=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,@77-A
JBSPSW,C
JMPNO_REPEATC=0,COUNTER>7
JMPYES_REPEATC=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