Pic Serial Communication Assembly Code
---> ServiceClient failure for DeepLeo[/ERROR]
Pic Serial Communication Assembly Code
__config _XT_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _BODEN_OFF
TMP_RX EQU 0x20 ; VALUE TO HOLD RECEIVED VALUE
COL_CNT EQU 0x21
LINE_CNT EQU 0x22
ORG 0x000
GOTO MAIN
ORG 0x004 ; INTERRUPT VECTOR
GOTO INTERRUPT
INCLUDE
MAIN:
CALL LCD_INIT ; FIRST OF ALL WE HAVE TO INITIALIZE LCD
CLRF LINE_CNT
MOVLW 0xFF
MOVWF COL_CNT
;---USE PORTA AS I/O
CLRF PORTA
MOVLW D'7' ; USE PORTA AS I/O
MOVWF CMCON ;
BSF STATUS,RP0 ; SWITCH TO BANK1
CLRF TRISA ; SET ALL PINS OF PORTA AS OUTPUT
BCF OPTION_REG,7
;---CONFIGURE PERIPHERAL INTERRUPTS
MOVLW B'00100000' ; DISABLE ALL PERIPHERAL INTERRUPTS EXCEPT RECEIVER
MOVWF PIE1 ; PERIPHERAL INTERRUPT ENABLE/DISABLE
;---CONFIGURE GENERAL INTERRUPTS
MOVLW B'01000000' ; DISABLE ALL INTERRUPTS EXCEPT PERIPHERAL
MOVWF INTCON ; INTERRUPT CONTROL REGISTER
;---CONFIGURE SPBRG FOR DESIRED BAUD RATE
MOVLW D'51' ; WE WILL USE 4800bps
MOVWF SPBRG ; BAUD AT 4MHZ
;---CONFIGURE TXSTA
MOVLW B'00100100' ; CONFIGURE TXSTA AS :
MOVWF TXSTA ;
;8 BIT TRANSMISSION - 6.BIT
;TRANSMIT ENABLED - 5.BIT
;ASYNCHRONOUS MODE - 4.BIT
;ENABLE HIGH SPEED BAUD RATE - 2.BIT
BCF STATUS,RP0 ; SWITCH TO BANK0
MOVLW B'10000000' ; ENABLE SERIAL PORT
MOVWF RCSTA ; RECEIVE STATUS REG
CLRF TMP_RX
BSF INTCON,7 ; ENABLE ALL UNMASKED INTERRUPTS
BSF RCSTA,4 ; ENABLE USART RECEIVE
MAIN_LOOP: ; CONTINOUS LOOP
GOTO MAIN_LOOP
INTERRUPT:
BCF INTCON,7 ; DISABLE ALL INTERRUPTS
BTFSS PIR1,5 ; CHECK IF THE RCIF FLAG IS SET
GOTO QUIT_INT ; IF NOT RETURN BACK TO THE MAIN LOOP
MOVF RCREG,W ; MOVE THE RECEIVED BYTE TO W
MOVWF PORTA ; MOVE W TO PORTA
MOVWF TMP_RX
BCF PIR1,5
INCF COL_CNT
MOVF COL_CNT, W
XORLW 0x10 ; CHECK IF WE REACHED THE END OF THE LINE
BTFSS STATUS, Z
GOTO QUIT_INT ; IF NOT
;ELSE, CHECK IF WE REACHED THE END OF THE COLUMN
CLRF COL_CNT
CALL LCD_L2
INCF LINE_CNT
MOVF LINE_CNT, W
XORLW 0x02
BTFSS STATUS, Z
GOTO QUIT_INT ; IF NOT
;ELSE
CLRF LINE_CNT
CALL LCD_CLR
CALL LCD_L1
QUIT_INT:
MOVF TMP_RX, W
CALL LCD_CHAR ; LCD_CHAR WRITES AN ASCII CODE CHAR TO THE LCD, THE LCD uC WILL THEN AUTOINCREMENT THE CURSOR
RETFIE
END
How to Test the Program?
To test the program, you need to do the following steps:
Connect the two PIC microcontrollers according to the circuit diagram. Make sure that the TX pin of the transmitter is connected to the RX pin of the receiver and vice versa.
Connect an LCD screen to the receiver according to the LCD driver code. Make sure that the LCD pins are connected to PORTD and PORTE of the receiver.
Connect a USB-TTL converter or an FTDI chip to the transmitter according to the circuit diagram. Make sure that the TX pin of the converter is connected to the RX pin of the transmitter and vice versa.
Connect a 9V battery or a DC power supply to each microcontroller according to the circuit diagram. Make sure that the positive terminal is connected to VDD and the negative terminal is connected to VSS.
Program each microcontroller with its corresponding assembly code using a PICkit2 or 3 programmer.
Open a serial terminal program on your computer, such as PuTTY or Tera Term. Set the baud rate to 4800 bps, data bits to 8, parity to none, stop bits to 1, and flow control to none.
Turn on the power supply and observe the LCD screen and the serial terminal. You should see the message "Hello World!" displayed on both devices.
Congratulations! You have successfully used PIC serial communication assembly code to communicate between two PIC microcontrollers.
Conclusion
In this article, you have learned the basics of PIC serial communication assembly code, such as what is UART, how to configure it, how to send and receive data, and how to handle interrupts. You have also learned how to write a simple program that uses PIC serial communication assembly code to transmit and receive data between two PIC microcontrollers. You have also learned how to test the program using an LCD screen and a serial terminal.
PIC serial communication assembly code is a useful skill that can help you communicate with other devices, such as a computer, a microcontroller, or a sensor. You can use it for various applications, such as data logging, remote control, wireless communication, etc. You can also use it to learn more advanced serial communication protocols, such as SPI and I2C.
We hope that this article has been helpful and informative for you. If you have any questions or comments, please feel free to leave them below. Thank you for reading! d282676c82
https://www.olsh-hilltown.com/group/working-mothers/discussion/bd6892fb-c893-421e-9074-d604e7cd6e15
https://www.agilityarc.com/group/mysite-231-group/discussion/c2982971-a684-40c2-a382-79e05b6b4d23
https://www.duranbeauty.com/group/grupo-duran-beauty/discussion/1151ca68-c88f-4518-891c-ee133e5f2f84