;**********************************************************************
;Use the serial port debugging wizard or the hyperterminal on the PC, set the baud rate to 9600, 8 data bits,
;1 stop bit, no parity bit.
;When burning, pay attention to the oscillation mode XT, and WDT should 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;
;************************
CB LOC K 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 ; protect the scene
SWAPF STATUS,W
CLRF STATUS
MOVWF STATUS_TEMP
MOVFW FSR
MOVWF FSR_TEMP
;------------------------
CHKRXINT
BANKSEL PIR1
BTFSS PIR1,RCIF ; Check if it is an interrupt request issued by USART
GOTO CHKTXINT
;----------------------------
_RDRXFIFO
BTFSC RCSTA,FERR ;Frame format error flag
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 ;Overspeed error flag
GOTO ENDOFINT
;------------------------
_OERR_PRO
BCF RCSTA,CREN ;0=Disable continuous receiving function
BSF RCSTA,CREN ;1 = Enable continuous receiving function
GOTO ENDOFINT
;------------------------
_FERR_PRO
MOVF RCREG,W
GOTO ENDOFINT
;********* ***************************
;Send program
CHKTXINT
BSF STATUS, RP0 ;Set file register body 1
BTFSS PIE1, TXIE ;Send interrupt flag Enable bit
GOTO ENDOFINT
BCF STATUS, RP0 ; Restore to file register 0
BTFSS PIR1, TXIF ; Transmit interrupt flag bit
GOTO ENDOFINT
; ---------------------- -
MOVLW TXBUFF ; Send temporary register = 20H
MOVWF FSR
MOVF TXPTR,W
ADDWF FSR,F
MOVF INDF,W
MOVWF TXREG
INCF TXPTR,F
DECFSZ TXCOUNT,F ;Number of data bits to be sent
GOTO ENDOFINT
;----------------------
BSF STATUS,RP0
BCF PIE1,TXIE ;Send interrupt bit disable
BCF STATUS, RP0
;--------------------------
ENDOFINT ;Restore the scene
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 ;Set file register bank 1
MOVLW B'00100100' ;Enable USART transmission, set baud rate generator to high speed mode
MOVWF TXSTA
MOVLW .25 ;Load baud rate generator to 9600
MOVWF SPBRG
CLRF PIE1
BSF PIE1,RCIE ;Open USART receive interrupt
CLRF STATUS ;Restore to file register bank 0
CLRF TXCOUNT
CLRF GETPTR
CLRF PUTPTR
MOVLW B'10010000' ; Enable USART continuous reception and enable USART port
MOVWF RCSTA
CLRF I NTC ON
BSF INTCON,PEIE ; Enable peripheral interrupt enable bit
BSF INTCON,GIE ; Enable global interrupt enable bit
; **************************************
LOOP
CALL CHECK_DATA
GOTO LOOP
; **************************************
CHECK_DATA
CLRF STATUS
MOVF TXCOUNT,W
SKPZ ;BTFSS STATUS,Z
RETURN
;--------------------------------
MOVF GETPTR,W
XORWF PUTPTR,W
SKPNZ ;BTFSC STATUS,Z
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 '-'
; MOVWF TXBUFF+1
; MOVLW 'P'
; MOVWF TXBUFF+2 ; MOVLW
'I'
; ' V' ; MOVWF TXBUFF+6 ; MOVLW 'R' ; MOVWF TXBUFF +7 ;--------------------------------- MOVLW 0X0D ; Enter key MOVWF TXBUFF+1 MOVLW 0X0A ; Line feed key MOVWF TXBUFF+2 ;----------------------------- MOVLW .3 MOVWF TXCOUNT CLRF TXPTR ; Clear 0 BSF STATUS, RP0 BSF PIE1, TXIE BCF STATUS, RP0 RETURN ;--------------------------- END
Previous article:Ethernet-RS-232 Protocol Converter Based on PIC18F66J60
Next article:PIC16F72 Timer C Program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- [NXP Rapid IoT Review] + First Rapid IOT Studio Project
- At 10 am today, Datang NXP will broadcast a live broadcast of [New energy lithium battery management solution with impedance detection function]
- Can anyone help me figure out what chip model this is?
- 【DJI】Automotive Software Engineer Position
- Xianji HPM6750 Review & DIY——RCSN
- How to use freertos to forward the received message content
- 【Beetle ESP32-C3】8. OLED clock and weather assistant (Arduino)
- R7F0C003/004 series, using IAR development environment, are there any tutorials?
- PWM wave problem
- Typical uses of voltage followers