LPC900 series MCU UART and CCU module to realize infrared communication program

Publisher:书卷气息Latest update time:2018-01-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LPC900 series MCU UART and CCU module to realize infrared communication program

$INCLUDE (REG932.INC) 

; variable definition 
BEEP BIT P2.7 
KEY1 BIT P0.1

FE BIT SCON.7 
PLEEN BIT TCR20.7 
RCV_BUF DATA 30H ;Receive buffer first address (30H~3FH) 
BRGR1_DATA DATA 09H ;Baud rate is set to 2400bit/s 
BRGR0_DATA DATA 0B4H 

    ORG 0000H 
    AJMP MAIN 
         
;Main program starts 
    ORG 0100H 
MAIN: 
    MOV SP,#60H 
    MOV P0M1,#00H ;P0,P1 ports are set to quasi-bidirectional 
    MOV P0M2,#00H  MOV
    P1M1,#00H 
    MOV P1M2,#00H 
    MOV P2M1,#0C0H ;P2.6,P2.7 are set to open drain 
    MOV P2M2,#0C0H 
    ACALL CCU_INIT ;CCU module is initialized to generate 38K Hz modulation signal 
    ACALL UART_INIT 
MAIN_L1: 
    JB KEY1,$ 
    ACALL SEND_DATA ;Send 16-byte data 
    MOV R7,#01H 
    ACALL DELAY 
    ACALL RCV_DATA ;Receive 16-byte data 
    ACALL COMPARE ;Compare the received data with the sent data 
    JZ MAIN_L2 
    CLR BEEP ;If correct, the buzzer will sound a short time 
    MOV R7,#01H 
    ACALL DELAY 
    SETB BEEP 
    AJMP MAIN_L1 
MAIN_L2: 
    CLR BEEP ;If wrong, the buzzer will sound a long time 
    MOV R7,#05H 
    ACALL DELAY 
    SETB BEEP 
    AJMP MAIN_L1 

;************************************************ 
; Name: SEND_DATA 
; Function: Send 16 bytes of data (0~15) continuously through UART 
; Input parameter: None 
; Output parameter: None 
; Note: This program uses query mode to send. 
;******************************************** 
SEND_DATA: 
    MOV R7,#10H 
    CLR TI 
    CLR A 
SEND_DL1: 
    MOV SBUF,A 
    JNB TI,$ ;Wait for one byte to be sent 
    CLR TI 
    INC A 
    DJNZ R7,SEND_DL1 
    RET 

;************************************************************************ 
; Name: RCV_DATA 
; Function: Receive 16 bytes of data continuously through UART 
; Input parameter: RCV_BUF--the first address of the buffer used to receive data 
; Output parameter: The received 16 bytes of data are located in the receiving buffer 
; Note: This program uses the query method for receiving. Because half-duplex communication is adopted, the 
receiving permission must be turned on before receiving data, and the receiving permission must be turned off after receiving. 
;******************************************************************** 
RCV_DATA: 
    MOV R7,#10H 
    MOV R0,#RCV_BUF 
    SETB REN ;Serial reception is enabled 
    CLR FE 
    CLR RI 
RCV_DL1: 
    JNB RI,$ ; Wait for receiving one byte 
    CLR RI 
    MOV A,SBUF 
    MOV @R0,A 
    INC R0 
    DJNZ R7,RCV_DL1 
    CLR REN ;Serial reception disable 
    RET 

;************************************************* 
; Name: COMPARE 
; Function: Compare whether the content in the buffer is 0~15 
; Input parameter: RCV_BUF--the first address of the buffer to be compared 
; Output parameter: ACC--returns 1 if the comparison is correct, otherwise returns 0. 
;************************************************ 
COMPARE: 
    MOV R7,#10H 
    MOV R0,#RCV_BUF 
    MOV R1,#00H 
    CLR A 
COMP_L1: 
    MOV A,@R0 
    CJNE A,01H,COMP_RTN ;Compare ACC with R1 (01H) 
    INC R0 
    INC R1 
    DJNZ R7,COMP_L1 
    MOV A,#01H ;Comparison result is correct, return 01H 
    RET 
COMP_RTN: 
    CLR A ;Comparison result is wrong, return 00H 
    RET 

;************************************************************************** 
; Name: CCU_INIT 
; Function: Initialize the CCU module, make OCA (P2.7) output 38KHz, 50% duty cycle PWM wave, 
; as the carrier of infrared ray 
; When using 6MHz crystal , CCU frequency = ((6000000/2)/6)*32=16MHz 
; Timer reload value = CCU frequency/infrared carrier frequency = 16000000/38000=421=01A5H 
;******************************************************************* 
CCU_INIT: 
    MOV TOR2H,#01H ; Timer reload value 
    MOV TOR2L,#0A5H 
    MOV OCRAH,#00H ; (OCRAH:OCRAL)=(TOR2H:TOR2L)/2, PWM duty cycle is 50% 
    MOV ​​OCRAL,#0D2H 
    MOV TCR21,#85H ; PLL pre- scaling is 5+1 
    MOV CCCRA,#01H ; Non- inverting PWM 
    MOV TCR20,#00H           
    SETB PLEEN 
    NOP 
    JNB PLEEN,$ ;Wait for the phase-locked loop (PLL) to stabilize 
    ORL TCR20,#03H ;Start the timer, symmetrical PWM mode 
    RET 

;*************************************** 
; Name: UART_INIT 
; Function: UART initialization, baud rate 2400bit/s    
;*************************************** 
UART_INIT: 
    MOV PCON,#00H 
    MOV SSTAT,#00H ;Double buffering disabled, interrupt disabled, use query mode to send and receive 
    MOV SCON,#40H ;Serial port mode 1, reception disabled 
    ORL PCON,#40H ;SMOD0=1, bit 7 of SCON is used as FE 
    MOV BRGCON,#00H 
    MOV BRGR1,#BRGR1_DATA 
    MOV BRGR0,#BRGR0_DATA 
    MOV BRGCON,#03H ;Start the baud rate generator of UART 
    RET 

;******************************************************** 
; Name: DELAY 
; Function: Delay (R7*0.1) seconds ( oscillator is 6MHz) 
; Input parameter: R7--delay time 
; Output parameter: None 
; Note: If the input parameter R7 is equal to 0, there will be no delay and it will return directly. 
;***************************************************** 
DELAY: 
    MOV     A,R7 
    JZ      DELAY_RTN 
DELAY_L1: 
    MOV     R6,#0C8H            ;延时0.1S 
DELAY_L2: 
    MOV     R5,#0FAH 
DELAY_L3: 
    NOP 
    NOP 
    NOP 
    NOP 
    DJNZ    R5,DELAY_L3 
    DJNZ    R6,DELAY_L2 
    DJNZ    R7,DELAY_L1 
DELAY_RTN: 
    RET     
    END 


Reference address:LPC900 series MCU UART and CCU module to realize infrared communication program

Previous article:The relationship between KEIL and standard C and programming methods
Next article:HT46R47 MCU HT6221 remote control receiver program

Recommended ReadingLatest update time:2024-11-16 19:54

C51 MCU writes an external interrupt (entry-level MCU)
Code section void main() { /*---------------EA,IT,EX must write-------------*/ EA=1; // Enable general interrupt IT1=1; //interrupt trigger mode             //=0 is low level trigger, =1 is falling edge trigger   EX1=1; //External interrupt enable bit       while(1) {     led1=0;     } }     void int1
[Microcontroller]
C51 MCU writes an external interrupt (entry-level MCU)
Extended design of 8051 microcontroller DPTR
  The emergence of single-chip microcomputer is a milestone in the history of computer technology development. It enables computers to enter the field of control from massive numerical calculations. Among microcontrollers, the 8051 series is the most classic and is still the most popular and widely used 8-bit MCU arch
[Microcontroller]
Extended design of 8051 microcontroller DPTR
Introduction to the characteristics of AVR microcontroller
RISC (Reduced Instruction Set Computer) is relative to CISC (Complex Instruction Set Computer). RISC does not simply reduce instructions, but improves the computing speed by making the computer structure simpler and more reasonable. RISC gives priority to simple instructions with the highest frequency of use and avoid
[Microcontroller]
Some words for you who are just starting to learn microcontrollers
Learning MCU ---- What should we do? Why do we need to learn microcontrollers? Microcontroller is a common course in electrical engineering majors in colleges and universities. Some schools even list it as an elective course. Among the many courses, it does not show its How important. Why should we study it? There are
[Microcontroller]
Ordinary MCU Teaching——Lecture 14 MCU Instructions (VIII)
Bits and bit operation instructions Through the examples of the running lights above, we have become accustomed to the "bit" that means a light is on or off, but the instructions we have learned are all introduced with "bytes": byte movement, addition, subtraction, logical operations, shifts, etc. Using bytes to hand
[Microcontroller]
Features and advantages of avr microcontroller
AVR microcontroller is an enhanced RISC (Reduced Instruction Set CPU) high-speed 8-bit microcontroller with built-in Flash developed by ATMEL in 1997. AVR microcontrollers can be widely used in various fields such as computer peripherals, industrial real-time control, instrumentation, communication equipment, and h
[Microcontroller]
51 single chip microcomputer example explanation, the button controls the light program
The wiring schematic diagram of the button control light is shown in Figure 11. Press the button on the lower 4 bits of the P1 port of the single-chip computer, and connect the light-emitting diode to the upper 4 bits. When SB1 is pressed (P1.0 port is "0"), LED1 lights up (P1.4 port is "0"). Similarly, if SB2, SB3, a
[Microcontroller]
51 single chip microcomputer example explanation, the button controls the light program
Energy-saving lighting control system based on single chip microcomputer
introduction At present, my country's power industry is developing rapidly, but the situation of insufficient power supply and low power efficiency is still serious and will continue to exist for a considerable period of time in the future. Promoting lighting energy-saving technology and saving electricity is one of
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号