TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: Medusa en 30 de Enero de 2014, 18:04:55
-
Hola,
Estoy usando CCS V4.079 para implementar un timeout de 30 seg para cuando reciba datos por el UART, pero no logro que salga del lazo de recepcion, alguien me puede decir en donde esta mi error!!
Aqui esta mi codgo:
#include <18F4520.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, timeout=5000)// RS232 Estándar
int8 next_in = 0;
int8 next_out = 0;
int8 theChar = 0;
int8 i;
int8 buffer[32];
char Signal_VAL[6];
int32 TimeOUT3_Clock;
int32 TimeOUT3;
#INT_RDA
void serial_isr() {
int t;
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % 32;
if(next_in==next_out)
next_in=t;
}
#define bkbhit (next_in!=next_out)
int8 bgetc() {
BYTE c;
WHILE(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % 32;
return(c);
}
void Clear_Buffer(){
for (i=0; i<32; i++){
buffer[i]= 0x00;
}
next_in = 0;
next_out = 0;
}
#INT_TIMER3
void Set_TimeOUT3() {
Set_Timer3(64911);
TimeOUT3_Clock++;
if (TimeOUT3_Clock >= 1000){
TimeOUT3++;
TimeOUT3_Clock = 0;
}
}
void Read_ISIG(){
Clear_Buffer();
TimeOUT3 = 0;
TimeOUT3_Clock = 0;
enable_interrupts(INT_TIMER3);
printf("AT_ISIG=1\r");
Delay_ms(100);
while ((theChar != '_') || (TimeOUT3 <= 30))theChar = bgetc();
theChar = bgetc();
if (theChar == 'I') {
theChar = bgetc();
if (theChar == 'S') {
theChar = bgetc();
if (theChar == 'I') {
theChar = bgetc();
if (theChar == 'G') {
theChar = bgetc();
if (theChar == ':') {
theChar = bgetc();
for (i=0; i<5; i++){
Signal_VAL[i] = bgetc();
}
}
}
}
}
}
disable_interrupts(INT_TIMER3);
}
void main() {
enable_interrupts(global);
enable_interrupts(int_rda);
setup_timer_3(T3_INTERNAL | T3_DIV_BY_8);
set_timer3(64911);
disable_interrupts(INT_TIMER3);
Read_ISIG();
while (TRUE){
delay_ms(200);
}
}
-
esa sentencia del timeout que esta dentro del define, nunca me funciono; asi que lo hice en forma distinta (usando timers), te pongo el enlace donde explico como funciona, ojala te sirva.
http://www.todopic.com.ar/foros/index.php?topic=41487.msg345399#msg345399 (http://www.todopic.com.ar/foros/index.php?topic=41487.msg345399#msg345399)