View previous topic :: View next topic |
Author |
Message |
vortexe90
Joined: 26 Feb 2013 Posts: 30 Location: Algeria
|
define input |
Posted: Thu Mar 28, 2013 6:22 am |
|
|
hi guys, I have a problem when I defined a 'Pin' of the microcontroller as input.
Example:
Code: | #include <16F877A.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
#define UP input(PIN_D2);
void main()
{
while(TRUE)
{
if (!UP)
{output_low(PIN_B4); }
}
|
Error when i compile:
Expecting a close paren
A numeric expression must appear here
I use CCS compiler v4.130 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9255 Location: Greensville,Ontario
|
|
Posted: Thu Mar 28, 2013 6:32 am |
|
|
I see
3 {
and
2 }
so the error message seems correct ..
hth
jay |
|
|
vortexe90
Joined: 26 Feb 2013 Posts: 30 Location: Algeria
|
|
Posted: Thu Mar 28, 2013 7:04 am |
|
|
I corrected the accolade but I still get the error
Code: | #include <16F877A.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
#define UP input(PIN_D2);
void main()
{
while(TRUE)
{
if (!UP) //-------------------> I corrected this accolade but I still get the error here
{output_low(PIN_B4);}
}
} |
|
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Thu Mar 28, 2013 7:31 am |
|
|
Take a look at your #define. You did it incorrectly. It replaces UP with everything after it. |
|
|
milan.rajik2013
Joined: 26 Mar 2013 Posts: 3 Location: Moscow
|
|
Posted: Thu Mar 28, 2013 7:53 am |
|
|
Use #define UP PIN_D2;
If PIN_D2 is a switch then you have to use debounce delay otherwise your code will not work.
Code: |
if(UP == 1) {
delay_ms(50);
if(UP == 1) {
PIN_D4 = ~PIN_D4;
}
}
|
_________________ Regards
Milan
Last edited by milan.rajik2013 on Thu Mar 28, 2013 7:58 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Thu Mar 28, 2013 7:57 am |
|
|
As a 'what to look for'. Jeremiah is giving the right answer.
'Defines' in C are text replacement macros. Exactly what is typed in the second part replaces what is typed in the first.
Take what is on your define line, as the replacement part, and type it in yourself where you use this. Does it look right?. |
|
|
|