CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Push button 16f877a

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ventouza



Joined: 21 Apr 2014
Posts: 12
Location: Kefalonia, Greece

View user's profile Send private message

Push button 16f877a
PostPosted: Mon Feb 04, 2019 3:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 04, 2019 3:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 04, 2019 4:21 am     Reply with quote

Thanks a lot Ttelmah!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group