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 support@ccsinfo.com

HI Can any one help me why this bit of code is only partialy

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



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

HI Can any one help me why this bit of code is only partialy
PostPosted: Sun Apr 23, 2006 7:43 am     Reply with quote

HI Can any one tell me why this bit of code is only partialy working .

when i press PINA2 it goes to scan_lite() then when i press PINA3 it stops as Global Variable ALARM_ON is set to False . But this only works for two presses of PINA3 after that all the leds stay off permently . until i reset the PIC and it works again for only two presses . Many thanks for any help as you cac see i am a newbie Sad

[code#include <16F627.h>
#USE DELAY( CLOCK=4000000 ) // Using a 4 Mhz clock //

#byte PORTA = 0xFF // output port D definition //
#bit PIR = PORTA.0 //definitions to actual outputs
#bit WINDOW = PORTA.1
#bit DOOR = PORTA.3


#bit SET_ALARM_BUTTON =PORTA.2 //switch
#bit RESET_ALARM_BUTTON =PORTA.3 //switch


#byte PINB = 0x06 // input port B definition //
#bit STROBE_LITE = PINB.4 // OUTPUT //
#bit BUZZER = PINB.5 // OUTPUT //
#bit SPEAKER = PINB.6 // OUTPUT //

int1 ALARM_ON=FALSE;

int SET_ALARM();
void scan_lite();


void SET_ALARM();
void scan_lite();
int1 movingRight=FALSE;

void main(void)
{
set_tris_a(0xFF); // Set port A to all input
set_tris_b(0x00); // Set port B to all output



while(TRUE)
{
SET_ALARM();// call function
scan_lite();// call function

}

}// end of main

void scan_lite() // funtion to do a knight rider scan
{
int data; data = 1;

while(ALARM_ON)
{
output_b(data);

if(movingRight)
data >>= 1;
else
data <<= 1;

if(data == 0x04)
movingRight = TRUE;
else if(data == 0x01)
movingRight = FALSE;
delay_ms(50);
if(input(PIN_A3)) // check PIN3 reset global ALARM_ON
ALARM_ON=FALSE;
}// end of while

} // end of scan_lite


int SET_ALARM()
{
if (input(PIN_A2))// check PINA2 and set global ALARM_ON
ALARM_ON=TRUE;



} // end od SET_ALARM




[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 23, 2006 10:45 am     Reply with quote

Look at your #byte statement for Port A. Is it done correctly ?
The #byte statement is used to declare the address of a PIC
register so you can read or write to it directly with a line of code.
What is the address of the PortA register in the PIC ?

Get the 16F627 data sheet and look in this section to find the address:
Quote:

FIGURE 3-2: DATA MEMORY MAP OF THE PIC16F627 AND PIC16F628

Data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40300c.pdf
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