本文主要是介绍红外发射汇编代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
;一个定时器+pwm实现红外发射,
;代码运行过程中不会占住CPU不放,可以做到无阻塞响应其他功能
;----------------------------------------
;红外发射处理服务
;----------------------------------------
IR_TIMER:
JBSET F_IR_SEND
GOTO IR_NO_SEND
JBSET F_IR_DATA_OK
GOTO IR_DATA_READY
IR_DATA_SENDING:
MOVAI 1
ADDRA IR_INT_CNT
MOVAR IR_INT_CNT
ASUBAR IR_COUNT
JBSET C
GOTO IR_TIMER_EXIT
CLRR IR_INT_CNT
MOVAR IR_COUNT1
JBCLR Z
GOTO IR_TIMER_OUT
MOVAI 1
ADDRA IR_INT_CNT1
MOVAR IR_INT_CNT1
ASUBAR IR_COUNT1
JBSET C
GOTO IR_TIMER_EXIT
CLRR IR_INT_CNT1
IR_TIMER_OUT:
BCLR F_IR_DATA_OK
IR_DATA_READY:
CLRR IR_INT_CNT
CLRR IR_INT_CNT1
MOVAI 1
ADDRA IR_SEND_STATUS
IR_SEND_9MS_H:
MOVAR IR_SEND_STATUS
ASUBAI 1
JBSET Z
GOTO IR_SEND_4_5MS_L
MOVAI 113
CLRR IR_COUNT1
MOVRA IR_COUNT
BSET BUZ0OE
BSET TC0EN
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_4_5MS_L:
MOVAR IR_SEND_STATUS
ASUBAI 2
JBSET Z
GOTO IR_SEND_DATA
MOVAI 56
MOVRA IR_COUNT
CLRR IR_COUNT1
BCLR BUZ0OE
BCLR TC0EN
CLRR IR_DATA_BYTES
CLRR IR_DATA_BITS
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_DATA:
JBCLR F_DATA_SEND
GOTO IR_SEND_DATA_P1
MOVAI 1
ADDRA IR_DATA_BYTES
MOVAR IR_DATA_BYTES
ASUBAI 1
JBSET Z
GOTO IR_DATA_2ND
MOVAI VAL_IR_USER_C1
MOVRA IR_DATA
GOTO IR_SEND_DATA_P1
IR_DATA_2ND:
MOVAR IR_DATA_BYTES
ASUBAI 2
JBSET Z
GOTO IR_DATA_3RD
MOVAI VAL_IR_USER_C2
MOVRA IR_DATA
GOTO IR_SEND_DATA_P1
IR_DATA_3RD:
MOVAR IR_DATA_BYTES
ASUBAI 3
JBSET Z
GOTO IR_DATA_4TH
MOVAR IR_KEY_VAL
MOVRA IR_DATA
GOTO IR_SEND_DATA_P1
IR_DATA_4TH:
MOVAR IR_DATA_BYTES
ASUBAI 4
JBSET Z
GOTO IR_DATA_STOP
MOVAI 255
ASUBAR IR_KEY_VAL
MOVRA IR_DATA
GOTO IR_SEND_DATA_P1
IR_SEND_DATA_P1:
MOVAR IR_SEND_STATUS ;每位数据由固定560us的高电平+不同宽度的低电平组成
ASUBAI 3
JBSET Z
GOTO IR_SEND_DATA_P2
MOVAI 7
MOVRA IR_COUNT
CLRR IR_COUNT1
BSET F_DATA_SEND
BSET BUZ0OE
BSET TC0EN
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_DATA_P2:
MOVAR IR_SEND_STATUS ;每位数据由固定560us的高电平+不同宽度的低电平组成
ASUBAI 4
JBSET Z
GOTO IR_SEND_DATA_NEXT_BIT
MOVAI 21 ;1需要1.69ms低电平,进中断总次数21(1690/80=21)
JBSET IR_DATA,0 ;数据是从最低位开始发送的
MOVAI 7 ;0需要0.565ms低电平,进中断总次数7(565/8=7)
MOVRA IR_COUNT
CLRR IR_COUNT1
BSET F_DATA_SEND
BCLR BUZ0OE
BCLR TC0EN
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_DATA_NEXT_BIT: ;发送下一位数据
MOVAR IR_SEND_STATUS
ASUBAI 5
JBSET Z
GOTO IR_SEND_DATA_END
MOVAI 1
ADDRA IR_DATA_BITS
MOVAR IR_DATA_BITS
ASUBAI 8
JBCLR C
GOTO IR_SEND_DATA_NEXT_BYTE
RRR IR_DATA
MOVAI 3
MOVRA IR_SEND_STATUS
GOTO IR_SEND_DATA_P1
IR_SEND_DATA_NEXT_BYTE:
BCLR F_DATA_SEND
CLRR IR_DATA_BITS
MOVAI 3
MOVRA IR_SEND_STATUS
GOTO IR_SEND_DATA
IR_DATA_STOP:
MOVAR IR_SEND_STATUS
ASUBAI 3
JBSET Z
GOTO IR_SEND_DATA_END
MOVAI 6
MOVRA IR_SEND_STATUS
MOVAI 7
MOVRA IR_COUNT
CLRR IR_COUNT1
BSET F_DATA_SEND
BSET BUZ0OE
BSET TC0EN
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_DATA_END:
MOVAR IR_SEND_STATUS
ASUBAI 7
JBSET Z
GOTO IR_SEND_DATA_REPEAT
MOVAI 100
MOVRA IR_COUNT
MOVAI 5
MOVRA IR_COUNT1
BSET F_DATA_SEND
BCLR BUZ0OE
BCLR TC0EN
BSET F_IR_DATA_OK
GOTO IR_TIMER_EXIT
IR_SEND_DATA_REPEAT:
MOVAR IR_SEND_STATUS
ASUBAI 8
JBSET Z
; GOTO IR_SEND_DATA_REPEAT_2MS25_L
GOTO IR_SEND_FINISH
MOVAR IR_SEND_CISHU
ASUBAI 4
JBCLR C
; GOTO SEND_REPEAT_CODE
GOTO IR_SEND_FINISH
MOVAI 1
ADDRA IR_SEND_CISHU
MOVAR IR_SEND_CISHU
ASUBAI 4
JBCLR C
; GOTO SEND_REPEAT_CODE
GOTO IR_SEND_FINISH ;此版无论怎样按按键都连续发送4次数据码,然后停发
BCLR F_DATA_SEND
CLRR IR_SEND_STATUS
GOTO IR_DATA_READY
IR_SEND_FINISH:
; BCLR F_NO_STOP
IR_NO_SEND:
BCLR F_IR_SEND
BCLR F_IR_DATA_OK
BCLR F_DATA_SEND
CLRR IR_SEND_STATUS
CLRR IR_SEND_CISHU
IR_TIMER_EXIT:
这篇关于红外发射汇编代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!