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

12f629 program problem

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



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

12f629 program problem
PostPosted: Sat May 22, 2010 1:11 am     Reply with quote

Hello
It gives 12f629, two buttons, two LEDs.
As long as the first button is held down, both LEDs are lit. If the second button is pressed, second LED goes off for 10 seconds. If you release the first button, both LEDs go off..

The program works fine but...the problem is that when I make that timing of 10 seconds, the second LED lights very short from time to time instead of going off, and I do not know why ...
Here is the program:

Code:

#include <12f629.h>
#FUSES NOWDT,INTRC_IO, NOPUT, NOPROTECT, NOBROWNOUT, NOMCLR, NOCPD
#use delay(clock=4000000)

long bec0=0; // variable for first button
long bec1=0; // ....for second button
long intr=0; // sistem interrupt variable
long sec=0; // secondes
int8 flag0=0; // led0 flag
int8 flag4=0; // led1 flag (buzer)
int8 flag4_temp=0; // disable timing flag

#int_rtcc
void clock_isr()
{
intr++;
if (intr>250)     //counts secondes
{
sec++;
intr=0;
}

////////////////////////////////////////////////////////////////////////////////
if (INPUT(PIN_A0)==0) //variable for first button
{
bec0++;
}

if (INPUT(PIN_A1)==0) //variable for seconde button
{
bec1++;
}
////////////////////////////////////////////////////////////////////////////////
//pin 0
if (bec0>4) //after 5 interrupts (20ms) the first button is certainly pressed
{
flag0=1; // ledul 0 ON
flag4=1; // ledul 1 ON (buzer)
}
//pin1(buzer)
if (bec1>4 && bec0>4) //after 5 interupts (20ms) second button is certainly pressed
{
flag4_temp=1; //activate timing
sec=0;
flag4=0;
}
////////////////////////////

if (!INPUT(PIN_A0)==0 && bec0>5) //first button released
{
flag0=0; //led0 OFF
flag4=0; //ledul1 OFF (buzer)
bec0=0; //button0 flag reset
sec=0;
flag4_temp=0; //timing flag reset
}
/////////////////////////////
if (!INPUT(PIN_A1)==0 && bec1>5) //second button released
{
bec1=0; //first button flag reset
flag4=0; //led1 OFF
}
///////////////////////////////////////////////////////////////////////////////
}

void main()
{
set_tris_a(0b000000011); //GP0, GP1 intrare GP2:GP5 iesiri
setup_comparator (NC_NC_NC_NC);
set_rtcc(6); //
setup_counters( RTCC_INTERNAL, RTCC_DIV_16 | RTCC_8_BIT);
enable_interrupts (INT_RTCC);
enable_interrupts(GLOBAL);
do
{
///////////////////////////////////////////////////
if(flag0==0) // stingere led0
output_low(PIN_A5);
if(flag0==1) // aprindere led1
output_high(PIN_A5);
//////////////////////////////////////////////////
if(flag4==0)
output_low(PIN_A4);
/////////////////////////////////////////////////
if(flag4_temp==1)
{
if (sec>10)
flag4=1;
else
flag4=0;
}
/////////////////////////////////////////////////
if(flag4==1)
output_high(PIN_A4);
////////////////////////////////////////////////////////////////////////////////
} while(1);
}
wwwglro



Joined: 03 Sep 2009
Posts: 17

View user's profile Send private message

PostPosted: Sun May 23, 2010 1:16 am     Reply with quote

After simulations made with Proteus, I found that those small flickers of the second LED are completely random compared to the seconds counted in the ISR.

Is correct besides counting seconds, to test if the buttons are pressed and do other stuff, in the ISR function?
Thank you

P.S. Is correct to initialize just once rtcc in main (ex: set_rtcc(6)) ?
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Sun May 23, 2010 1:41 am     Reply with quote

Can you check the output of that pin with a scope? Do you have all required pulldown/pulldown resistors connected? Is your clock configured correctly?

These are the obvious fixes, I don't have time at the moment to go over your entire code, it seems like a lot for a couple of LED's.
_________________
Vinnie Ryan
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