Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC code for RX and TX

Status
Not open for further replies.

Cheetos

Member level 3
Joined
May 26, 2011
Messages
57
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,700
hello, i am new in using the USART library of PIC16F877A. i would just like to know if my PIC will be able to receive a data with this code. my all of pins in PORTB will turn on once i received a data. I have set i as the variable i needed. i need i be equal to 1 so that PORTB will turn on. if not equal to 1 then PORTB will turn off


void main(){
float i;
PORTB=0x00;
TRISB=0x00;
PORTC=0;
TRISC=0x03;


while(1){
Usart_Init(9600);

if(Usart_Data_Ready()){
i=Usart_Read();

if(i==1){
PORTB=0xFF;
}
if(i==0){
PORTB=0x00;
}
}

}

}
 

i will give you a much easier code.

---------- Post added at 13:59 ---------- Previous post was at 13:39 ----------

void main(){
char i; // usart data are char, not float
PORTB = 0x00;
TRISB = 0x00;
TRISC = 0xBF // only TX pin is made output on port C


while(1){
Usart_Init(9600);

if(Usart_Data_Ready()){
i=Usart_Read();

if(i==1) // PortB only comes up if the data received is 1 you can use the last code to check if any data is received
{
PORTB=0xFF;
}
if(i==0){
PORTB=0x00;
}
}

if (Usart_Data_Ready())
{
PORTB = 0xFF;
}

}

}
 
oh i see, many thanks to you sir! :grin:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top