View previous topic :: View next topic |
Author |
Message |
Ventouza
Joined: 21 Apr 2014 Posts: 12 Location: Kefalonia, Greece
|
Push button 16f877a |
Posted: Mon Feb 04, 2019 3:31 am |
|
|
Hi there,
i have written a simple program, when i press the button a led must be on!
But it doesn't, what am i doing wrong? I use the 5.008 version.
Here is the code:
Code: |
#define btn1 PIN_A0
#define test PIN_C1
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20MHz)
void main()
{
output_drive(test);
output_low(test);
output_float(btn1);
while(true)
{
if(input(btn1==0))
{
output_high(test);
}
else output_low(test);
}
}
|
The button is connected with an external pull up 10k resistor. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Feb 04, 2019 3:33 am |
|
|
One very major but simple syntax error:
if(input(btn1==0))
Needs to be:
if(input(btn1)==0)
Currently it is trying to input from a pin defined by the logical result of
comparing btn1, with the value 0.... |
|
|
Ventouza
Joined: 21 Apr 2014 Posts: 12 Location: Kefalonia, Greece
|
|
Posted: Mon Feb 04, 2019 4:21 am |
|
|
Thanks a lot Ttelmah! |
|
|
|