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

16f877a input and output defining...

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



Joined: 10 Apr 2009
Posts: 1

View user's profile Send private message

16f877a input and output defining...
PostPosted: Fri Apr 10, 2009 10:12 am     Reply with quote

Hi everyone out there...
I'm trying to write a code to a 16f877a and I had tried to simulate the following code. However, when I troubleshoot and inject a 5V to the input pin to trigger and hoping for the output LED to light, it doesn't work.
Anyone can lighten my queries?

Code:
#include <16F877.H>
#FUSES HS,NOWDT,NOLVP
#USE DELAY(clock=12000000)
#USE RS232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


#DEFINE SIREN        PIN_B7
#DEFINE RED          PIN_B4
#DEFINE YELLOW       PIN_B3
#DEFINE GREEN        PIN_B2
#DEFINE TOUCH        PIN_A1
#DEFINE LIGHT        PIN_A2
#DEFINE DOOR         PIN_A3
#DEFINE PANIC        PIN_A4


//Turning On The Siren
void SIREN_ON()
{
   OUTPUT_HIGH(SIREN);
}

//Turning On The Red LED
void RED_ON()
{
   OUTPUT_HIGH(RED);
}

//Turning On The Yellow LED
void YELLOW_ON()
{
   OUTPUT_HIGH(YELLOW);
}

//Turning On The Green LED
void GREEN_ON()
{
   OUTPUT_HIGH(GREEN);
}


//Main Function
void MAIN()
{   

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

     
SET_TRIS_A(0xFF);
SET_TRIS_B(0x00);
SET_TRIS_C(0x0F);
SET_TRIS_D(0x00);

SENSOR1=INPUT(TOUCH);
SENSOR2=INPUT(LIGHT);
SENSOR3=INPUT(DOOR);
SENSOR4=INPUT(PANIC);

while(1){
      if(SENSOR1)
      {
         SIREN_ON();
         RED_ON();
      }
      else if(SENSOR2)
      {
         SIREN_ON();
         YELLOW_ON();
      }
      else if(SENSOR3)
      {
         SIREN_ON();
         RED_ON();
      }
      else if(SENSOR4)
      {
         SIREN_ON();
      }

}
}


The input of A1 to A4 is suppose to be connect to sensor with approximate 5V input to the pin when trigger, while the output will be 5v to the LED.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 10, 2009 10:25 am     Reply with quote

Quote:
SENSOR1=INPUT(TOUCH);
SENSOR2=INPUT(LIGHT);
SENSOR3=INPUT(DOOR);
SENSOR4=INPUT(PANIC);

while(1){


}

You are reading the sensors outside of the loop. If your program is
already running, it will be in the while() loop. It can't get any more
updates from the sensors. Put the sensor reading inside the loop.
It's also a good idea to put a delay_ms(100) statement (or more)
inside the loop to debounce the inputs.

Also, the standard in C is to use lower case (or mixed case) for function
names and variables. Upper case is mostly reserved for constants
(#define statements).
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