;Use the serial port debugging wizard or the PC terminal's hyperterminal, set the baud rate to 9600, 8 data bits,
1 stop bit, no parity bit.
;First, send a character such as "2" from the PC to the serial port. After receiving it, the microcontroller returns the received number such as "2-PIC16" to the computer.
;Note the settings of the experimental board: S4, S5, S1 must all be OFF, and S13 pins 6 and 7 must be ON.
;When burning, pay attention to the oscillation mode XT, and WDT must be disabled.
LIST P=16F877
INCLUDE "P16F877.INC"
;***************************************
__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_
ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC;
;************************
CBLOCK 0x20
TXBUFF :9
TXPTR
TXCOUNT
RXBUFF :9
PUTPTR
GETPTR
STATUS_TEMP
FSR_TEMP
ENDC
W_TEMP EQU 7FH
;-------------------------
ORG 0X000
GOTO MAIN
;---------------- ---------
ORG 0X004
GOTO INT
ORG 0X008
INT
MOVWF W_TEMP
SWAPF STATUS,W
CLRF STATUS
MOVWF STATUS_TEMP
MOVFW FSR
MOVWF FSR_TEMP
CHKRXINT
BANKSEL PIR1
BTFSS PIR1,RCIF
GOTO CHKTXINT
_RDRXFIFO
BTFSC RCSTA,FERR
GOTO _FERR_PRO
MOVLW RXBUFF
MOVWF FSR
MOVF PUTPTR,W
ADDWF FSR,F
MOVF RCREG,W
MOVWF INDF
INCF PUTPTR,F
MOVLW .7
ANDWF PUTPTR,F
BTFSC PIR1,RCIF
GOTO _RDRXFIFO
BTFSS RCSTA,OERR
GOTO ENDOFINT
_OERR_PRO
BCF RCSTA,CREN
BSF RCSTA,CREN
GOTO ENDOFINT
_FERR_PRO
MOVF RCREG,W
GOTO ENDOFINT
;---------------------
CHKTXINT
BSF STATUS,RP0
BTFSS PIE1,TXIE
GOTO ENDOFINT
BCF STATUS,RP0
BTFSS PIR1,TXIF
GOTO ENDOFINT
MOVLW TXBUFF
MOVWF FSR
MOVF TXPTR,W
ADDWF FSR,F
MOVF INDF,W
MOVWF TXREG
INCF TXPTR,F
DECFSZ TXCOUNT,F
GOTO ENDOFINT
BSF STATUS ,RP0
BCF PIE1,TXIE
BCF STATUS,RP0
ENDOFINT
CLRF STATUS
MOVFW FSR_TEMP
MOVWF FSR
SWAPF STATUS_TEMP,W
MOVWF STATUS
SWAPF W_TEMP,F
SWAPF W_TEMP,W
RETFIE
;-------------------
MAIN
BANKSEL TXSTA
MOVLW B'00100100'
MOVWF TXSTA
MOVLW .25
MOVWF SPBRG
CLRF PIE1
BSF PIE1,RCIE
CLRF STATUS
CLRF TXCOUNT
CLRF GETPTR
CLRF PUTPTR
MOVLW B'10010000'
MOVWF RCSTA
CLRF INTCON
BSF INTCON,PEIE
BSF INTCON,GIE
LOOP
CALL CHECK_DATA
GOTO LOOP
;----------------------
CHECK_DATA
CLRF STATUS
MOVF TXCOUNT,W
SKPZ
RETURN
MOVF GETPTR,W
XORWF PUTPTR,W
SKPNZ
RETURN
MOVLW RXBUFF
MOVWF FSR
MOVF GETPTR,W
ADDWF FSR,F
INCF GETPTR,F
MOVLW .7
ANDWF GETPTR,F
MOVF INDF,W
MOVWF TXBUFF+0
MOVLW 'P'
MOVWF TXBUFF+1
MOVLW 'I'
MOVWF TXBUFF+2
MOVLW 'C'
MOVWF TXBUFF+3
MOVLW 'A'
MOVWF TXBUFF+4
MOVLW 'V'
MOVWF TXBUFF+5
MOVLW 'R'
MOVWF TXBUFF+6
MOVLW 0X0D
MOVWF TXBUFF+7
MOVLW 0X0A
MOVWF TXBUFF+8
MOVLW .9
MOVWF TXCOUNT
CLRF TXPTR
BSF STATUS,RP0
BSF PIE1,TXIE
BCF STATUS,RP0
RETURN
;- --------------------
END
Previous article:Design of Laser Password Controller Based on AT89C51
Next article:Software UART Design Based on the Universal Pins of Single-Chip Microcomputer
Recommended ReadingLatest update time:2024-11-17 00:09
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- 2024 DigiKey Innovation Contest
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- How to check the number of bytes occupied by the written code, memory usage, and stack overflow when using IAR for MSP430
- Are there really industrial products using rtthread on a large scale?
- Tektronix MDO3014 oscilloscope channel fault repair - attached practical solutions for related faults
- Which characters cannot appear in double quotes in C language? Can anyone tell me?
- The control board mPython 0.3.6 was released yesterday
- Please help me look at the relationship between IL and Vo of this current detection circuit. I have been looking at it for a long time but still can't understand the relationship.
- [MCU] W806 Lianshengde 9.9 yuan development board experience 2 --- littlevgl8.0 transplantation
- XuetangX Hardware Blazar a-Board Open Source Hardware Board Review
- AUTOSAR software development learning complete set of materials
- Murata Tmall flagship store officially opened: 20% off on all items in the first month of opening!