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.

[SOLVED] i don't know how to use receive in USART

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 have a problem with my usart with PIC16f877a. i can transmit a data but i do not know how to receive any, how can i receive data with my USART?
 

PHP:
void usrt_init()
	{
         SYNC=0;
         BRGH=1;
         SPEN=1;
         CREN=1;
         RX9=0;
         SPBRG=10;
         GIE=1;
         PEIE=1;
         RCIE=1;
         RCIF=0;
	}

Now, when any data is received then interrupt will occur. Then in interrupt service routine, if(RCIF==1) then collect the received value from RCREG register and clear RCIF. Choose SPBGR and BRGH value according to the baud rate requirement.
check datasheet of PIC16F87XA: page no 114. (hope you checked this since you already transmitted data)

or You can do it without interrupt also...In this case, you need to disable interrupt (RCIE=0); then you can check the status of RCIF periodically and if it become 1then clear it and read the received data from RCREG.
 
Last edited:
PHP:
void usrt_init()
	{
         SYNC=0;
         BRGH=1;
         SPEN=1;
         CREN=1;
         RX9=0;
         SPBRG=10;
         GIE=1;
         PEIE=1;
         RCIE=1;
         RCIF=0;
	}

Now, when any data is received then interrupt will occur. Then in interrupt service routine, if(RCIF==1) then collect the received value from RCREG register and clear RCIF. Choose SPBGR and BRGH value according to the baud rate requirement.
check datasheet of PIC16F87XA: page no 114. (hope you checked this since you already transmitted data)

or You can do it without interrupt also...In this case, you need to disable interrupt (RCIE=0); then you can check the status of RCIF periodically and if it become 1then clear it and read the received data from RCREG.

Thank you vinodstanur, is there a code for this in mikroC? i forgot to mention that i am using mikroC

---------- Post added at 07:16 ---------- Previous post was at 06:55 ----------

I am using mikroC compiler
 

if you use mikro C you should study from Help (F1) menu.
This below code is basic for programming.

You can use this code program to PIC and make GUI or PIC as master for sending data.
actually u can simmulate on Proteus.




Code:
unsigned short i;

void main() {

  // Initialize USART module (8 bit, 2400 baud rate, no parity bit..)
  Usart_Init(2400);

  do {
    if (Usart_Data_Ready()) {       // If data is received
      i = Usart_Read();                // Read the received data
      Usart_Write(i);                   // Send data via USART
    }
  } while (1);
}//~!
 
Thank you all for your help, i am now able to receive what i transmitted :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top