1. PIC1 microcontroller programming (sending part)
LIST P=16F877
#INCLUDE P16F876.INC
CBLOCK 0X24; Reserve three bytes for display
COUNT; used as a counter or register
ENDC
ORG 0X0000 ; program reset entry
NOP
START GOTO MAIN
ORG 0X20
MAIN MOVLW 0X30; The following will initialize the RAM content
MOVWF FSR; Start from unit 30H
MOVLW 0X30 ; assign value 30H to unit 30H
MOVWF COUNT
INTRAM MOVF COUNT, 0; assign 30H to 7FH to unit 30H to 7FH
MOVWF INDF
INCF COUNT, 1
INCF FSR, 1
BTFSS COUNT, 7
GOTO INTRAM
BSF STATUS, RP0; Initialize the SCI component
MOVLW 0X19; Set the transmission baud rate to about 9600 bps
MOVWF SPBRG
MOVLW 0X04; Select asynchronous high-speed mode to transmit 8-bit data
MOVWF TXSTA
BCF STATUS, RP0
MOVLW 0X80; Enable synchronous serial port to work
MOVWF RCSTA
BSF STATUS, RP0
BSF T RISC , 7; Set RC6 and RC7 to input mode and disconnect the external circuit
BSF TRISC, 6
BCF STATUS, RP0
MOVLW 0X30; 30H is sent as a synchronization character
MOVWF FSR
MOVF INDF,0
MOVWF TXREG; write the data to be sent into the transmit buffer TXREG
BSF STATUS, RP0
BSF TXSTA, TXEN; Send permission
BCF STATUS, RP0
BSF RCSTA, CREN; receive data enable
LOOPTX BTFSS PIR1, RCIF ; Wait for the response byte from PIC2
GOTO LOOPTX
MOVF RCREG, 0; read response byte, clear RCIF
LOOPTX1 BTFSS PIR1, TXIF; send next byte
GOTO LOOPTX1
INCF FSR
MOVF INDF,0
MOVWF TXREG
BTFSS FSR, 7; Have the contents of the 30H~7FH units been sent?
GOTO LOOPTX ; No, continue to send the next byte
BSF STATUS, RP0; if yes, stop sending
BCF TXSTA, TXEN
BCF STATUS, RP0; Data transmission completed
CALLLED; call the display subroutine to display the sent data
END; program ends
2. PIC2 microcontroller programming (receiving part)
LIST P=16F876
#INCLUDE P16F876.INC
CBLOCK 0X24
COUNT
ENDC
ORG 0X0000
NOP
START GOTO MAIN
MAIN BSF STATUS, RP0; Initialization procedure is the same as the sending subroutine
MOVLW 0X19; baud rate setting is the same as PIC1
MOVWF SPBRG
MOVLW 0X04 ; asynchronous high-speed transmission
MOVWF TXSTA
BCF STATUS, RP0
MOVLW 0X80; serial port operation enable
MOVWF RCSTA
BSF STATUS, RP0
BSF TRISC, 7; isolated from external circuits
BSF TRISC, 6
BCF STATUS, RP0
MOVLW 0X30; store the sent data starting from unit 30H
MOVWF FSR
BSF RCSTA, CREN; receive enable
BSF STATUS, RP0
BSF TXSTA, TXEN; Send permission
BCF STATUS, RP0
WAIT BTFSS PIR1, RCIF; Waiting to receive data
GOTO WAIT
MOVF RCREG, 0; read data
MOVWF INDF ;Store the received response byte into the RAM of PIC2
INCF FSR
MOVWF TXREG ; send response byte
LOOPTX BTFSS PIR1, TXIF; Wait for writing to complete
GOTO LOOPTX
BTFSS FSR, 7; Are all data received?
GOTO WAIT1; No, continue to receive other data
BCF RCSTA, RCEN; After receiving, turn off the receiving and sending data enable
BSF STATUS, RP0
BCF PIE1, TXEN
BCF STATUS, RP0
CALL LED; call the display subroutine to display the received data
END; program ends
Previous article:PIC microcontroller common instructions introduction and instruction function classification table
Next article:You should know these advantages of PIC microcontrollers
- 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
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Can you help me transfer the Ambarella A2S HD camera PCB + schematic diagram to PDF?
- RP2040 microcontroller chip goes on sale for $1
- I will force myself to occupy a post position. Tomorrow I will share my experience of learning how to control WS812 16*16 dot matrix transformation with ESP32
- In-depth analysis of T-BOX system solution: wireless connection unit
- Prize survey: ST MEMS Sensor Forum User Survey, Participate and Get Surprises
- Design of Adaptive PID Controller Based on FPGA
- What is Alibaba PC Safe Service?
- NB-IoT Standard Evolution R13-R14
- Announcement of postponement of the award for the Pingtouge RVB2601 open source application creative collection activity
- Q&A on Connectivity with Qorvo: Addressing Thermal Challenges at the Wi-Fi Front End