EM78P153范例程序

;芯片为em78p153
;p64,p65接晶振,振荡模式为4mhz晶振
;看门狗关,指令周期为2个clock,p63为复位脚
;*******************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
;********************表格转换子程序程序******************
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
;**********************表格转换程序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
;**********************表格转换程序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
;*********************扫描引导码**********************
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
;*********************接收数据**********************
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
;*********************发送数据**********************
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 ;调用码表转换子程序
mov code3,a
rep:
call transmit_data
bs port6,output
call judge_repeat_code ;扫描引导码是否在重复?
jbs flag,lead
jmp scan_lead_code
jbc flag,repeat
jmp rep ;引导码是重复,继续扫描
jmp receive_data_procee ;引导码不重复,去接收新数据
;****************引导码的检测子程序*****************
judge_start_code:
clr counter ;清计数器
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 ;停止记数
ret
hh:
bc psw,c
rlc tempcode
jmp continue_1
;****************发送数据子程序**********************
transmit_data:
mov a,@4
mov counter,a
mov a,user_code ;@0b10010000 ;发送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
;***************发送数据1子程序********************
send_code_1:
mov a,@0b00100000
contw ;停止记数
mov a,@0b00000001 ;允许tcc中断
iow iocf0
mov a,@35 ;引导脉冲的预置值
mov tcc,a
mov a,@0b00000001 ;选择预分频比为1:4
contw
bc port6,output
wait_1:
jbs rf,tcif
jmp wait_1
mov a,@0b00100000
contw ;停止记数
bc rf,tcif
mov a,@32 ;代码1的预置值
mov tcc,a
mov a,@0b00000101 ;选择预分频比为1:64
contw
bs port6,output
wait_2:
jbs rf,tcif
jmp wait_2
bc rf,tcif
mov a,@0b00100000
contw ;停止记数
ret
;***************发送数据0子程序********************
send_code_0:
mov a,@0b00100000
contw ;停止记数
mov a,@0b00000001 ;允许tcc中断
iow iocf0
mov a,@35 ;引导脉冲的预置值
mov tcc,a
mov a,@0b00000001 ;选择预分频比为1:4
contw
bc port6,output
wait_3:
jbs rf,tcif
jmp wait_3
mov a,@0b00100000
contw ;停止记数
bc rf,tcif
mov a,@114 ;代码0的预置值
mov tcc,a
mov a,@0b00000101 ;选择预分频比为1:64
contw
bs port6,output
wait_4:
jbs rf,tcif
jmp wait_4
nop
bc rf,tcif
mov a,@0b00100000
contw ;停止记数
ret
;****************重复码的检测子程序******************
judge_repeat_code:
clr counter ;清计数器
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

驱动电平对于液晶光阀输出图像的影响
五分钟看完上汽集团名爵锐腾 完成C-NCAP碰撞测试全过程
特瑞仕 | 线性稳压IC网络研讨会问答集锦,请查收~
展锐W117强续航+独立蜂窝 助力智能穿戴的独立时代
科比特全新无人机航电板发布,将给行业带来哪些红利
EM78P153范例程序
IDC:Q3全球可穿戴设备出货量达历史新高
2019年手机市场中的关键词大盘点 这些元素值得我们关注
华为开发者大会讲了什么?看完你就懂了!
分布式存储与传统数据存储方式有什么区别
MiR首次向中国市场引入其最近推出的MiR500自主移动机器人
区块链技术发展现状和趋势
肖特基势垒二极管的特征介绍
华为nova9系列的这些功能很实用,但你不一定了解
COHDA支持真实世界测试领域 5G Advanced网络技术演进白皮书2.0发布
普莱信打破封装设备多个领域国外垄断局面
逆导晶闸管(RCT)是什么?
摩托车里程表可使用双极霍尔传感器AH402F,兼容SS360
Flash盘的FAT结构分析
电子标签辅助拣货系统在工业生产行业的未来可期