View previous topic :: View next topic |
Author |
Message |
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
Program never exit function |
Posted: Thu Aug 13, 2009 4:20 pm |
|
|
Hi i have this function: Code: | int1 GetCO2() {
int8 T6603StatusReg,bty1,bty2;
int16 cnt;
bit_set(LED_Status);
fprintf(UART2,ReadStatusReg);
cnt=0;
while (fgetc(UART2) != 0xFF) {
cnt++;
delay_ms(1);
if (cnt==500) {
bit_clear(LED_Status);
break;
}
}
bty1 = fgetc(UART2);
bty2 = fgetc(UART2);
T6603StatusReg = fgetc(UART2);
If (T6603StatusReg != 0)
Return(1);
delay_ms(200);
fprintf(UART2, ReadCO2Level);
while (fgetc(UART2) != 0xFF) {
cnt++;
delay_ms(1);
if (cnt==500)
break;
}
bty1 = fgetc(UART2);
bty2 = fgetc(UART2);
CO2HighByte = fgetc(UART2);
CO2LowByte = fgetc(UART2);
CO2 = make16(CO2HighByte, CO2LowByte);
If ((CO2 > CO2Max) && (CO2 != 0))
CO2Max = CO2;
If ((CO2 < CO2Min) && (CO2 != 0))
CO2Min = CO2;
Return(0);
} |
but it never exits the function what could be wrong??? thanks! AC |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 13, 2009 4:29 pm |
|
|
Try to trouble-shoot the problem first, instead of asking us first.
Put some putc() statements after each section of code, so you can
trace the flow of the program. Example:
(Debug lines are marked with *** TESTING ***)
Code: |
int1 GetCO2() {
int8 T6603StatusReg,bty1,bty2;
int16 cnt;
fputc('1', UART1); // *** TESTING ***
bit_set(LED_Status);
fprintf(UART2,ReadStatusReg);
cnt=0;
fputc('2', UART1); // *** TESTING ***
while (fgetc(UART2) != 0xFF) {
fputc('3', UART1); // *** TESTING ***
cnt++;
delay_ms(1);
if (cnt==500) {
bit_clear(LED_Status);
fputc('4', UART1); // *** TESTING ***
break;
}
}
fputc('5', UART1); // *** TESTING ***
bty1 = fgetc(UART2);
fputc('6', UART1); // *** TESTING ***
bty2 = fgetc(UART2);
fputc('7', UART1); // *** TESTING ***
T6603StatusReg = fgetc(UART2);
fputc('8', UART1); // *** TESTING ***
|
Or, use a debugger, and put breakpoints in the routine. See how far
it gets. Find the line that's causing the problem.
Or, comment out sections of the routine until it does exit. Then
uncomment smaller sections and find the exact line or area that
is causing the problem.
Those are 3 methods you can use to find the problem. |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Thu Aug 13, 2009 7:08 pm |
|
|
Ya i know forums make us lazy, but i will resist and think before i speak.
I know where it jams that why i posted, it does on the first while loop but i don't know why it bugs out, it's a very simple piece of code. I tried connecting the UART to HTerm and the command is sent properly. When
i reconnect to my CO2 modules (T6603-5) UART at the right baud rate (19200) i don't receive the response back. You know what by the time i was writing this post i think i figured out my problem. The CO2 module from GE sensing works on 5V i guess i will need a level translator to talk with it or maybe just a pull-up resistor, hahaha thats a good one forums really make you think:0 Thanks PCM
AC
------------ |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 13, 2009 7:29 pm |
|
|
did you READ how fgetc() actually works ?
before you wrote that mess?
in French, i would say to you:
ne tenir aucun compte de, est ne pas prêter attention à. |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Thu Aug 13, 2009 7:50 pm |
|
|
instead of being a smart asm why don't don't you explain what mess
are you invoking. If you have something to say to me say it in english
because im french from Quebec. Thanks for the double pointer on reading the manual, the first being from PCM programmer. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 13, 2009 7:58 pm |
|
|
je comprendre
votre nom m'a dit que
mais maintenant lire le livre, ou allez loin
or Casse-toi |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Thu Aug 13, 2009 8:02 pm |
|
|
asmboy you sould read my previous reply before spontaniously answering
something not important, i said i'm pretty sure i found the problem in fact i am sure, i forgot to use a some sort of level translator between my CO2 module (5V) and the pic (3V) so it can't work, i guess VIH of the CO2 module Rx pin is too high or something, i will find it for sure i always do most of the time. ciao
AC
---------- |
|
|
|