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
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What are the main parameters for selecting magnetic beads?
- Learn embedded development from engineers——Based on STM32 and μC/OS-III
- What is the output/input impedance value of CC2xxx?
- [TI recommended course] #[High Precision Lab] Operational Amplifier: 16 Fully Differential Amplifier#
- EEWORLD University Hall----Live Replay: Infineon & Intron Explanation- How to Choose a Suitable Automotive MOSFET
- Amway uses LT768 to realize TFT industrial serial port screen solution
- What are the methods of wireless bridge relay transmission?
- Diode selection
- The computer will automatically restart when the LabVIEW program is running
- Master these techniques to easily operate DC-DC circuits!