HI Can any one help me why this bit of code is only partialy
Posted: Sun Apr 23, 2006 7:43 am
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
[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
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
Posted: Sun Apr 23, 2006 10:45 am
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
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