⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asm.s43

📁 该程序是基于iar平台用msp430f123设计的红外线接受(RC,40khz),同时带有按键和指示灯。
💻 S43
📖 第 1 页 / 共 2 页
字号:
#include  "msp430x12x.h"
;*****************************************************************************
;   Decode RC5 IR Remote Control / TX to PC @ 2400
;
;   Description: Decode 12-bit bi-phase RC5 format IR packet using Timer_A. 
;   Timer_A CCR1 is used to decode IR packet, capture mode to detect mid-bit
;   edge and compare mode to latch data bit. CCR2 is used for decoder 
;   over-run detection. 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 MSB first. 2 Start, C and 11-bits of data.
;   S1-S2-C-A4-A3-A2-A1-A0-C5-C4-C3-C2-C1-C0
;
;   Demonstrate with IR monitor - TX IRData as CR, LF, 4 ASCII Bytes
;
;                   MSP430F1123
;               -----------------
;           /|\|              XIN|-  
;            | |                 | 32kHz
;            --|RST          XOUT|-
;              |                 |
;              |             P1.3|-- ESCAPE
;              |             P1.2|--RETURN
;              |             P1.1|--RIGHT
;              |             P1.0|--LEFT
;              |             P2.4|--DOWN
;              |             P2.3|--UP
; IR Receiver->|P2.2/TA0     P3.7|--> LED
;              |             P3.6|--> INT
;              |        P3.5/URXD|--  RXD
;              |        P3.4/UTXD|--> TXD

;   Bit pattern as seen at MSP430
;
;    1.78ms
;    +---  +---  +---     ----  ---+     +---
;       |  |  |  |  |     |  |  |  |     |  |
;       ---+  ---+  +--+---  +--+  +-----+  +--
;    ^Start^Start^  1  ^ 0   ^  0  ^
;
;   CPU registers used
#define     RXTXData  R4                    
#define     BitCnt    R5
#define     IRData    R6
#define     IRBit     R7
;
;   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

Esc         equ     008h
Return         equ     004h
Right         equ     002h
Left         equ     001h
Down         equ     010h
Up          equ     008h

LED         equ     080h                    ; LED on P3.7
RXD         equ     020h                    ; RXD on P3.5
TXD         equ     010h                    ; TXD on P3.4
IRIN        equ     004h                    ; IR input on P2.2

Bit_50      equ     29                      ; 890 us @ 32768 ACLK
Bit_75      equ     44                      ; 1348 us @ 32768 ACLK

Ch_up       equ     32                      ;
Ch_dwn      equ     33                      ;
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   #LPM3,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	        bic.b    #00Fh,&P1SEL
                bic.b    #00Fh,&P1DIR      
                bis.b    #00Fh,&P1IE       ;开中断
                bis.b    #00Fh,&P1IES
                bic.b    #00Fh,&P1IFG      ;清中断标志位
;----------------------------------------------------------     
SetupP2         bis.b    #004h,&P2SEL
                bic.b    #0FFh,&P2DIR                     
                bis.b    #018h,&P2IE       ;
                bis.b    #018h,&P2IES
                bic.b    #018h,&P2IFG      ;清中断标志位
;----------------------------------------------------------     
SetupP3	        bis.b	 #030h , &P3SEL	    
                bic.b	 #0ffh , &P3DIR	    ;
                bis.b    #0D0h , &P3DIR     ;        
                bic.b    #LED,&P3OUT             ; P3.7, low, LED off 
                eint                           
                ret                           
;----------------------------------------------------------------------------- 
IR_Ready;   Subroutine to prepare to receive 12-bit RC5 into IRData
;----------------------------------------------------------------------------- 
             clr.w   IRData                  ;
            mov.w   #014,IRBit              ; 12 data + 1 start + completion 
SetupC1     mov.w   #CM1+SCS+CAP+CCIE,&CCTL1    ; CAP CCI1A, falling edge, int
            bis.b        #00fh,&P1IE
            bis.b        #018h,&P2IE
            ret                             ;
/* 
;----------------------------------------------------------------------------- 
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 as 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                             ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -