📄 tx.dt
字号:
;******************************************;
; 项目名称: 遥控器 V1
; 设计者: 小丁
; 完成日期: 2007年1月4日
; 芯片型号: EMC78P152s
; 振荡类型: IRC
; 频率: 4MHz/4Clock
; WDT: 开
; CHECKSUM: A7A1
;******************************************;
; P60 Key1
; P61 Key2
; P62 RF
; P63 GND
; P64 Not Used
; P65 Not Used
;========EM78常量定义======================;
Key_1_Data equ @0x01
Key_2_Data equ @0x02
;========EM78专用寄存器地址定义============;
include "em78p153.h" ;专用寄存器头文件见头文件包
;========EM78一般寄存器定义================;
;------------------------------------------;
Send_Buffer equ 0x10 ;1Byte 发送缓存
Used_Id_Num1 equ 0x11 ;1Byte 用户ID1
Used_Id_Num2 equ 0x12 ;1Byte 用户ID2
Key_Data equ 0x13 ;1Byte 按键码
Image_of_Tcc equ 0x14 ;1Byte TCC缓存
Key_Value equ 0x15 ;1Byte 按键值
IO_Buffer equ 0x16 ;1Byte IO口状态缓存
Random_Var equ 0x17 ;1Byte 随机变量
Delay_Counter equ 0x18 ;1Byte 延时计数
;========EM78一般控制位定义================;
;**************上电复位入口****************;
org 0
jmp System_Initialize
;**************用户码表入口****************;
Id_Table:
add pc,a
retl @0x82 ;Id_Num1(00~FF)
retl @0x83 ;Id_Num2(00~FF)
;****************系统初始化****************;
System_Initialize:
contw @0b00000111 ;Tcc rate 1:256
clr r5 ;
iow ioc5,@0b00000000
mov r6,@0b00001011
iow ioc6,@0b00001011
iow iocd,@0b11110100 ;P60~P62内部上拉
iow ioce,@0b10000000 ;开看门狗
;=======
iclr ;初始化清空变量
;=======
mov a,@0
call Id_Table
mov Used_Id_Num1,a
mov a,@1
call Id_Table
mov Used_Id_Num2,a
;****************主程序开始****************;
Main_Loop:
wdtc
Get_Tcc_Value:
mov a,tcc
xor a,Image_of_Tcc
and a,@0x08 ;修改此值可以改变按键灵敏度
jbc Status,z
jmp Main_Loop
xor Image_of_Tcc,a ;缓存tcc
;****************子程序开始*****************;
;===========================================;
; 程序名: Read_Key
; 功能: 读键程序
;===========================================;
Read_Key:
mov a,r6
and a,@0b00000011 ;读键
mov IO_Buffer,a
;=======================================;
mov a,IO_Buffer
xor a,@0b00000011
jbc status,z
jmp System_Sleep
;=======================================;
mov a,IO_Buffer ;读键
xor a,Key_Value
jbc status,z
jmp Same_Key_Status
;===================================;
xor Key_Value,a
No_Key_Pressed:
jmp Main_Loop
;===========================================;
Same_Key_Status:
;=======================================;
mov a,Key_Value
add pc,a
jmp Key_2 ;00
jmp Key_2 ;01
jmp Key_1 ;10
jmp No_Key_Pressed ;11
;=======================================;
Key_1:
mov Key_Data,@Key_1_Data
jmp Key_Ret
;=======================================;
Key_2:
mov Key_Data,@Key_2_Data
jmp Key_Ret
;=======================================;
Key_Ret:
;===========================================;
;-----------子程序Read_Key结束--------------;
;===========================================;
;****************子程序开始*****************;
;===========================================;
; 程序名: RF_Send
; 功能: 发射无线
;===========================================;
Rf_Port equ r6
Rf equ 2
;===========================================;
RF_Send:
mov a,Used_Id_Num1 ;发送用户码1
mov Send_Buffer,a
call Send_Data
;=======
mov a,Used_Id_Num2 ;发送用户码2
mov Send_Buffer,a
call Send_Data
;=======
mov a,Key_Data ;发送按键码
mov Send_Buffer,a
call Send_Data
;=======
bs Rf_Port,Rf
call Delay_300us
bc Rf_Port,Rf
call Delay_6000us
;=======
jmp Main_Loop
;=======================================;
Send_Data:
call Send_Bit ;D0
call Send_Bit ;D1
call Send_Bit ;D2
call Send_Bit ;D3
call Send_Bit ;D4
call Send_Bit ;D5
call Send_Bit ;D6
call Send_Bit ;D7
ret
;=======================================;
Send_Bit:
jbc Send_Buffer,0
call Send_Bit1
jbs Send_Buffer,0
call Send_Bit0
rrc Send_Buffer ;发送顺序控制
ret
;=======================================;
Send_Bit1:
bs Rf_Port,Rf
call Delay_500us
call Delay_500us
call Delay_500us
bc Rf_Port,Rf
call Delay_500us
ret
;=======================================;
Send_Bit0:
bs Rf_Port,Rf
call Delay_500us
bc Rf_Port,Rf
call Delay_500us
ret
;===========================================;
;-----------子程序RF_Send结束---------------;
;===========================================;
System_Sleep:
mov a,r6
and a,@0b00000011
xor a,@0b00000011
jbs status,z
jmp Main_Loop
wdtc ;清除WDT和预分频器
mov a,@0b00000000 ;关闭WDT
iow ioce
wdtc ;睡眠前关闭WDT
mov r6,r6
mov a,@0b00000010 ;使能P6的输入变化中断
iow iocf
disi
slep ;进入休眠
nop
jmp System_Initialize
;===========================================;
; 程序名: Delay
; 功能: 延时程序
;===========================================;
Delay_6000us:
mov Delay_Counter,@240
Delay_6000us_Loop:
call Delay_25us
djz Delay_Counter
jmp Delay_6000us_Loop
ret
;===========================================;
Delay_2000us:
mov Delay_Counter,@80
Delay_2000us_Loop:
call Delay_25us
djz Delay_Counter
jmp Delay_2000us_Loop
ret
;===========================================;
Delay_500us:
mov Delay_Counter,@20
Delay_500us_Loop:
call Delay_25us
djz Delay_Counter
jmp Delay_500us_Loop
ret
;===========================================;
Delay_300us:
mov Delay_Counter,@12
Delay_300us_Loop:
call Delay_25us
djz Delay_Counter
jmp Delay_300us_Loop
ret
;===========================================;
Delay_25us:;4M/4Clock
wdtc
nop;4
nop
nop
nop
nop;8
nop
nop
nop
nop;12
nop
nop
nop
nop;16
nop
nop
nop
nop;20
nop
nop
nop
nop;24
ret;26
;===========================================;
;------------子程序Delay结束----------------;
;===========================================;
;==========================================;
mov macro Reg,@Value
mov a,@Value
mov Reg,a
endm
;==========================================;
mov macro dReg,sReg
mov a,sReg
mov dReg,a
endm
;==========================================;
contw macro @Value ;contw
mov a,@Value
contw
endm
;==========================================;
iow macro Reg,@Value
mov a,@Value
iow Reg
endm
;==========================================;
xora macro dReg,sReg
mov a,dReg
xor a,sReg
endm
;==========================================;
xora macro Reg,@Value
mov a,Reg
xor a,@Value
endm
;==========================================;
suba macro Reg,@Value
mov a,Reg
sub a,@Value
endm
;==========================================;
suba macro @Value,Reg
mov a,@Value
sub a,Reg
endm
;==========================================;
imov macro dReg,sReg ;整数移动
rmov dReg+1,sReg+1
rmov dReg,sReg
endm
;==========================================;
iinc macro Reg ;int inc
inc Reg+1
jbc status,z
inc Reg
endm
;==========================================;
idec macro Reg ;int dec
mov Reg+1,Reg+1
jbc status,z
dec Reg
dec Reg+1
endm
;==========================================;
ineg macro Reg
com Reg+1
inc Reg+1
jbc status,z
dec Reg+0
com Reg+0
endm
;==========================================;
iadd macro dReg,sReg
mov a,sReg+1
add dReg+1,a
jbc status,c
inc dReg+0
mov a,sReg
add dReg+0,a
endm
;==========================================;
jnz macro Reg
mov Reg,Reg
jbc status,z
endm
;==========================================;
ijnz macro Reg
mov a,Reg+1
or a,Reg
jbc status,z
endm
;==========================================;
je macro sReg1,sReg2 ;相同
mov a,sReg1
xor a,sReg2
jbs status,z
endm
;==========================================;
jne macro sReg1,sReg2 ;不相同
mov a,sReg1
xor a,sReg2
jbc status,z
endm
;==========================================;
jh macro Reg1,Reg2 ;Reg1>Reg2?
mov a,Reg1
sub a,Reg2
jbc status,c
endm
;==========================================;
jl macro Reg1,Reg2 ;Reg1<Reg2?
mov a,Reg2
sub a,Reg1
jbc status,c
endm
;==========================================;
jlc macro Reg,@Value ;Reg<@Value?
mov a,@Value
sub a,Reg
jbc status,c
endm
;==========================================;
Table macro Reg
mov a,Reg
tbl
endm
;==========================================;
iclr macro ;indirect Clear Ram
mov a,@15
mov rsr,a
Initial_User_Ram: ;初始化清空变量
inc rsr
clr iar
mov a,rsr
and a,@0b00111111
xor a,@0b00111111
jbs status,z
jmp Initial_User_Ram
clr rsr
endm
;==========================================;
END
;==========================================;
;==========================================;
;==========================================;
;==========================================;
;==========================================;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -