View previous topic :: View next topic |
Author |
Message |
Ferdl Guest
|
INT_RDA trouble? comm from pc 2 pic |
Posted: Mon Apr 12, 2004 11:00 am |
|
|
i've ran into some troubles with my programm using int_rda.
it's only executed one time. after i hit enter a second time, it doesn't display anything.
Code: |
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#define buffer_SIZE 10
BYTE buffer[buffer_SIZE]={0};
BYTE tail = 0;
BYTE receivedFrame = 0;
int8 T1;
BYTE T2;
BYTE T3;
BYTE L1;
BYTE L2;
BYTE L3;
BYTE A1;
BYTE A2;
BYTE A3;
#INT_RDA
void serial_isr()
{
buffer[tail] = getc();
if(buffer[tail] == '\r' || tail == (buffer_SIZE - 1))
{
receivedFrame = 1;
disable_interrupts(int_rda);
}
else
{
tail++;
}
}
void message_handler()
{
int i;
T1=buffer[0];
T2=buffer[1];
T3=buffer[3];
L1=buffer[4];
L2=buffer[5];
L3=buffer[6];
A1=buffer[7];
A2=buffer[8];
A3=buffer[9];
if(T1>'0') output_high(PIN_B0);
if(T2>'0') output_high(PIN_B1);
if(T3>'0') output_high(PIN_B2);
if(L1>'0') output_high(PIN_B3);
if(L2>'0') output_high(PIN_B4);
if(L3>'0') output_high(PIN_B5);
if(A1>'0') output_high(PIN_B6);
if(A2>'0') output_high(PIN_B7);
for(i=0;i<BUFFER_SIZE-1;i++) buffer[i]=0;
}
void main()
{
BYTE head = 0;
enable_interrupts(global);
enable_interrupts(int_rda);
while (TRUE)
{
if(receivedFrame == 1)
{
// while(head <= tail){
// putc(buffer[head++]);
puts(buffer);
message_handler();
delay_ms(2500);
OUTPUT_B(0x00);
head = tail = 0;
receivedFrame = 0;
enable_interrupts(int_rda);
} // end if
} // end while true
}// end main
|
hyperterm output:
Code: |
5656
00000
111
000
00
1111
555
Ì11
|
[/code] |
|
![](templates/subSilver/images/spacer.gif) |
drolleman Guest
|
|
Posted: Mon Apr 12, 2004 3:40 pm |
|
|
you disable the interupt right after you start the funtion and reenable it before exiting the funtion |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Apr 13, 2004 7:26 am |
|
|
I perfer to use a buffer that is zero indexed rather than circular because of some efficiencies in decoding the recieved packet. Puting that aside I think this line is not going to work.
Code: | while(head <= tail) |
It should be this instead.
Code: | while(head != tail) |
Here is an example of how I handle serial packets.
http://home.houston.rr.com/neutone/serial.c |
|
![](templates/subSilver/images/spacer.gif) |
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
interrupts |
Posted: Tue Apr 13, 2004 2:10 pm |
|
|
Try disabling your global interrupts when you disable your int_rda just as a test. Try putting printf() around in the program to see if you are reaching points in the program when you should be. Helps to know exactly where your program stops working. Good place is in #int_rda itself to echo back each char received. |
|
![](templates/subSilver/images/spacer.gif) |
|