📄 ir.asm
字号:
;====================================================================================
; The information contained herein is the exclusive property of
; Sunplus Technology Co. And shall not be distributed, reproduced,
; or disclosed in whole in part without prior written permission.
; (C) COPYRIGHT 2004 SUNPLUS TECHNOLOGY CO.
; ALL RIGHTS RESERVED
; The entire notice above must be reproduced on all authorized copies.
;====================================================================================
;====================================================================================
; Program Name: IR.asm
; Applied body: SPMC65P2404*28P
; Description: Receiving,convert and showing datas
; Reference: SPMC65P2404 Programming Guide
; Author: Hailong Jiang/Sunnorth
; Revision history:
;------------------------------------------------------------------------------------
; Version Date Modify By Description
; 1.0.0 2004-12-13 Hailong Jiang First Edition
; 1.0.1 2005-1-12 Hailong Jiang Second Edition:transfer from SPMC652 to SPMC65P2404
;====================================================================================
.SYNTAX 6502 ;Process standard 6502 addressing syntax
.LINKLIST ;Generate linklist information
.SYMBOLS ;Generate symbolic debug information
;====================================================================================
.PAGE0
G_led_number DS 1 ;display data
G_ir_data DS 4 ;ir data
G_ir_time Ds 1 ;capture value
G_ir_number DS 1 ;the numbers of bit that have been reveived
G_ir_flag DS 1 ;reveiving control flag
C_ir_number .EQU 32 ;number size
C_start .EQU 0x01 ;reveiving start flag
C_over .EQU 0x04 ;reveiving over flag
.DATA
;====================================================================================
.CODE
;==================================================================================
; Function: F_Data_Change
; Description: convert the reveived datas to key value
; Input: G_ir_data
; Output: G_led_number
; Destroy: A,X
; Stacks: 1
;==================================================================================
F_Data_Change:
lda G_ir_flag
and #C_over ;reveive over?
beq ?_IR_end ;no
ldx #0
?_key_number_Loop:
lda T_KEY_number,x
cmp G_ir_data+2 ;data= tab data
beq ?_key_number ;yes
inx
cpx #10
bcs ?_error ;data is error?yes
jmp ?_key_number_Loop
?_key_number:
stx G_led_number ;get data
?_error:
lda G_ir_flag ;clear ir control flage
and #~C_over
sta G_ir_flag
?_IR_end:
rts
T_KEY_number:
.DB 0x90,0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10
;==================================================================================
; Function: F_IR_LED
; Description: Display LED
; Input: G_led_number
; Output: none
; Destroy: A
; Stacks: 1
;==================================================================================
F_IR_LED:
ldx G_led_number
cpx #10
bcs ?E_RROR
lda T_Segment,x
sta P_IOA_Data
?L_LED_END:
rts
?E_RROR: ;error cope
NOP
JMP ?L_LED_END
T_Segment:
.DB $3F ;0
.DB $6 ;1
.DB $5B ;2
.DB $4F ;3
.DB $66 ;4
.DB $6D ;5
.DB $7D ;6
.DB $7 ;7
.DB $7F ;8
.DB $6F ;9
;==================================================================================
; Function: F_IR_Receive
; Description: decode and save the reasult in a 4-byte data
; Input: G_ir_flag
; Output: 4-byte datas G_ir_data
; Destroy: A,X
; Stacks: 1
;==================================================================================
F_IR_Receive:
lda P_TMR3_CapHi
sta G_ir_time ;capture value
lda G_ir_flag
and #C_start ;First receive data? 0x01
bne ?_incetp_number_begin ;no
lda G_ir_time ;\
cmp #135 ;+
bcc ?_error_1 ;+=the front code(9ms)?
cmp #145 ;+
bcs ?_error_1 ;/
lda #C_start
sta G_ir_flag ;set start flag
jmp ?_incept_end
?_error_1:
jmp ?_error
?_incetp_number_begin:
lda G_ir_time ;\
cmp #14 ;+
bcc ?_error ;+= receive "0"?
cmp #22 ;+
bcs ?_incept_1 ;/
jmp ?_icept_number ;no
?_incept_1:
lda G_ir_time ;\
cmp #30 ;+
bcc ?_error ;+=receive "1"?
cmp #40 ;/
bcs ?_error ;yes
sec
?_icept_number:
rol G_ir_data+3
rol G_ir_data+2
rol G_ir_data+1
rol G_ir_data
inc G_ir_number
lda G_ir_number
cmp #C_ir_number ;receive end?
bne ?_incept_end ;no
?_write_end:
jsr F_Data_Checkup ;check up datas
beq ?_error
lda #C_over
sta G_ir_flag
lda #0
sta G_ir_number
jmp ?_incept_end
?_error:
lda #0
sta G_ir_data ;\
sta G_ir_data+1 ;+
sta G_ir_data+2 ;+=clear variable
sta G_ir_data+3 ;+
sta G_ir_number ;/
sta G_ir_flag
?_incept_end:
rts
;==================================================================================
; Function: F_Data_Checkup
; Description: check up the received datas
; Input: G_ir_data
; Output: Error flag: Z=1 datas is error
; Z=0 datas is right
; Destroy: A
; Stacks: 1
;==================================================================================
F_Data_Checkup:
lda G_ir_data
cmp G_ir_data+1
bne ?L_Error
cmp #$10
bne ?L_Error
lda G_ir_data+2
ora G_ir_data+3
cmp #$FF
bne ?L_Error
lda #99
jmp ?L_Exit
?L_Error:
lda #0
?L_Exit:
rts
;==================================================================================
; Function: F_IR_Init
; Description: IR init
; Input: none
; Output: none
; Destroy: A
; Stacks: 1
;==================================================================================
F_IR_Init:
;----------------------------------------------------------------
;init port
lda #0
sta P_IOA_Attrib
sta P_IOA_Data
lda #$FF
sta P_IOA_Dir
lda #0
sta P_IOB_Attrib
sta P_IOB_Data
sta P_IOB_Dir
;------------------------------------------------------
;1.024ms loop
lda #C_TBASE_Div_8k ;1.024ms
sta P_BUZ_Ctrl
;------------------------------
;initialize invariable
lda #0
sta G_ir_flag
sta G_led_number
sta G_ir_number
;------------------------------
;initialize cap3
;falling clear, falling INT
lda #$00 ;Set Timer3 preload counter= 0
sta P_TMR3_PreloadLo
lda #C_T3FCS_Div_512 ;Set Timer3 clock source is Fcs/512
sta P_TMR2_3_Ctrl1
lda #C_T38B_CAP ;Set Timer3 is 8-bit capture
sta P_TMR2_3_Ctrl0
lda #8 ;Falling edge clear counter
sta P_IRQ_Opt1
sta P_IRQ_Opt1
lda #$20 ;Be same with CAP3ES edge setting
sta P_CAP_Ctrl
lda #$FF ;clear INT request flag
sta P_INT_Flag0
lda #C_INT_CAP3IE ;Capture3 INT enable
sta P_INT_Ctrl0
rts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -