hi every body
these days iam learning interfacing PIC using it's USART module with another PIC or either with PC but 1st i do search and find that it is commonly used in Asynchronous Mode and that was discussed in details in Microchip DeviceDoc on
ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf
which discusses using the USART module in microchip PICs in Asynchronous Mode so after reading i thought 8 bit mode will be a good start so i wrote a program for 2 pic16f876a 1st for a transmitter and the other for a receiver
the transmitter will test the statue of switches on PORTB and every switch press will send a different value but as a start the code will test RP0 only and send 0XFF in case of it was High and the receiver will get that value and mov it on PORTB and blink the LEDs
the code uses the same baud rate discussed in the DeviceDoc and i ensured that i did like the PDF and datasheet said specially the datasheet in page 109 the paragraph named
"ADDRESSABLE UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)"
it said that
"Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter."
and that what i did already in the code but unfortunately the circuit doesn't work when simulate it in Proteus 7 Professional
here is the code for the transmitter
and here ther code for the receiver
and that is the circuit i build on Proteus
and at the end the project files
http://www.4shared.com/file/165679401/3eb67abe/USART_RS232.html
thnx 4 ur time
these days iam learning interfacing PIC using it's USART module with another PIC or either with PC but 1st i do search and find that it is commonly used in Asynchronous Mode and that was discussed in details in Microchip DeviceDoc on
ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf
which discusses using the USART module in microchip PICs in Asynchronous Mode so after reading i thought 8 bit mode will be a good start so i wrote a program for 2 pic16f876a 1st for a transmitter and the other for a receiver
the transmitter will test the statue of switches on PORTB and every switch press will send a different value but as a start the code will test RP0 only and send 0XFF in case of it was High and the receiver will get that value and mov it on PORTB and blink the LEDs
the code uses the same baud rate discussed in the DeviceDoc and i ensured that i did like the PDF and datasheet said specially the datasheet in page 109 the paragraph named
"ADDRESSABLE UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)"
it said that
"Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous Receiver Transmitter."
and that what i did already in the code but unfortunately the circuit doesn't work when simulate it in Proteus 7 Professional
here is the code for the transmitter
Rich (BB code):
LIST P=16F876A
#INCLUDE<P16F876A.INC>
__CONFIG _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
TXDataByte EQU 0X20
RXDataByte EQU 0X21
ORG 0X00
INITIATE
BSF STATUS,RP0;-------I'm in Bank(1)
MOVLW 0XFF;-----------Initiate Ports
MOVWF TRISB
MOVLW B'11000000'
MOVWF TRISC
MOVLW D'25';----------Initiate Baude Rate Register Generator
MOVWF SPBRG
BSF TXSTA,2;-------High Baud Rate
MOVLW B'00100100';----Initiate TXSTA Register
MOVWF TXSTA
BCF STATUS,RP0;-------I'm in Bank(0)
BSF RCSTA,7
MOVLW B'10010000';----Initiate RCSTA Register
MOVWF RCSTA
MOVLW 0XFF
MOVWF TXDataByte
MAIN
BTFSS PORTB,0
GOTO MAIN;NO
;WAIT_RELESE;YES
;BTFSC PORTB,0
;GOTO WAIT_RELESE;NO
WaitTX;YES
BTFSS PIR1,TXIF
GOTO WaitTX;NO
MOVF TXDataByte;YES
MOVWF TXREG
BCF PIR1,TXIF
GOTO MAIN
END
Rich (BB code):
LIST P=16F876A
#INCLUDE<P16F876A.INC>
__CONFIG _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
TXDataByte EQU 0X20
RXDataByte EQU 0X21
ORG 0X00
INITIATE
BSF STATUS,RP0;-------I'm in Bank(1)
MOVLW 0X00;-----------Initiate Ports
MOVWF TRISB
MOVLW B'11000000'
MOVWF TRISC
MOVLW D'25';----------Initiate Baude Rate Register Generator
MOVWF SPBRG
BSF TXSTA,2;-------High Baud Rate
MOVLW B'00100100';----Initiate TXSTA Register
MOVWF TXSTA
BCF STATUS,RP0;-------I'm in Bank(0)
BSF RCSTA,7
MOVLW B'10010000';----Initiate RCSTA Register
MOVWF RCSTA
MOVLW 0X00
MOVWF PORTB
MAIN
WaitRX
BTFSS PIR1,RCIF
GOTO WaitRX;NO
MOVF RCREG;YES
MOVWF PORTB
BCF PIR1,RCIF
GOTO MAIN
END
and at the end the project files
http://www.4shared.com/file/165679401/3eb67abe/USART_RS232.html
thnx 4 ur time