?? main.asm
字號:
;==========================================================
;
; 模塊: FM發(fā)射模塊控制代碼
;
; 版本: 1.01
;
; 日期: 2007-7-28
;
; 作者: 施探宇
;
; 說明: Zi2020 應(yīng)用圖
;
; +-----+
; (106.7)P5.0 ===| |=== P5.1(PREV KEY)(POWER KEY)
; (107.1)P6.7 ===| |=== P5.2(NEXT KEY)
; (107.5)P6.6 ===| |=== P5.3(CE,Zi2020 高打開)
; Vdd ===| |=== Vss
; (107.9)P6.5 ===| |=== P6.0(音頻檢測)
; FM LED)P6.4 ===| |=== P6.1(SDA,Zi2020)
; (NC)P6.3 ===| |=== P6.2(SCL,Zi2020)
; +-----+
;
;==========================================================
include "reg.inc"
include "ir_code.inc"
;===========================================================
; Start()
;===========================================================
ORG 0x00
jmp Start
ORG 0x01
reti
ORG 0x08
DISI
jbc INT_STATU,@TC_FLAG_BIT ;計時中斷
jmp Time_Int
jbc INT_STATU,@EX_FLAG_BIT ;外部中斷p60
jmp Exent_Int0
jbc INT_STATU,@P6_FLAG_BIT ;腳位變化中斷
jmp Exent_Int1
reti
;------------------------------
; 程序開始
;------------------------------
ORG 0x20
Start:
DISI ;禁止中斷
call Init_Con_reg ;初始化控制寄存器
call CleanRam ;清除寄存器
call Init_Ioport ;初始化輸入輸出口
ENI ;開中斷
;===========================================================
; main()
;===========================================================
main:
call Get_Remote_Key ;獲得遙控按鍵
;call delay_1s
;mov a,@0x80
;xor P6,a
jmp main
;===========================================================
; main end
;===========================================================
;==============================================================================================
;計時中斷時間== (4*(256-TIME_COUNT)*時鐘周期)/fos(晶振頻率)
;100us int ones
;==============================================================================================
Time_Int:
;------------------------------
; 保存狀態(tài)寄存器
;------------------------------
mov pop_a,a
mov a,FLAG
mov pop_statu,a
;------------------------------
; 設(shè)定每次中斷時長
;------------------------------
mov a,@209d
mov TIME_COUNT,a
;------------------------------
;超過120毫秒后表示遙控按鍵己彈起
;------------------------------
inc Time_Int_Count
inc Time_Delay
mov a,Time_Delay
sub a,@60d
jbs FLAG,@Z
jmp return_t_int
inc Time_Delay1
clr Time_Delay
mov a,Time_Delay1
sub a,@20d
jbs FLAG,@Z
jmp return_t_int
clr Time_Delay1
clr Time_Delay
mov a,Status_1
and a,@0xFC
mov Status_1,a
;clr Ir_Repeat_Times
bc Status_1,@IR_KEY_DOWN_UP_BIT ;按鍵彈起
bc Status_1,@STATE_9M_BIT ;
return_t_int:
;*********************************************
time_Int_ret:
;------------------------------
; 恢復(fù)保存狀態(tài)
;------------------------------
mov a,pop_statu
mov FLAG,a
mov a,pop_a
bc INT_STATU,@TC_FLAG_BIT
reti
;==============================================================================================
;腳位變化中斷
;==============================================================================================
Exent_Int1:
;------------------------------
; 保存狀態(tài)寄存器
;------------------------------
mov pop_a,a
mov a,FLAG
mov pop_statu,a
;*********************************************
;*********************************************
Exent_Int1_ret:
;------------------------------
; 恢復(fù)保存狀態(tài)
;------------------------------
mov a,pop_statu
mov FLAG,a
mov a,pop_a
bc INT_STATU,@P6_FLAG_BIT
reti
;==============================================================================================
;外部中斷
;==============================================================================================
Exent_Int0:
;------------------------------
; 保存狀態(tài)寄存器
;------------------------------
mov pop_a,a
mov a,FLAG
mov pop_statu,a
;*********************************************
clr Time_Delay
clr Time_Delay1
jbc Status_1,@STATE_9M_BIT ;判斷是否是接收起始碼9毫秒狀態(tài)
jmp state_first
jbc Status_1,@STATE_2M_BIT ;
jmp state_third
bs Status_1,@STATE_9M_BIT ;設(shè)置狀態(tài)為接收9毫秒
jmp ex_int_ret
state_first:
mov a,Time_Int_Count
sub a,@IR_TIME_9000US+IR_TIME_4500US+10*IR_TIME_MARGIN
jbs FLAG,@C
jmp error_return
mov a,Time_Int_Count
sub a,@IR_TIME_9000US+IR_TIME_2250US-10*IR_TIME_MARGIN
jbc FLAG,@C
jmp error_return
mov a,Time_Int_Count
sub a,@IR_TIME_9000US+IR_TIME_4500US-10*IR_TIME_MARGIN
jbs FLAG,@C
jmp SET_SECN_2MS
inc Ir_Repeat_Times
jmp error_return
SET_SECN_2MS:
bs Status_1,@STATE_2M_BIT
bc Status_1,@STATE_9M_BIT
mov a,@0x20 ;接收碼值長度
mov Remote_Bit_Count,a
jmp ex_int_ret
state_third:
mov a,Time_Int_Count
sub a,@IR_TIME_2250US+3*IR_TIME_MARGIN ;允許誤差300us
jbs FLAG,@C
jmp error_return
mov a,Time_Int_Count
sub a,@IR_TIME_1125US-3*IR_TIME_MARGIN ;允許誤差300us
jbc FLAG,@C
jmp error_return
mov a,Time_Int_Count
;與當(dāng)中值(1125+2250)/2=1.6ms判斷是1或0
sub a,@(IR_TIME_2250US+IR_TIME_1125US)/2
rrc Remote_Cmd_Code1
rrc Remote_Cmd_Code0
rrc Remote_Sys_Code1
rrc Remote_Sys_Code0
dec Remote_Bit_Count
jbs FLAG,@Z
jmp ex_int_ret
set_ok:
;遙控碼接收完畢
clr Ir_Repeat_Times
bs Status_1,@IR_KEY_OK_BIT
bs Status_1,@IR_KEY_DOWN_UP_BIT
error_return:
;初始化接收狀態(tài)
bc Status_1,@STATE_2M_BIT
bs Status_1,@STATE_9M_BIT
ex_int_ret:
clr Time_Int_Count
;*********************************************
Exent_Int0_ret:
bc INT_STATU,@EX_FLAG_BIT
;------------------------------
; 恢復(fù)保存狀態(tài)
;------------------------------
mov a,pop_statu
mov FLAG,a
mov a,pop_a
reti
;------------------------------
;外部中斷結(jié)束
;------------------------------
;===============================================
; Includes Other Functions.
;===============================================
include "init_sys.asm"
include "key.asm"
include "time.asm"
END
;===============================================
; End of file.
;===============================================
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -