DRM081
DRM081
RS08
Microcontrollers
DRM081
Rev. 0
6/2006
freescale.com
Multi-Button IR Remote Control using the MC9RS08KA2
Designer Reference Manual
To provide the most up-to-date information, the revision of our documents on the World Wide Web will be
the most current. Your printed copy may be an earlier revision. To verify that you have the latest
information available, refer to http://www.freescale.com
The following revision history table summarizes changes contained in this document. For your
convenience, the page number designators have been linked to the appropriate location.
Revision History
Revision Page
Date Description
Level Number(s)
Chapter 1
Introduction
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Freescale’s New Generation Ultra Low Cost MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Reference Demo Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 2
Fundamentals of IR Remote Control Communication
2.1 Configuration of the IR Remote Control Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Control Frame Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Chapter 3
System Concept
3.1 System Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Application Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Control Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Chapter 4
Hardware
4.1 Hardware Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 MC9RS09KA2 IR Remote Control Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.1 Oscillator Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.2 Keypad Scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 LCD and LED Display in Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.4 IR Transmitter Diode Drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.5 BDM Interface Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Chapter 5
Software Design
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2 Transmitter Flow Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3 Transmitter Software Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3.2 Key Decoding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.3.3 Transmission Control Frame Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Appendix A.
Schematic
Appendix B.
Program Listing
1.1 Introduction
This document describes a reference design for an infrared (IR) remote control (RC) solution using the
MC9RS08KA2 microcontroller.
For many air conditioner and small home appliance applications, there is a need for a wireless user
interface such as a remote control unit to send data from a transmitter to a receiver using infrared
communication. The basic requirements of an IR remote control unit are: lower power consumption in
standby mode; low operating voltage; low system cost; and easy code modification for customizing to
different models.
This reference design includes both the transmitter and the receiver unit. In this document, the focus is to
show the use of the 6-pin DFN packaged MC9RS08KA2 microcontroller unit (MCU) for the IR remote
control transmitter unit. For details on the receiver, please refer to the designer reference manual,
Freescale document, DRM082 – Infrared remote control using the MC68HC908LT8.
A feature of this reference design is a 6-pin BDM interface header for in-circuit FLASH programming and
debugging in the remote control transmitter.
1. The power consumption is dependant on application and system requirements. The 1µA assumes that all modules are turned
off except the internal clock source (ICS).
Chapter 2
Fundamentals of IR Remote Control Communication
REMOTE
CONTROL IR TX DIODE IR RX MODULE
TX MCU
Demodulated Digital
KEYPAD Control Signal
Infrared Rays
8µs
26µs
Frame Format
Header Data Code Data Code Data Code Customer Code
(8 bits) (8 bits) (8 bits) (8 bits)
9ms
13.5ms
Figure 2-2. Control Frame Waveform
Chapter 3
System Concept
C1 0 A/C OFF
1 A/C ON
0 0 0 AUTO mode(1) no temp. no sleep
custom
0 0 1 COOL mode(2) custom wind
temp.
custom
0 1 0 HUMIDITY mode(2) custom wind
temp.
custom
0 1 1 WIND mode(2) custom wind no sleep
temp.
custom
1 0 0 HEAT mode(3) custom wind
temp.
0 0 °C
0 1 Reserved
1 0 °F (Lower range)
1 1 °F (Higher range)
0 Light ON
1 Light OFF
X Reserved
C2 0 Sleep OFF
1 Sleep ON
0 Swing OFF
1 Swing ON
0 0 AUTO Wind Speed
0 1 LOW Wind Speed
1 0 MIDDLE Wind Speed
1 1 HIGH Wind Speed
°C °F °F
Temperature
C1[3:2] = 0:0 C1[3:2] = 1:0 C1[3:2] = 1:1
0 0 0 0 15°C 59°F 75°F
0 0 0 1 16°C 60°F 76°F
0 0 1 0 17°C 61°F 77°F
0 0 1 1 18°C 62°F 78°F
Since each customer has their own requirements and definitions, Table 3-1 only includes the general and
common control parameters. Additional parameters can be added, thus increasing the frame length by
the additional control bytes.
Chapter 4
Hardware
potential on the ACMP– pin. When a KBI occurs the RC network (R11 and C3) on ACMP+ starts charging.
Which button is pressed is determined by counting the time for the charge voltage on ACMP+ to equal
the resistor divider voltage on ACMP–.
VDD
1 1
R11 R10
4.70K
2 2 4.70K
1 1
C3 C4
0.068uF 1uF
2 2
GND GND
ACMP+
ACMP-
1 1 1 1 1 1 1 1 1
R1 R2 R3 R4 R5 R6 R7 R8 R9
931 1.58K 2.37K 3.32K 4.70K 6.65K 9.31K 14.0K 23.7K
2 2 2 2 2 2 2 2 2
KBI2
1 S1 1 S2 1 S3 1 S4 1 S5 1 S6 1 S7 1 S8 1 S9
3 3 3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2
GND
S1: ON/OFF S6: MODEL
S2: MODE S7: SLEEP
S3: WIND S8: LIGHT
S4: + S9: SWING
S5: -
Operating Modes
LOW
(1-bar ON)
Temperature
MIDDLE
(3-bar ON)
HIGH
(5-bar ON)
VDD
NDS7002A IR_LED
Q1 D1 R14
2 3 1 2 1 2
2.2
GND
220 R12
VDD
U1 P1
VSS 2 1
RST 4 3
VDD 6 5
KA2
GND
BKGD
Figure 4-4 shows the connection between the BDM header (P1) with MC9RS08KA2 in the transmitter
unit. To reprogram or debug code, just connect the hardware interface board between the PC and the
BDM header. For normal transmitter unit operation, pins 3 and 4 are shorted, and the RST pin becomes
the KBI2 pin.
Chapter 5
Software Design
5.1 Introduction
This chapter describes the software design for the IR remote controller reference design. This includes
outlines for the following:
• General flow chart
• Transmitter software implementation
5.3.1 Initialization
After transmitter power on, the following are initialized on the MC9RS08KA2 MCU:
• ICS trimmed to 16-MHz, ± 2%
• Clear COP counter
• Set configuration registers
– Disable COP and RTI
– Enable LVI
– Disable IRQ
• Initialize system variables
• Initialize control frame data
• Initialize GPIO A modules
– All GPIO as outputs low except PTA2
– sets A0 and A1 to logic high
• Initialize timer module
– Set clock source to bus frequency divide-by-64
• Enable KBI2 pin for falling-edge trigger interrupts
After initialization, the main routine will enter and remain in stop mode for power saving (stop IDD = 1µA)
until a button is pressed. On wake up, the button is software debounced and decoded, the control frame
updated, and the frame transmitted out. After the IR signal is transmitted, the system will return to stop
mode again, ready to detect a button press.
START
Initialization
stop mode
Button Y Y Button
Pressed? Released?
N N
Decode Keys
Update
Control Frame
Transmit IR Frame
The flow chart in Figure 5-1 shows that when a button is pressed, the system will wake up from stop mode.
After that, key decoding is performed. The detail operation of the key decoding is shown in the flow chart
of Figure 5-2. When the system wakes up, the keyboard interrupt will be disabled and key debounce
performed to eliminate the noise that may trigger a wrong key pressed. After key debounce, key decoding
is performed to determine which button is pressed. This reference design uses an emulated ADC to find
out which key is pressed. When a key is pressed, both comparator pins (ACMP+ and ACMP–) and the
timer will be enabled and timer count starts. The voltage on the ACMP– pin is dependent on the resistor
divider that is connected to the keys on the keypad. The timer counts the period for the voltage on the
ACMP+ pin to charge up until it is equal to the voltage on the ACMP– pin. When the two voltages are
equal, an interrupt will occur and the timer count is recorded. As each button has a different voltage and
hence, different timer counts, the button pressed can be determined.
When the key is identified, the control frame will be updated according the function of the key. The frame
is then transmitted out through the IR transmitter diode with 38kHz, 1/3 duty, cycle carrier.
Key Scan
Discharge capacitor
in ACMP+ pin
Is voltage No
on ACMP+/–
same? The voltage on ACMP+ will charge up until
it is equal to the voltage on ACMP–.
Yes
The voltage on ACMP– is determined by the
different potential divider for each keys.
Disable Comparator
Key identified by
charging time
Update
Control Frame
Return
VDD
VDD
1
1 1 1
D D
1
DC1 C1 C2 B1
0.1uF
Schematics
Schematic
Appendix A.
2 2 1uF/6V 2 10uF/6V
2
R14
Appendix A.
VDD
2 2.2
GND
Freescale Semiconductor
2
IR_LED
D1
1 1
1
R11 R10
4.70K
3
2 2 4.70K
Q1 R12
1 1 2
NDS7002A
220 1 1
2
C C
C3 C4
0.068uF 1uF
2 2
GND GND
GND U1
/RST 1 6 ACMP+
PA2/K2/RST PA0/K0/A+
PTA3 2 5 ACMP-
PA3/AO/BKGD PA1/K1/A-
VDD 3 4 GND
VDD VSS
1 1 1 1 1 1 1 1 1
9RS08KA2FP
GND
R1 R2 R3 R4 R5 R6 R7 R8 R9
931 1.58K 2.37K 3.32K 4.70K 6.65K 9.31K 14.0K 23.7K
2 2 2 2 2 2 2 2 2
1 S1 1 S2 1 S3 1 S4 1 S5 1 S6 1 S7 1 S8 1 S9
3 3 3 3 3 3 3 3 3
B B
2 2 2 2 2 2 2 2 2
P1
GND 2 1 PTA3 GND
/RST 4 3 KBIP2 S1: ON/OFF S6: MODEL
VDD 6 5
S2: MODE S7: SLEEP
BDM HEADER S3: WIND S8: LIGHT
A A
Transmitter Software Implementation
25
FREESCALE SEMICONDUCTOR HK LTD. DATE: 03/04/06
DESCRIPTION: MC9RS08KA2 REMOTE CONTROL REFERENCE DEMO(M68DEMOKA2RC1) REV: 0.1 SHEET 01 of 01
5 4 3 2 1
Software Design
Appendix B.
Program Listing
;**************************************************************
;
; (c) copyright Freescale Semiconductor. 2006
; ALL RIGHTS RESERVED
;
;**************************************************************
;**************************************************************
;* Remote Control Coding for 9RS08KA2
;*
;* Author: T.C. Lun
;* Date: Feb 2006
;*
;* PTA0/KBI0/ACMP+ Keypads input
;* PTA1/KBI1/ACMP- RC input
;* PTA2/KBI2/TCLK/RESETb/VPP KBI for S6-S9
;* PTA3/ACMPO/BKGD/MS Unused
;* PTA4/KBI4 KBI for S1-S5
;* PTA5/KBI5 IR output
;**************************************************************
; include derivative specific macros
XDEF Entry
include "MC9RS08KA2.inc"
;=========================================================================
; ICS Definition
;=========================================================================
ICS_DIV_1 equ $00
ICS_DIV_2 equ $40
ICS_DIV_4 equ $80
ICS_DIV_8 equ $c0
;=========================================================================
; MTIM Definition
;=========================================================================
MTIM_DIV_1 equ $00
MTIM_DIV_2 equ $01
MTIM_DIV_4 equ $02
MTIM_DIV_8 equ $03
MTIM_DIV_16 equ $04
MTIM_DIV_32 equ $05
MTIM_DIV_64 equ $06
MTIM_DIV_128 equ $07
MTIM_DIV_256 equ $08
;=========================================================================
; ACMP Definition
;=========================================================================
ACMP_OUTPUT_FALLING equ $00
ACMP_OUTPUT_RAISING equ $01
ACMP_OUTPUT_BOTH equ $03
;=========================================================================
; RTI Definition
;=========================================================================
RTI_DISABLE equ $00
RTI_8MS equ $01
RTI_32MS equ $02
RTI_64MS equ $03
RTI_128MS equ $04
RTI_256MS equ $05
RTI_512MS equ $06
RTI_1024MS equ $07
;=========================================================================
; Application Definition
;=========================================================================
RC equ PTAD_PTAD0
mRC equ mPTAD_PTAD0
TEMPSEN equ PTAD_PTAD1
mTEMPSEN equ mPTAD_PTAD1
KEY equ PTAD_PTAD2
mKEY equ mPTAD_PTAD2
IR equ PTAD_PTAD3
mIR equ mPTAD_PTAD3
Test equ PTAD_PTAD5
mTest equ mPTAD_PTAD5
mTest1 equ mPTAD_PTAD4
;(Value for Tx frame delay call for 0.5mS delay) for FSL
Head_Time_ON equ $10 ; Carrier on time for heading (8mS) 16*0.5ms
Head_Time_OFF equ $08 ; Carrier off time for heading (4mS) 8*0.5ms
;=========================================================================
; Application Macro
;=========================================================================
StartTimer: macro
mov DelayPeriod, MTIMMOD ; OF period
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
endm
StopTimer: macro
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC ; Reset and Stop Timer
endm
org TINY_RAMStart
; variable/data section
KeyRead ds.b 1 ; ADC value from Keypad [00]
Tx_Data10 ds.b 1 ; Nibble 1-0 (first 4-bit will be shift out)=%0000xxxx [06]
Tx_Data32 ds.b 1 ; Nibble 3-2 =%10010000 [07]
Tx_Data54 ds.b 1 ; Nibble 5-4 =%00000001 [08]
Tx_CtmCode ds.b 1 ; Nibble 9-8 (last bit will be shift out)=%x0100101 [09]
org RAMStart
; variable/data section
Tmp3 ds.b 1 ; Tmp [20]
;....
Tmpx ds.b 1 ; Tmp [4F]
org ROMStart
; code section [3800]
main:
Entry:
;-------------------------------------------------------
; Config ICS
; Device is pre-trim to 16MHz ICLK frequency
; TRIM value are stored in $3FFA:$3FFB
;-------------------------------------------------------
mov #HIGH_6_13(NV_ICSTRM), PAGESEL; Select $3FC0 - $3FFF
mov MAP_ADDR_6(NV_FTRIM), ICSSC ; $3FFB -> ICSSC
mov MAP_ADDR_6(NV_ICSTRM), ICSTRM ; $3FFA -> ICSTRIM
mov #ICS_DIV_4, ICSC2 ; Use 2MHz
;-------------------------------------------------------
;Config System
;-------------------------------------------------------
mov #HIGH_6_13(SOPT), PAGESEL ; Init Page register
mov #(mSOPT_COPT|mSOPT_STOPE), MAP_ADDR_6(SOPT) ; SOPT, COP disabled
mov #(mSPMSC1_LVDE|mSPMSC1_LVDRE), MAP_ADDR_6(SPMSC1) ; LVI enable
mov #(RTI_DISABLE), MAP_ADDR_6(SRTISC) ; RTI disable
;-------------------------------------------------------
; Init RAM
;-------------------------------------------------------
clr KeyRead
; ----------------------------------------------------------------------------- *
; System Variable Init
; ----------------------------------------------------------------------------- *
clr Tx_Flag ; Initial Tx flag
;-------------------------------------------------------
;Key Scan Start
;-------------------------------------------------------
KeyScanStart:
jsr Delay_5mS
jsr Delay_5mS
jsr Delay_5mS
lda KeyRead
Key_Error:
bra KeyScanStart
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Delay 8ms
; [8.0ms delay, Timer clock = bus / 64 = 32us, 32us*313=10.0ms]
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Delay_1mS:
mov #31, MTIMMOD ; OF period (1ms)
bra DelayX
Delay_3mS:
mov #94, MTIMMOD ; OF period (3ms)
bra DelayX
Delay_4mS:
mov #125, MTIMMOD ; OF period (3ms)
bra DelayX
Delay_5mS:
mov #156, MTIMMOD ; OF period (5ms)
bra DelayX
Delay_6mS:
mov #188, MTIMMOD ; OF period (6ms)
bra DelayX
Delay_7mS:
mov #219, MTIMMOD ; OF period (7ms)
bra DelayX
Delay_8mS:
mov #250, MTIMMOD ; OF period (8ms)
DelayX:
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
wait
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC ; mask interrupt and clear flag
rts
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Delay Xms (1-8mS)
; [8.0ms delay, Timer clock = bus / 64 = 32us, 32us*156=1-8ms]
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Delay_XmS:
sta MTIMMOD ; OF period
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC; Reset and Start Timer
wait
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Read Keypad voltage Value
; Timer prescalar=8 -> Timer clk~250kHz
; Bus = 2MHz
; Max OF period = 1.02ms
; Timer resolution = 4us
; [i/p: ACMP interrupt]
; [o/p: KeyRead]
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReadSensor:
mov #(MTIM_BUS_CLK|MTIM_DIV_8), MTIMCLK ; Change Timer resolution
mov #255, MTIMMOD ; OF period
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
NoReading:
mov #$FF, KeyRead ; Biggest Number
clr ACMPSC ; disable ACMP
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC ; mask interrupt and clear flag
mov #(MTIM_BUS_CLK|MTIM_DIV_64), MTIMCLK ; Reset Timer resolution
rts
; ----------------------------------------------------------------------------- *
; Tx Data Update
; ----------------------------------------------------------------------------- *
; ----------------------------------------------------------------------------- *
S1_Key: ; ON/OFF Key pressed(ON/OFF)
brclr 7,Tx_Data10,S1_ON ; Check ON/OFF status
S1_ON:
bset 7,Tx_Data10 ; Change to ON state
Clear_T_S:
bclr 3,Tx_Data32 ; Clear Sleep
bclr 3,Auto_Mode
bclr 3,Cool_Mode
bclr 3,Humd_Mode
bclr 3,Wind_Mode
bclr 3,Heat_Mode
bset TX_READY,Tx_Flag ; Tx ready
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S2_Key: ; Modes Key pressed (MODE)
; (Auto>Cool>Humd>Wind>Heat)
brclr 7,Tx_Data10,Slip_S2 ; No action if S1=OFF
Inc_Modes:
inca
lsla
lsla
lsla
lsla
sta Tx_Data_Temp ; Store higher nibble
lda Tx_Data10
and #%00001111 ; mask higher nibble
ora Tx_Data_Temp
sta Tx_Data10
bset TX_READY,Tx_Flag ; Tx ready
lda Tx_Data10
and #%01110000
cmp #%00000000 ; Check Auto mode?
beq Auto_2_D32
cmp #%00010000 ; Check Cool mode?
beq Cool_2_D32
Auto_2_D32:
mov Auto_Mode,Tx_Data32
bra End_S2
Cool_2_D32:
mov Cool_Mode,Tx_Data32
bra End_S2
Humd_2_D32:
mov Humd_Mode,Tx_Data32
bra End_S2
Wind_2_D32:
mov Wind_Mode,Tx_Data32
Slip_S2:
End_S2:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S3_Key: ; "Fan Speed" Key pressed (WIND)
; (Auto>low>mid>high)
brclr 7,Tx_Data10,Slip_S3 ; No action if AC OFF
Rst_Wind:
bclr 0,Tx_Data32
bclr 1,Tx_Data32 ; Change to Min. value (Auto)
End_S3:
jsr Data32_To_Modes ; Check & update Data32 & Modes
bset TX_READY,Tx_Flag ; Tx ready
Slip_S3:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S4_Key: ; + Key pressed for oC / Model Set (^)
S4_Normal:
brclr 7,Tx_Data10,Slip_S4 ; No action if S1=OFF
lda Tx_Data10
and #%01110000
lda Tx_Data32
lsra ; shift higher nibble to lower nibble
lsra ; All higher nibble is %0000
lsra
lsra
inca
lsla
lsla
lsla
lsla
sta Tx_Data_Temp ; Store higher nibble
lda Tx_Data32
and #%00001111 ; mask higher nibble
ora Tx_Data_Temp
sta Tx_Data32
No_Inc_Data32:
jsr Data32_To_Modes ; Check & update Data32 & Modes
bset TX_READY,Tx_Flag ; Tx ready
bset S34_KEY_ON,Key_Flag
Slip_S4:
End_S4:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S5_Key: ; - Key pressed for oC / Model Set (v)
S5_Normal:
brclr 7,Tx_Data10,Slip_S5 ; No action if S1=OFF
lda Tx_Data10
and #%01110000
beq Slip_S5 ; No action if in Auto Mode
lda Tx_Data32
lsra ; shift higher nibble to lower nibble
lsra ; All higher nibble is %0000
lsra
lsra
cmp #%00000000 ; Is reach Min $0000, No need Dec
beq No_Dec_Data32
deca
lsla
lsla
lsla
lsla
sta Tx_Data32
No_Dec_Data32:
jsr Data32_To_Modes ; Check & update Data32 & Modes
bset TX_READY,Tx_Flag ; Tx ready
bset S34_KEY_ON,Key_Flag
Slip_S5:
End_S5:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S6_Key: ; "Model Set" Key pressed (SET)
; Model Number cannot be change
; due to no LCD in KA2 demo
brclr 3,Tx_Data54,Model_Set
Model_Confirm:
bclr 3,Tx_Data54 ; Model Confrim (MODEL ON)
bra End_S6
Model_Set:
bset 3,Tx_Data54 ; Model Set (MODEL flash)
End_S6:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S7_Key: ; Sleep Key pressed (OK)
brclr 7,Tx_Data10,Slip_S7 ; No action if S1=OFF
; Here AC ON
lda Tx_Data10
and #%01110000 ; mask all bit except b6-4
cmp #%00010000 ; Check Cool mode (001)
beq Sleep_ON_Cool
cmp #%00100000 ; Check Humd mode (010)
beq Sleep_ON_Humd
cmp #%01000000 ; Check Heat mode (100)
beq Sleep_ON_Heat
bra Slip_S7 ; Slip if in others modes
Sleep_ON_Cool:
bset 3,Cool_Mode
bra Set_Data32
Sleep_ON_Humd:
bset 3,Humd_Mode
bra Set_Data32
Sleep_ON_Heat:
bset 3,Heat_Mode
Set_Data32:
bset 3,Tx_Data32 ; OFF -> ON
bset TX_READY,Tx_Flag ; Tx ready
bra End_S7
lda Tx_Data10
and #%01110000 ; mask all bit except b6-4
cmp #%00010000 ; Check Cool mode (001)
beq Sleep_OFF_Cool
cmp #%00100000 ; Check Humd mode (010)
beq Sleep_OFF_Humd
cmp #%01000000 ; Check Heat mode (100)
beq Sleep_OFF_Heat
bra Slip_S7
Sleep_OFF_Cool:
bclr 3,Cool_Mode
bra Clr_Data32
Sleep_OFF_Humd:
bclr 3,Humd_Mode
bra Clr_Data32
Sleep_OFF_Heat:
bclr 3,Heat_Mode
Clr_Data32:
bclr 3,Tx_Data32 ; OFF -> ON
bset TX_READY,Tx_Flag ; Tx ready
bra End_S7
Slip_S7:
End_S7:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S8_Key: ; Light Key pressed (M.WIND)
brset 1,Tx_Data10,Light_OFF ; Check ON/OFF? (1=ON)
bset 1,Tx_Data10 ; OFF -> ON
bset TX_READY,Tx_Flag ; Tx ready
bra End_S8
Light_OFF:
bclr 1,Tx_Data10 ; ON -> OFF
bset TX_READY,Tx_Flag ; Tx ready
End_S8:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
S9_Key: ; Swing Key pressed (A.M.WIND)
brclr 7,Tx_Data10,Slip_S9 ; No action if S1=OFF
; Here (S1=ON)
brset 2,Tx_Data32,Swing_OFF ; Check ON/OFF? (1=ON)
bset 2,Tx_Data32 ; OFF -> ON
bset 2,Auto_Mode
bset 2,Cool_Mode
bset 2,Humd_Mode
bset 2,Wind_Mode
bset 2,Heat_Mode
bset TX_READY,Tx_Flag ; Tx ready
bra End_S9
Swing_OFF:
bclr 2,Tx_Data32 ; ON -> OFF
bclr 2,Auto_Mode
bclr 2,Cool_Mode
bclr 2,Humd_Mode
bclr 2,Wind_Mode
bclr 2,Heat_Mode
bset TX_READY,Tx_Flag ; Tx ready
Slip_S9:
End_S9:
jmp Tx_Frame
; ----------------------------------------------------------------------------- *
; Update Data32 to Difference Modes (Auto mode check can be remove)
; ----------------------------------------------------------------------------- *
Data32_To_Modes:
lda Tx_Data10
and #%01110000
cmp #%00000000 ; Check Auto mode?
beq D32_2_Auto
cmp #%00010000 ; Check Cool mode?
beq D32_2_Cool
cmp #%00100000 ; Check Humd mode?
beq D32_2_Humd
cmp #%00110000 ; Check Wind mode?
beq D32_2_Wind
mov Tx_Data32,Heat_Mode ; It is Heat mode
rts
D32_2_Auto:
mov Tx_Data32,Auto_Mode
rts
D32_2_Cool:
mov Tx_Data32,Cool_Mode
rts
D32_2_Humd:
mov Tx_Data32,Humd_Mode
rts
D32_2_Wind:
mov Tx_Data32,Wind_Mode
rts
; ----------------------------------------------------------------------------- *
; Frame Tx (need to check Tx_Ready flag)
;
; <Need to fine turn the timming of bit transmission>!!!!!!
; ----------------------------------------------------------------------------- *
Tx_Frame:
; --------------------------------------------------------- *
Tx_Header: ; Header Code Tx
HEADER_OFF:
mov #31, MTIMMOD ; OF period = 128*31=4mS
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
wait
; ----------------------------------------------------------------------------- *
; Tx Data from 2.0 - 9.3
; ----------------------------------------------------------------------------- *
lda Tx_Data10
; ----------------------------- *
lda Tx_Data32
; ----------------------------- *
lda Tx_Data54
; ----------------------------- *
lda Tx_CtmCode
ldx #$08 ; [1us]
Tx_Loop_76:
lsra ; Right shift LSB to Carry flag [0.5us]
blo Data_N_76 ; [1.5us] jump if C=1
bsr Data_0 ; Send Data 0 [2us] if C=0
bra Tx_N_76_Next
Data_N_76:
bsr Data_1 ; Send Data 1 [2us] if C=1
Tx_N_76_Next:
dbnzx Tx_Loop_76 ; Transmit again if X>0 [2us]
; ----------------------------- *
Tx_Stop: ; Stop bit Tx
; --------------------------------------------------------- *
Key_Released:
jsr Delay_1mS
brset KEY, PTAD, Key_Released
; --------------------------------------------------------- *
; ----------------------------------------------------------------------------- *
; Tx Data "0" OR Data "1"
; ----------------------------------------------------------------------------- *
Data_0: ; 630us carrier + 560us No carrier
; Here Bus =2MHz, Timer clock = bus/64 = 32us, Instruction Cycle = 0.5us
; 26us 8us(ON)+14us(OFF) carrier freq.
Data0_OFF:
mov #16, MTIMMOD ; OF period = 32*16=500us
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
wait
rts ; [4us]
; ----------------------------------------------------------------------------- *
Data_1: ; 630us carrier + 1660us No carrier
; Here Bus =2MHz, Timer clock = bus/64 = 32us, Instruction Cycle = 0.5us
; 26us 8us(ON)+14us(OFF) carrier freq.
mov #16, MTIMMOD ; OF period = 32*16=500us
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
Data1_ON:
bset IR,PTAD ; IR ON [5]
bset IR,PTAD ; IR ON [5]
bset IR,PTAD ; IR ON [5]
nop ; [1]
; 16*.5 = 8us
bclr IR,PTAD ; IR OFF [5]
bclr IR,PTAD ; IR OFF [5]
bclr IR,PTAD ; IR OFF [5]
bclr IR,PTAD ; IR OFF [5]
bclr IR,PTAD ; IR OFF [5]
bclr IR,PTAD ; IR OFF [5]
nop ; [1]
brclr MTIMSC_TOF, MTIMSC, Data1_ON ;[5]
; 36*.5 = 18us
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC ; mask interrupt and clear flag
Data1_OFF:
mov #47, MTIMMOD ; OF period = 32*47=1664us
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC ; Reset and Start Timer
wait
rts ; [4us]
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Reset Vector
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
org $3ffc
Security:
dc.b $FF
jmp main
DRM081
Rev. 0, 6/2006