View previous topic :: View next topic |
Author |
Message |
xyzsor
Joined: 19 Dec 2010 Posts: 12
|
Does the PIC16f877a's UART buffer flooded? Need help. |
Posted: Mon Jan 31, 2011 12:44 am |
|
|
Good morning everyone. I have a little problem that I need help with.
I connected my PIC16f877a to a PC via UART.
I could send data and the PIC would receive it.
However I notice if the PIC is not reading the data being sent (example it is doing a sequence) and the UART of the pic, gets flooded with data. The pic's program hangs up or something like that.
Example I send the data
"?H???A?XYZ??Sd,v??!??3|?Ad?A?XYZa?Saja"
What I want to happen is that when the pic receives an XYZ data it would start a running lights sequence.
Heres my code.
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7) //Sets up serial port output pin & baud rate
#byte portb=6 /* defines memory location of register */
void main()
{
//declare variables
int8 data[10];
byte c,d;
set_tris_b(0x00);
delay_ms(500);
//test if pic is working
portb = 0xFF;
delay_ms(500);
portb = 0x00;
delay_ms(500);
portb = 0xFF;
delay_ms(500);
portb = 0x00;
delay_ms(500);
//wait for passphrase
while (true)
{
data[0] = getc();
if (data[0]=='X')
{
portb = 0x01;
again:
data[1] = getc();
if (data[1]=='X')
goto again;
if (data[1]=='Y')
{
portb = 0x03;
data[2] = getc();
if (data[2]=='Z')
{
//start a running lights pattern
c = 0; /*initialize the count c equal to zero */
d = 0x01; /* assigns the content of d to 0x01 */
while(c<8) {
portb = d; /*sends content of d to portb to turn-on the first LED*/
delay_ms(80); /* creates half second delay between LED on/off*/
d = d << 1; /* shifts the value of data to the left by 1 using shift left operator(<<) */
c++; /* increments the value of c by 1*/
}
}
}
}
else
portb = 0x55;
}
}
|
It works well if I sent data when the pic is just reading or waiting for the XYZ during the getc() part.
But if I send a stream of data while the pic is doing a running lights sequence, the PIC would hang up.
Whats wrong? Does the PIC get flooded? Is there a way to clear the PICS UART buffer before starting the getc() again?
Thanks in advance to everyone who helps. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Jan 31, 2011 3:33 am |
|
|
ERRORS......
Last answered on Saturday, in the thread 'continuous serial reception'.
Do a search.
Best Wishes |
|
|
xyzsor
Joined: 19 Dec 2010 Posts: 12
|
Thanks |
Posted: Mon Jan 31, 2011 9:23 am |
|
|
Ttelmah wrote: | ERRORS......
Last answered on Saturday, in the thread 'continuous serial reception'.
Do a search.
Best Wishes |
Nice!.. Thanks a lot.. just one word, fixed it all.. Errors.. Again thanks... |
|
|
|