Slaa 134
Slaa 134
Slaa 134
MSP430
ABSTRACT
This application report describes the use of Timer_A3 to decode RC5 and SIRC TV IR remote
control signals. The decoder described in this report is interrupt-driven and operates as a
background function using specific features the Timer_A3. Only a small portion of the
MSP430 CPUs nonreal-time resources is used. Specific hardware bit-latching capabilities
of the Timer_A3 module are used for real-time decoding of the IR data signal, independent
and asynchronous to the CPU. CPU activity and power consumption are kept to an absolute
minimum level. The Timer_A3 decoder implementation also allows other tasks to occur
simultaneously if required. The solutions provided are written specifically for MSP430x11x(1)
and MSP430x12x derivatives, but can be adapted to any other MSP430 incorporating
Timer_A3.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Clock Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Demonstration Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Decoding Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
RC5 Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Example 11x1_rc5.243 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
SIRC Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Example 11x1_SRC.s43 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
UART Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
PC Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Appendix A 11x1_SIRC.s43.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Appendix B 11x1_RC5.s43.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
List of Figures
1 IR Decoder Demonstration Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Inverted RC5 Data Packet as Seen by the MSP430 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Inverted SIRC Data Packet as Seen by the MSP430 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
SLAA134
Introduction
Adding TV remote-control decoding capability to an MSP430 application is a low-cost method of
enabling IR wireless communication. IR decoding capability can be added to an MSP430x11x(1)
application using one Timer_A3 capture/compare register, less than 200 bytes of code, and an
external sensor. See the demonstration circuit in Figure 1. For demonstration purposes, the
decoded IR information packets are transmitted serially to a PC and a LED illuminates on P1.0 if
a channel + code is received.
TPS77033
1
XOUT
7
32,768 Hz
14
RST/NMI
P1.1
5
2
4
3
VOUT
13
GND
RX
GND
40 kHz Modulated IR
15
EN
3
VCC
100 k
VCC
OUT
7
TX
P1.2
4
P1.0
680
VSS
DB9
LED
1 F
MSP430F1121
XIN
IN
4.7 F
SLAA134
Both RC5 and SIRC protocols transmit packets of information serially using a 40-kHz modulated
IR carrier. A logical 1 indicates the presence of 40-kHz modulated IR, and a 0 indicates its
absence. The 40-kHz modulation is used to filter out natural forms of IR present from sources
such as sunlight or office florescent lights. While 40 kHz is the most common modulation
frequency, some systems use other frequencies in the 32-kHz to 64-kHz range. In order to
decode RC5 or SIRC signals, the 40-kHz modulation must first be removed to expose the actual
data bits in the serial packet. A simple three-pin VISHAY TSOP1840SS3V 3-V integrated sensor
is used in this report to amplify, filter, and demodulate the IR signal, providing a clean logic-level
output with only the serial data present. With no 40-kHz IR modulation present, the sensor
output is high; when 40-kHz IR is present, the output is low. Thus, the sensor also has the effect
of inverting the transmitted data in addition to removing the modulation. The IR-sensor output is
connected directly to MSP430x11x(1) input pin P1.2. P1.2 is configured by software as a
capture/compare function for Timer_A3 capture/compare register 1 (CCR1) using the port 1
option-select (P1SEL) register. Using the capture/compare features of Timer_A3 enables much
easier decoding of the IR data. CCR1 does the IR data receive and transmit bit latching in
hardware, independent of CPU and other system activity. The IR decoding is done as a
background task using minimum CPU resources. To communicate the received IR data, a UART
is implemented using CCR0. The UART transmit function is configured on P1.1.
Clock Selection
Both RC5 and SIRC packet timings are relatively slow (>1 ms/bit) compared to the operation of
the MSP430. The demonstration circuit uses a common 32,768-Hz watch crystal as the source
for the auxiliary clock (ACLK), which is also selected as the Timer_A3 clock source. With this
clock source, Timer_A3 has a resolution of 30.5 smore than enough accuracy to resolve
either RC5 or SIRC protocols with no bit errors. The on-chip digitally-controlled oscillator (DCO)
is used at the default frequency of approximately 1 Mhz for the CPU master clock (MCLK). As
the 32,768 Hz watch crystal sources the clock for Timer_A3 and IR decoder function, CPU
speed is not critical. The CPU only needs to operate sufficiently fast to manage the tasks
required. Using the slower ACLK for the IR decoder and the faster DCO for the CPU, both
ultralow-power standby and fast-burst code execution are enabled. The MSP430 CPU must not
be clocked from the slow watch crystal to eliminate the occurrence of long interrupt latency and
higher power consumption. The CPU must be clocked fast, but in short interrupt-driven intervals,
to conserve power and allow rapid noncompromised program execution.
Demonstration Circuit
The demonstration circuit is powered directly by a PC serial port with regulation from a 3.3-V
TPS76033 low-dropout voltage regulator. One low-power LED is used in the circuit on P1.0 to
indicate if a channel + command has been received. A serial port interface on P1.1 is
implemented using a TI SN74AHC1G04 inverter. If a fully compliant RS232 interface is required,
integrated circuits such as TIs low-power 3-V MAX3221 can be used. Reset is pulled high and a
32,768 Hz watch crystal is used for clock generation. No phase-shift capacitors are required if a
watch crystal is used, as these are integrated in the MSP430 clock buffer.
SLAA134
Decoding Software
Two software examples are included. Example 11x1_rc5.s43 decodes the RC5 protocol, and
11x1_sirc.s43 decodes SIRC. The Mainloop of both examples is short and operates identically.
Only the background IR decoder software is unique.
Mainloop call
bis.w
call
call
jmp
#IR_Ready
#LPM3,SR
#TXIR_2_PC
#LED_Disp
Mainloop
;
;
;
;
;
Ready IR decoder
Enter LPM3, stop, save power
TX received command
Test for Channel +
The IR decoder function is enabled in Mainloop by calling the IR_Ready subroutine. Next,
software in the Mainloop sets bits in the CPU status register (SR) to put the system into
low-power mode 3 (LPM3). In LPM3, the CPU and DCO are off, but Timer_A3 is still counting
from the ACLK with CCR1 interrupt logic fully active. Even though the system is in LPM3, the
Timer_A3 driven decoder will run interrupt-driven in the background. The architecture of the
MSP430 automatically enables the CPU and DCO when any enabled interrupt is requested. The
DCO starts and becomes stable in less than 6 s. Short burst events can be processed
efficiently. Additionally, when an enabled interrupt occurs, the system automatically saves the
original SR on the stack and clears the SR low-power bits inside of the interrupt service routine.
After the interrupt service routine has been processed, the reti (return from interrupt) instruction
pops the original SR off the stack. The system returns to the previous state prior to the interrupt
service routineunless the SR on the stack is modified inside of the interrupt service routine.
In this report, after a complete IR packet has been received using the background CCR1
interrupt service routine, software returns the CPU to active in Mainloop by clearing the LPM3
bits from the SR saved on the stack. This is a convenient way of managing the Mainloop with
true event-driven programming. The received IR data packet is converted to four ASCII
characters and transmitted to a PC using 2400 baud 8N1 UART protocol by calling the
TXIR_2_PC subroutine. The four ASCII characters are preceded by a carriage return and
line-feed character. The active Mainloop completes by calling the LED_Disp subroutine. The
LED_Disp subroutine will set P1.0 to power the LED if the IR data packet is a channel +
command. The Mainloop repeats, waiting in LPM3 for the next IR data packet.
RC5 Protocol
The RC5 protocol is a type of Manchester encoded data packet. Manchester data is unique in
that a data is signified by a transition in the middle of the bit. A 1 is received by the MSP430
(after inversion by the IR sensor) as a high-to-low transition, and a 0 as a low-to-high transition.
The RC5 IR packet consists of 14 bits: two start bits (S1, S0), one control bit (C), five address
bits (A4 to A0), and a six bit command code (C5 to C0). The entire 14-bit packet is received
MSB first, starting with two start bits. Figure 2 shows the RC5 packet as received by the
MSP430 after demodulation and inversion from the IR sensor. The start bits are always
transmitted as 1. The control bit toggles whenever a new key is received. The five address bits
represent 32 different potential addresses of the equipment for which the packet is intended.
The six command bits represent 64 commands that can be transmitted. The bit period for RC5 is
1.78 ms long, with half of that period high and the other half low. The duration for the complete
14-bit packet is approximately 25 ms.
SLAA134
First Capture TAR Counter Value Latched in CCRx
Compare Logic Level Latched in SCCI
1.78 ms
S1
S0
Start
A4
A3
Control
A2
Address Code
A1
A0
C5
C4
C3
C2
C1
C0
Comand Code
Example 11x1_rc5.243
Two CPU registers are used in the 11x1_RC5.s43 example. IRData (R6) receives the RC5 IR
packet, and IRBit (R7) is used as a temporary counter to track the IR data bits as they are
received. The choice of R6 and R7 is arbitraryany two CPU registers or RAM bytes can be
used. Two variables are defined: Bit_50 is 1/2 of an RC5 1.78-ms bit length in Timer_A3 clocks
(same as ACLK), and Bit_75 is 1/4 of a bit length. As a 32,768-Hz watch crystal is used in this
report to generate the ACLK, BIT_50 and Bit_75 are as follows:
Bit_50
Bit_75
equ
equ
29
44
The subroutine IR_Ready enables CCR1 to capture the Timer_A3 counter register (TAR) and
request an interrupt on the falling edge of the IR sensor output, as configured on P1.2. TAR is
captured on the falling edge and automatically stored in CCR1 and a TA1_ISR interrupt is
requested. Inside of the TA1_ISR, software determines if the interrupt was triggered from a
capture or compare. As a capture was the source of the first interrupt, BIT_75 ( of a bit length)
is added directly to CCR1, which stored the exact time the IR sensor output edge fell in the
middle of the first bit. Because the stored CCR1 capture occurred in the middle of the first bit,
adding of a bit length will effectively offset CCR1 to the middle of the first half of the next bit.
CCR1 is now reconfigured by software to compare mode. The next CCR1 interrupt is now timed
for the middle of the first half of the second start bit. As configured, when the CCR1 compare
occurs, the logic level present at P1.2 will be latched into the registers synchronous capture
compare input (SCCI) latch. SCCI provides the very important feature of enabling CCR1
hardware to capture and store the logic level on P1.2 with the exact timing generated from
Timer_A3, irrespective of other system or CPU activities. In this application, the CPU is actually
off while the IR decoder is enabled. Even with the CPU off, the logic level of P1.2 will be
captured and stored in SCCI exactly when the CCR1 compare occurs. Software does not
directly read P1.2; instead it reads the latched data in SCCI after the event. Software will recover
received data from SCCI bit by bit, shifting the data into the storage register IRData.
SLAA134
RX_Cont
bit.w
rlc.w
#SCCI,&CCTL1
IRData
After each bit has been recovered, CCR1 is reconfigured to capture on both rising and falling
edges. The next capture will occur and self-synchronize on the next bits midpoint transition. To
insure the data packet is decoding properly, the CCR2 interrupt is also enabled and loaded with
a value of 1/2 the bit length of the compare stored in CCR1. The next bit transition received
should occur in approximately 1/4 of a bit length if the packet is decoding properly. Inside of a
normally occurring CCR1_ISR CCR1 edge capture, CCR2 interrupt is cleared by software. If
CCR1_ISR does not capture a normally occurring edge and clears the CCR2 interrupt,
CCR2_ISR will reset the decoder assuming an overrun error. In normal operation, the balance of
the bits are recovered and received into IRData.
SIRC Protocol
The SIRC protocol uses a data packet with an encoding scheme of variable bit length. The
length of a bit determines its logical value. The start bit is 2.4 ms of modulated IR, a 600-s 0,
and a 1.2-ms 1. All data bits, excluding the start bit, also include a 600-s sync pulse, or lack of
IR presence. The total length of a received 0, including the sync pulse, is therefore 1200 s, and
the total length of a 1 is 1800 s. A complete SIRC packet consists of the start bit and 12 data
bits. The 12 data bits are comprised of a seven-bit command code (C6 to C0) and a five-bit
device code (D4 to D0). The SIRC protocol sends data LSB first. C0 is the first bit received
following the start bit.
Figure 3 shows the SIRC data packet as received by the MSP430 after demodulation and
inversion from the IR decoder.
Last Capture
First Capture
Second Capture
D4
D3
D2
D1
1.2 ms
1.8 ms
1.8 ms
1.2 ms
D0
C6
C5
Device Code
C4
C3
Start
2.4 ms
C2
C1
Comand Code
C0
S
Start
Example 11x1_SRC.s43
Three CPU registers are used in the 11x1_SIRC.s43 example: IRData (R6) receives the IR data,
IRBit (R7) is used to track bits as they are received, and IRlength (R8) is used to store the length
of the data bits as they are received. Three variables are defined: IR_Mid is of an SIRC bit
length in Timer_A3 clocks, IR_Start is approximately 2.3 ms in Timer_A3 clocks (the minimum
length of a valid start bit), and IR_Start2 is approximately 2.5 ms in Timer_A3 clocks (the
maximum length of a valid start bit).
SLAA134
IR_Mid
IR_Start
IR_Start2
equ
equ
equ
49
75
82
The subroutine IR_Ready enables CCR1 to capture on a falling edge from the IR sensor
connected to P1.2. The MSP430 system is then placed in LPM3 with only ACLK and Timer_A3
active. On the first falling edge, indicating the beginning of the start bit, a CCR1 capture occurs
capturing TAR into CCR1 and requesting interrupt TA1_ISR. The count in TAR is automatically
captured and stored in CCR1 by hardware, no software is required. CCR1 is stored by software
in IRLength after the capture. After the first falling edge, CCR1 capture edge is switched to a
rising edge that will capture at the end of the start bit. The length of a data bit is calculated by
subtracting the current TAR capture stored in CCR1 from the previous saved in IRLength. If the
start bit length received is not between 2.3 ms and 2.5 ms, the decoder software will reset
assuming that an error has occurred. A valid start bit should be approximately 2.4 ms. Inside the
TA1_ISR, the IRBit is used to count down the 12 data bits as they are received. Each data bit is
calculated by comparing its bit length to IR_Mid. The length of IR_Mid is 1500 s, which is the
difference between a 1 and a 0. A bit length greater than IR_Mid is decoded as a 1, a length less
than IR_Mid is decoded as a 0. Hardware capturing of Timer_A3 insures that software interrupt
latency does not effect the accuracy of the captured timer value and the calculated bit length.
Software does not directly read Timer_A3, but instead, the latched timer value in CCR1. The
system stack is also used to temporarily save the current CCR1 value to be subtracted from the
previous in IRlength.
IR_ST_Test
IR_Bit
IR_Shift
push.w
sub.w
cmp.w
rrc.w
&CCR1
IRlength,0(SP)
#IR_Mid,0(SP)
IRData
;
;
;
;
With CCR1 hardware capturing the Timer_A3 value exactly when edges occur on P1.2, other
real-time activities can occur simultaneously with the IR decoder. The IR decoder software runs
interrupt-driven in the background. Data are shifted into IRData bit-by-bit under software control
after each bit has been received.
UART Software
The UART function is implemented with CCR0 and uses two CPU registers: RXTXData (R4)
and BitCnt (R5). A complete description of the UART function is provided in a separate
application report, please see the References section of this report.
PC Monitor
A standard PC terminal program can be used to receive the serial data packets transmitted from
the demonstration circuit. The 16-bit IRData are right justified and sent as four ASCII characters.
The terminal program must be set at 2400 baud 8N1.
References
1. MSP430x11x1 Mixed Signal Microcontroller datasheet, Texas Instruments literature number
SLAS241
2. MSP430x1xx Family Users Guide, Texas Instruments literature number SLAU049
3. Implementing a UART Function with Timer_A3, Texas Instruments literature number SLAA078
4. Photo Module for PCM Remote Control System, VISHAY literature number 82052
SLAA134
Appendix A
11x1_SIRC.s43.txt
You may,
; only under TIs copyright in the Program, use and modify the
; Program without any charge or restriction.
You may
To protect TIs
SLAA134
You agree
TI reserves all
msp430x11x1.h
;*****************************************************************************
;
;
;
D4D3D2D1D0C6C5C4C3C2C1C0Start
;
;
;
;
MSP430F1121
/|\|
| |
|RST
XIN|
| 32kHz
XOUT|
|
; IR Receiver>|P1.2/CCR1
P1.0|> LED0
;
;
1 = 1.2ms low
2 = 0.6ms low
SLAA134
;
;
sync
snyc
snyc
snyc
++
+\\+
++
Start
;
;
#define
RXTXData
R4
#define
BitCnt
R5
#define
IRData
R6
#define
IRBit
R7
#define
IRlength
R8
;
;
Bitime_5
equ
06
Bitime
equ
014
IR_Mid
equ
49
IR_Start
equ
75
IR_Start2
equ
82
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
CR
equ
0dh
;
;
M. Buccini
July 2001
;*****************************************************************************
;
ORG
0F000h
; Program Start
;
RESET
mov.w
#0300h,SP
call
#Init_Sys
10
SLAA134
Mainloop
call
#IR_Ready
; Ready IR decoder
bis.w
#LPM0,SR
call
#TXIR_2_PC
; TX received command
call
#LED_Disp
jmp
Mainloop
;
;
;
Init_Sys;
;
StopWDT
mov.w
#WDTPW+WDTHOLD,&WDTCTL
SetupTA
mov.w
#TASSEL0+MC1,&TACTL
; ACLK, continuous
SetupC0
mov.w
#OUT,&CCTL0
SetupP1
bis.b
#IRIN+TXD,&P1SEL
bis.b
#LED0+TXD,&P1DIR
bic.b
#LED0,&P1OUT
eint
ret
;
IR_Ready;
SetupC1
clr.w
IRData
clr.w
IRlength
mov.b
#14,IRBit
mov.w
#CM1+SCS+CAP+CCIE,&CCTL1
ret
;
TXIR_2_PC;
;
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
;
IRData
; IRData = 3412
call
#TX_Byte_ASCII
swpb
IRData
; IRData = 1234
11
SLAA134
;
TX_Byte_ASCII; TX Byte from IRData in two ASCII bytes
mov.b
IRData,R15
call
#NUM_ASCIR
mov.b
IRData,R15
jmp
NUM_ASCIA
;
;
NUM_ASCIR
rrc.b
R15
; 1. and 3. pass
rrc.b
R15
rrc.b
R15
rrc.b
R15
;
;
NUM_ASCIA
NUM_End
and.b
#0fh,R15
; 2. and 4. pass
add.b
#030h,R15
cmp.b
#03ah,R15
jlo
NUM_End
add.b
#039,R15
mov.b
R15,RXTXData
;
TX_Byte;
TX_Wait
mov.w
&TAR,&CCR0
add.w
#Bitime,&CCR0
bis.w
#0100h, RXTXData
rla.w
RXTXData
mov.w
#10,BitCnt
mov.w
#OUTMOD0+CCIE,&CCTL0
tst.w
BitCnt
jnz
TX_Wait
ret
;
;
;
TA0_ISR
;
UART_TX
TX_Space
12
add.w
#Bitime,&CCR0
bic.w
#OUTMOD2,&CCTL0
; TX Mark
rra.w
RXTXData
jc
TX_Test
bis.w
#OUTMOD2,&CCTL0
; TX Space
SLAA134
TX_Test
TX_Next
dec.w
BitCnt
jnz
TX_Next
; Next bit?
bic.w
#CCIE,&CCTL0
reti
;
;
;
TAX_ISR;
;
add.w
&TAIV,PC
reti
jmp
; CCR0 no source
TA1_ISR
; CCR1
jmp
TA2_ISR
; CCR2
reti
reti
;TA_over
reti
TA1_ISR
mov.w
#CM0+SCS+CAP+CCIE,&CCTL1
IR_ST_Test
push.w
&CCR1
sub.w
IRlength,0(SP)
cmp.b
#14,IRBit
jeq
IR_Next
cmp.b
#13,IRBit
; Start bit?
jne
IR_Bit
cmp.w
#IR_Start2,0(SP)
jge
IR_error
IR_error
cmp.w
#IR_Start,0(SP)
jge
IR_Next
incd.w
SP
; Clean up stack
call
#IR_Ready
reti
IR_Bit
cmp.w
#IR_Mid,0(SP)
IR_Shift
rrc.w
IRData
; Carry >IRData
IR_Next
mov.w
&CCR1,IRlength
incd.w
SP
; Clean up stack
dec.b
IRBit
jnz
IR_Cont
clr.w
&CCTL1
; Disable CCR1
rrc.w
IRData
rrc.w
IRData
IR_Comp
13
SLAA134
IR_Cont
rrc.w
IRData
rrc.w
IRData
and.w
#0FFFh,IRData
mov.w
#GIE,0(SP)
reti
;
;
;
LED_Disp;
;
and.w
#07Fh,IRData
LED_off
bic.b
#01h,&P1OUT
; LED0 off
LED0_tst
cmp.w
#Ch_up,IRData
jne
LED_exit
bis.b
#01h,&P1OUT
; LED0 on
LED_exit
ret
;
;
;
ORG
0FFFEh
DW
RESET
ORG
0FFF2h
; Timer_A0 Vector
DW
TA0_ISR
ORG
0FFF0h
; Timer_AX Vector
DW
TAX_ISR
END
14
SLAA134
Appendix B
11x1_RC5.s43.txt
You may,
; only under TIs copyright in the Program, use and modify the
; Program without any charge or restriction.
You may
To protect TIs
15
SLAA134
You agree
TI reserves all
msp430x14x.h
;*****************************************************************************
;
;
;
edge and compare mode to latch data bit. CCR2 is used for decoder
S1S2CA4A3A2A1A0C5C4C3C2C1C0
;
;
;
;
MSP430F1121
/|\|
| |
|RST
XIN|
| 32kHz
XOUT|
; IR Receiver>|P1.2/CCR1
P1.0|> LED
;
;
;
;
1.78ms
16
SLAA134
^Start^Start^
++
++
++
^ 0
|
+
;
;
#define
RXTXData
R4
#define
BitCnt
R5
#define
IRData
R6
#define
IRBit
R7
;
;
Bitime_5
equ
06
Bitime
equ
014
LED0
equ
001h
; LED0 on P1.0
TXD
equ
002h
; TXD on P1.1
IRIN
equ
004h
; IR input on P1.2
Bit_50
equ
29
Bit_75
equ
44
Ch_up
equ
32
Ch_dwn
equ
33
LF
equ
0ah
CR
equ
0dh
;
;
M. Buccini
July 2001
;*****************************************************************************
;
ORG
0F000h
; Program Start
;
RESET
mov.w
#0300h,SP
call
#Init_Sys
Mainloop
call
#IR_Ready
; Ready IR decoder
bis.w
#LPM3,SR
call
#TXIR_2_PC
; TX received command
call
#LED_Disp
jmp
Mainloop
;
;
17
SLAA134
;
Init_Sys;
;
StopWDT
mov.w
#WDTPW+WDTHOLD,&WDTCTL
SetupTA
mov.w
#TASSEL0+MC1,&TACTL
; ACLK, continuous
SetupC0
mov.w
#OUT,&CCTL0
SetupP1
bis.b
#IRIN+TXD,&P1SEL
bis.b
#LED0+TXD,&P1DIR
bic.b
#LED0,&P1OUT
eint
ret
;
IR_Ready;
SetupC1
clr.w
IRData
mov.w
#014,IRBit
mov.w
#CM1+SCS+CAP+CCIE,&CCTL1
ret
;
;
;
TXIR_2_PC;
;
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
;
IRData
; IRData = 3412
call
#TX_Byte_ASCII
swpb
IRData
; IRData = 1234
;
IRData,R15
call
#NUM_ASCIR
mov.b
IRData,R15
jmp
NUM_ASCIA
;
;
18
SLAA134
NUM_ASCIR
rrc.b
R15
; 1. and 3. pass
rrc.b
R15
rrc.b
R15
rrc.b
R15
;
;
NUM_ASCIA
NUM_End
and.b
#0fh,R15
; 2. and 4. pass
add.b
#030h,R15
cmp.b
#03ah,R15
jlo
NUM_End
add.b
#039,R15
mov.b
R15,RXTXData
;
TX_Byte;
TX_Wait
mov.w
&TAR,&CCR0
add.w
#Bitime,&CCR0
bis.w
#0100h, RXTXData
rla.w
RXTXData
mov.w
#10,BitCnt
mov.w
#OUTMOD0+CCIE,&CCTL0
tst.w
BitCnt
jnz
TX_Wait
ret
;
;
;
TA0_ISR
;
add.w
#Bitime,&CCR0
bic.w
#OUTMOD2,&CCTL0
; TX Mark
rra.w
RXTXData
jc
TX_Test
TX_Space
bis.w
#OUTMOD2,&CCTL0
; TX Space
TX_Test
dec.w
BitCnt
jnz
TX_Next
; Next bit?
bic.w
#CCIE,&CCTL0
UART_TX
TX_Next
reti
;
;
;
TAX_ISR;
19
SLAA134
;
add.w
&TAIV,PC
reti
jmp
TA1_ISR
; CCR1
jmp
TA2_ISR
; CCR2
reti
; CCR3
reti
; CCR4
;TA_over
reti
TA1_ISR
bit.w
#CAP,&CCTL1
jc
RX_edge
RX_Bit
RX_Cont
dec.w
IRBit
jz
RX_Comp
bit.w
#SCCI,&CCTL1
rlc.w
IRData
mov.w
#CM1+CM0+CAP+CCIE+SCS,&CCTL1
push.w
&CCR1
add.w
#Bit_50,0(SP)
pop.w
&CCR2
mov.w
#CCIE,&CCTL2
reti
;
;
RX_Comp
clr.w
&CCTL1
; Disable CCR1
and.w
#0FFFh,IRData
mov.w
#GIE,0(SP)
reti
;
;
RX_edge
clr.w
&CCTL2
mov.w
#CCIE,&CCTL1
add.w
#Bit_75,&CCR1
reti
;
;
TA2_ISR
clr.w
&CCTL2
call
#IR_Ready
reti
;
LED_Disp;
20
SLAA134
and.w
#03Fh,IRData
LED_off
bic.b
#01h,&P1OUT
; LED0 off
LED0_tst
cmp.w
#Ch_up,IRData
jne
LED_exit
bis.b
#01h,&P1OUT
; LED0 on
LED_exit
ret
;
;
;
ORG
0FFFEh
DW
RESET
ORG
0FFF2h
; Timer_A0 Vector
DW
TA0_ISR
ORG
0FFF0h
; Timer_AX Vector
DW
TAX_ISR
END
21
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,
enhancements, improvements, and other changes to its products and services at any time and to discontinue
any product or service without notice. Customers should obtain the latest relevant information before placing
orders and should verify that such information is current and complete. All products are sold subject to TIs terms
and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in
accordance with TIs standard warranty. Testing and other quality control techniques are used to the extent TI
deems necessary to support this warranty. Except where mandated by government requirements, testing of all
parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for
their products and applications using TI components. To minimize the risks associated with customer products
and applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right,
copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process
in which TI products or services are used. Information published by TI regarding thirdparty products or services
does not constitute a license from TI to use such products or services or a warranty or endorsement thereof.
Use of such information may require a license from a third party under the patents or other intellectual property
of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of information in TI data books or data sheets is permissible only if reproduction is without
alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction
of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for
such altered documentation.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that
product or service voids all express and any implied warranties for the associated TI product or service and
is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.
Mailing Address:
Texas Instruments
Post Office Box 655303
Dallas, Texas 75265