View previous topic :: View next topic |
Author |
Message |
Charles Linquist
Joined: 07 May 2005 Posts: 28 Location: Campbell, CA
|
Undefined Identifier Error |
Posted: Sat May 14, 2005 11:44 am |
|
|
I have included a code fragment below. In the line flagged, I get the error "Undefined Identifier"
What I am trying to do is to read the state of an input pin, and
set a flag equal to that state.
Can someone tell me what I'm doing wrong?
//Below is the last part of an ISR
set_RTCC(0x67);
Flg1 = Input_PIN_A0; // Error occurs here
}
// Beginning of main program
void main()
{
int8 a;
int1 Flg1;
int1 Flg2; |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat May 14, 2005 11:51 am |
|
|
Try input(PIN_A0)
Also, see the manual page 122 |
|
|
Charles Linquist
Joined: 07 May 2005 Posts: 28 Location: Campbell, CA
|
|
Posted: Sat May 14, 2005 12:25 pm |
|
|
I tried the construct
FLG1 = input(Pin_A0);
as suggested, but it still tells me that
FLG1 is an "Undefined Identifier" |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat May 14, 2005 12:38 pm |
|
|
Either you have the CASE preprocessor line included (it is normally not case sensitive) or the declaration is out of scope. What you posted is not enough to tell where you are using the input() command. The variable either has to be defined in the routine where you are using it or, if it is global, the declaration line must be physically BEFORE any instance of it being used in the code.
BTW, What version PIC and compiler are you using?
Last edited by dyeatman on Sat May 14, 2005 12:43 pm; edited 1 time in total |
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Sat May 14, 2005 12:40 pm |
|
|
I think you have te declare the variable global.
Not in main.
Gerrit |
|
|
Charles Linquist
Joined: 07 May 2005 Posts: 28 Location: Campbell, CA
|
|
Posted: Sat May 14, 2005 3:32 pm |
|
|
That was my trouble. I needed to define the variable before I used it.
Thanks!
I'm trying to measure the RPM of a fan, and I need to know how many times a bit (tachometer) toggles in X milliseconds.
In PicBasic, I would use the routine
If PORTA.0 <> OldPortA THEN
Counter = Counter+1
OldPortA = PortA.0
ENDIF
In my C program, I have a 1msec timer interrupt running and I'm having trouble figuring out how to do the same thing. Is there some elegant way?
I'm not trying to be a pest, I'm just a newbie that is having a hard time.
I'm using compiler version 3.224 |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat May 14, 2005 4:48 pm |
|
|
Charles,
Usng the latest version, great!
Need to know a little more about what you are doing.
What PIC are you using and where are you connecting your fan tach input?
Is your timer on Timer0? Timer1?
If can you post the code you have so far it likely will answer most of the questions and we can help you clean it up and get it running the way you want.
P.S. PLease use the Code button when posting your code to retain the formatting. |
|
|
Charles Linquist
Joined: 07 May 2005 Posts: 28 Location: Campbell, CA
|
|
Posted: Sat May 14, 2005 6:26 pm |
|
|
I'm using an 18F452, although I will port it over to an 18F8722
I'm running the '452 at 20Mhz, My interrupt is tied to TMR0
Code: |
#include <18F458.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000) // 20MHz clock
#use fast_io(b)
int1 Flg1;
int1 Flg2;
int1 Flg3;
int1 Flg4;
int1 Flg5;
int1 Flg6;
int1 Flg7;
int1 Flg8;
int8 ToggleCounter1;
int8 ToggleCounter2;
int8 ToggleCounter3;
int8 ToggleCounter4;
int8 ToggleCounter5;
int8 ToggleCounter6;
int8 ToggleCounter7;
int8 ToggleCounter8;
#int_rtcc
RTCC_isr()
{
output_toggle(PIN_B0);
set_RTCC(0x67);
IF (Input(Pin_A0) != Flg1);
{++ToggleCounter1
Flg1 = Input(Pin_A0);
}
}
void main()
{
int8 a;
port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
set_tris_b(0x00);
set_tris_a(0xFF);
a = 0;
while (a == 0) // Note the '==' and no ';' here !!!
{
output_toggle(PIN_B1);
delay_ms(500); // Need to see if it is running without a scope
}
}
|
|
|
|
|