📄 11x1_sirc.s43
字号:
; THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
; REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
; INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
; FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
; COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
; TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
; POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
; INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
; YOUR USE OF THE PROGRAM.
;
; IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
; CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
; THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
; OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
; OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
; EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
; REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
; OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
; USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
; AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
; YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
; (U.S.$500).
;
; Unless otherwise stated, the Program written and copyrighted
; by Texas Instruments is distributed as "freeware". You may,
; only under TI's copyright in the Program, use and modify the
; Program without any charge or restriction. You may
; distribute to third parties, provided that you transfer a
; copy of this license to the third party and the third party
; agrees to these terms by its first use of the Program. You
; must reproduce the copyright notice and any other legend of
; ownership on each copy or partial copy, of the Program.
;
; You acknowledge and agree that the Program contains
; copyrighted material, trade secrets and other TI proprietary
; information and is protected by copyright laws,
; international copyright treaties, and trade secret laws, as
; well as other intellectual property laws. To protect TI's
; rights in the Program, you agree not to decompile, reverse
; engineer, disassemble or otherwise translate any object code
; versions of the Program to a human-readable form. You agree
; that in no event will you alter, remove or destroy any
; copyright notice included in the Program. TI reserves all
; rights not specifically granted under this license. Except
; as specifically provided herein, nothing in this agreement
; shall be construed as conferring by implication, estoppel,
; or otherwise, upon you, any license or other right under any
; TI patents, copyrights or trade secrets.
;
; You may not use the Program in non-TI devices.
;
#include "msp430x11x1.h"
;*****************************************************************************
; MSP-FET430X110 Demo - Decode SIRC IR Remote Control / TX to PC @ 2400
;
; Description: Decode 12-bit SIRC format IR packet using Timer_A.
; Timer_A CCR1 is used to decode IR packet, capture mode to measure IR bit
; length. Received packet is TXed to PC using Timer_A CCR0 as a UART
; fuction. Packet sent as four ACII bytes, preceeded by a CR and LF
; character. P1.0 is set if channel+ is RXed, reset if not. IR data are
; received LSB first. Start, 12-bits of data.
; D4-D3-D2-D1-D0-C6-C5-C4-C3-C2-C1-C0-Start
;
; Demonstrate with IR monitor - TX IRData as CR, LF, 4 ASCII Bytes
;
; MSP430F1121
; -----------------
; /|\| XIN|-
; | | | 32kHz
; --|RST XOUT|-
; | |
; IR Receiver->|P1.2/CCR1 P1.0|--> LED0
; | P1.1|--> 2400 8N1
;
; Bit pattern as seen at MSP430
; Start = 2.4ms low ~ 79 @ 32kHz ACLK
; 1 = 1.2ms low
; 2 = 0.6ms low
; sync = 0.6ms high
;
; sync snyc snyc snyc
; ---+ +--- +--- +--- +--+ +-----
; | | | | | | | | | |
; +----\\----+ ---+ ------+ ---+ +---------+
; ^ 0 ^ 1 ^ 0 ^ Start ^
;
; CPU registers used
#define RXTXData R4
#define BitCnt R5
#define IRData R6
#define IRBit R7
#define IRlength R8
;
; Conditions for 2400 Baud SW UART, ACLK = 32768
Bitime_5 equ 06 ; .5 bit length + small adj.
Bitime equ 014 ; 427us bit length ~ 2341 baud
;
IR_Mid equ 49 ; 1500us @ 32768Hz ACLK
IR_Start equ 75 ; 2300us @ 32768Hz ACLK
IR_Start2 equ 82 ; 2500us @ 32768Hz ACLK
;
LED0 equ 001h ; LED0 on P1.0
TXD equ 002h ; TXD on P1.1
IRIN equ 004h ; IR input on P1.2
Ch_up equ 16 ;
Ch_dwn equ 17 ;
LF equ 0ah ; ASCII Line Feed
CR equ 0dh ; ASCII Carriage Return
;
; M. Buccini
; Texas Instruments, Inc
; July 2001
;*****************************************************************************
;-----------------------------------------------------------------------------
ORG 0F000h ; Program Start
;-----------------------------------------------------------------------------
RESET mov.w #0300h,SP ; Initialize 'x112x stackpointer
call #Init_Sys ; Initialize System Peripherals
;
Mainloop call #IR_Ready ; Ready IR decoder
bis.w #LPM0,SR ; Enter LPMx, stop, save power
call #TXIR_2_PC ; TX received command
call #LED_Disp ; Test for Channel +/-
jmp Mainloop ;
;
;-----------------------------------------------------------------------------
Init_Sys; Initialize System Peripherals
;-----------------------------------------------------------------------------
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop Watchdog Timer
SetupTA mov.w #TASSEL0+MC1,&TACTL ; ACLK, continous
SetupC0 mov.w #OUT,&CCTL0 ; TXD Idle as Mark
SetupP1 bis.b #IRIN+TXD,&P1SEL ; P1.2 CCR1, P1.1 CCR0
bis.b #LED0+TXD,&P1DIR ; P1.0, TXD outputs
bic.b #LED0,&P1OUT ; P1.0, low, LED off
eint ;
ret ; Return from subroutine
;
;-----------------------------------------------------------------------------
IR_Ready; Subroutine prepares to receive 12-bit SIRC into IRData buffer
;-----------------------------------------------------------------------------
clr.w IRData ;
clr.w IRlength ;
mov.b #14,IRBit ; Two start edges and 12 data bits
SetupC1 mov.w #CM1+SCS+CAP+CCIE,&CCTL1 ; CAP CCI1A,falling edge,int
ret ; Return from subroutine
;
;-----------------------------------------------------------------------------
TXIR_2_PC; Subroutine to send CR, LF and IRData as four ASCII bytes to PC
; R15 used as working register and not saved
;-----------------------------------------------------------------------------
mov #CR,RXTXData ; CR to UART buffer
call #TX_Byte ; CR --> PC/user
mov #LF,RXTXData ; LF to UART buffer
call #TX_Byte ; CR --> PC/user
;
TX_Word_ASCII; TX Word from IRData as four ASCII bytes
swpb IRData ; IRData = 3412
call #TX_Byte_ASCII ;
swpb IRData ; IRData = 1234
;
TX_Byte_ASCII; TX Byte from IRData in two ASCII bytes
mov.b IRData,R15 ; transmit ..x. of value
call #NUM_ASCIR ;
mov.b IRData,R15 ; transmit ...x of value
jmp NUM_ASCIA ;
;
NUM_ASCIR rrc.b R15 ; 1. and 3. pass
rrc.b R15 ;
rrc.b R15 ;
rrc.b R15 ;
;
NUM_ASCIA and.b #0fh,R15 ; 2. and 4. pass
add.b #030h,R15 ;
cmp.b #03ah,R15 ;
jlo NUM_End ;
add.b #039,R15 ;
NUM_End mov.b R15,RXTXData ; load transmit buffer, FALL
;
;-----------------------------------------------------------------------------
TX_Byte; Subroutine to TX Byte from RXTXData Buffer using CCR0 UART
;-----------------------------------------------------------------------------
mov.w &TAR,&CCR0 ; Current state of TA Counter
add.w #Bitime,&CCR0 ; Some time till first bit
bis.w #0100h, RXTXData ; Add mark stop bit to RXTXData
rla.w RXTXData ; Add space start bit
mov.w #10,BitCnt ; Load Bit Counter, 8 data + SP
mov.w #OUTMOD0+CCIE,&CCTL0 ; TXD = mark = idle
TX_Wait tst.w BitCnt ; Wait for TX completion
jnz TX_Wait ;
ret ;
;
;-----------------------------------------------------------------------------
TA0_ISR ; RXTXData Buffer holds UART Data
;-----------------------------------------------------------------------------
add.w #Bitime,&CCR0 ; Time to Next Bit
UART_TX bic.w #OUTMOD2,&CCTL0 ; TX Mark
rra.w RXTXData ; LSB is shifted to carry
jc TX_Test ; Jump --> bit = 1
TX_Space bis.w #OUTMOD2,&CCTL0 ; TX Space
TX_Test dec.w BitCnt ; All bits sent (or received)?
jnz TX_Next ; Next bit?
bic.w #CCIE,&CCTL0 ; All Bits TX/RX, Disable Int.
TX_Next reti ;
;
;-----------------------------------------------------------------------------
TAX_ISR; Common ISR - CCR1-4 and overflow
;-----------------------------------------------------------------------------
add.w &TAIV,PC ; Add Timer_A offset vector
reti ; CCR0 - no source
jmp TA1_ISR ; CCR1
; jmp TA2_ISR ; CCR2
; reti ; CCR3 - not used
; reti ; CCR4 - not used
;TA_over reti ; TA overflow - not used
;
TA1_ISR mov.w #CM0+SCS+CAP+CCIE,&CCTL1 ; CAP CCI1A,rising edge,int
IR_ST_Test push.w &CCR1 ; Temp save to stack CCR1 count
sub.w IRlength,0(SP) ; Time length last capture
cmp.b #14,IRBit ; First falling edge?
jeq IR_Next ; Jump --> first falling edge
cmp.b #13,IRBit ; Start bit?
jne IR_Bit ; Jump --> not start bit
; cmp.w #IR_Start2,0(SP) ; Start bit > 2.5ms
; jge IR_error ; Jump--> IRlength > 2.5ms
cmp.w #IR_Start,0(SP) ; Start bit minimum ~ 2.3ms
jge IR_Next ; Jump--> IRlength > 2.3ms
IR_error incd.w SP ; Clean up stack
call #IR_Ready ; ERROR - restart RX sequence
reti ; Return from interrupt
;
IR_Bit cmp.w #IR_Mid,0(SP) ; C=1 if IR RXed bit = 1
IR_Shift rrc.w IRData ; Carry ->IRData
IR_Next mov.w &CCR1,IRlength ; Save captured edge
incd.w SP ; Clean up stack
dec.b IRBit ;
jnz IR_Cont ; Jump--> not last bit
IR_Comp clr.w &CCTL1 ; Disable CCR1
rrc.w IRData ; 12-bit IRData right justified
rrc.w IRData ;
rrc.w IRData ;
rrc.w IRData ;
and.w #0FFFh,IRData ; Isolate 12-bit packet
mov.w #GIE,0(SP) ; Decode Byte = Active in Mainloop
IR_Cont reti ;
;
;-----------------------------------------------------------------------------
LED_Disp; LED0 (P1.0) set if IRData = Channel+ code (16)
;-----------------------------------------------------------------------------
and.w #07Fh,IRData ; Isolate 7-bit comand code
LED_off bic.b #01h,&P1OUT ; LED0 off
LED0_tst cmp.w #Ch_up,IRData ; Test for Channel+ (32)
jne LED_exit ;
bis.b #01h,&P1OUT ; LED0 on
LED_exit ret ; Return from subroutine
;
;
;-----------------------------------------------------------------------------
; Interrupt Vectors Used
;-----------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
ORG 0FFF2h ; Timer_A0 Vector
DW TA0_ISR ;
ORG 0FFF0h ; Timer_AX Vector
DW TAX_ISR ;
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -