electronicfreak
Jun 25 2008, 2:39 AM
hi friends,
i m facing aproblem with timer ...
void check_button();
void OFF();
//unsigned char
void inti_m();
unsigned short SECOND,cnt,minu,h,m;
int*MINUTE=1,HOUR=0,oldstate;
void min_init();
//void
void interrupt()
{
cnt++ ;
PIR1.TMR1IF = 0; // clear TMR1IF
TMR1H = 0x0B;
TMR1L = 0xF7;
if (cnt == 2) { // if cnt is 76
SECOND++;
cnt = 0; // reset cnt
if (SECOND==60)
{
SECOND=0; //reset SECOND
// m++;
// if(m==1)
// { m=0;
min_init() ; //GO TO min_init() function
//PORTB =~PORTB;
// }
}
}
}
void main()
{
inti_m();
check_button();
do{
if(PORTB.F0==0)
{check_button();
}
else if (PORTB.F0==1)
{
OFF();
}
}
while(1);
}
void inti_m()
{
//OPTION=0x40;
TRISB=0x00;
TRISC=0xFF;
PORTB=0xF0;
//PORTC=0x00;
TMR1H = 0x0B; // Initialize Timer1 register
TMR1L = 0xFD;
cnt = 0; // initialize cnt
INTCON = 0xC0; // Set GIE, PEIE
//PORTB = 0xF0; // Initialize PORTB
SECOND=0;
m=0;
minu=0;
}
void check_button()
{
for(;;)
{
if (PORTC.F0==1)
{ // Delay_ms(10);
// if(PORTB==0){
//if ( Button(&PORTB, 0, 1, 0)) {
PORTB.F0=1;
PIE1.TMR1IE = 1; // enable Timer1 interrupt
T1CON.T1CKPS1=1;
T1CON.T1CKPS0=1;
T1CON.T1OSCEN=1;
T1CON.TMR1ON = 1; // Timer1 settings
PIR1.TMR1IF = 0; // clear TMR1IF
/*}
else
{
OFF();
} */
break;
}
}
}
void min_init()
{
minu++;
if (minu>=MINUTE)
{ minu=0;
PORTB.F0 =0;
T1CON = 0;
}
// return 0;
}
void OFF()
{if(PORTC.F0==1)
{ PORTB=0;
T1CON = 0;
//INTCON.RBIF=0;
}
}
this is the programm for the 1min timer , operated when key is pressed.
it works fine ..... i m using mikro c compiler.....
but my problem is that after timer starts in between key is pressed microcontroller should be reset.....
or itshould go to the OFF () function and exicute it............
please any budy help me..............
i m facing aproblem with timer ...
CODE:
void check_button();
void OFF();
//unsigned char
void inti_m();
unsigned short SECOND,cnt,minu,h,m;
int*MINUTE=1,HOUR=0,oldstate;
void min_init();
//void
void interrupt()
{
cnt++ ;
PIR1.TMR1IF = 0; // clear TMR1IF
TMR1H = 0x0B;
TMR1L = 0xF7;
if (cnt == 2) { // if cnt is 76
SECOND++;
cnt = 0; // reset cnt
if (SECOND==60)
{
SECOND=0; //reset SECOND
// m++;
// if(m==1)
// { m=0;
min_init() ; //GO TO min_init() function
//PORTB =~PORTB;
// }
}
}
}
void main()
{
inti_m();
check_button();
do{
if(PORTB.F0==0)
{check_button();
}
else if (PORTB.F0==1)
{
OFF();
}
}
while(1);
}
void inti_m()
{
//OPTION=0x40;
TRISB=0x00;
TRISC=0xFF;
PORTB=0xF0;
//PORTC=0x00;
TMR1H = 0x0B; // Initialize Timer1 register
TMR1L = 0xFD;
cnt = 0; // initialize cnt
INTCON = 0xC0; // Set GIE, PEIE
//PORTB = 0xF0; // Initialize PORTB
SECOND=0;
m=0;
minu=0;
}
void check_button()
{
for(;;)
{
if (PORTC.F0==1)
{ // Delay_ms(10);
// if(PORTB==0){
//if ( Button(&PORTB, 0, 1, 0)) {
PORTB.F0=1;
PIE1.TMR1IE = 1; // enable Timer1 interrupt
T1CON.T1CKPS1=1;
T1CON.T1CKPS0=1;
T1CON.T1OSCEN=1;
T1CON.TMR1ON = 1; // Timer1 settings
PIR1.TMR1IF = 0; // clear TMR1IF
/*}
else
{
OFF();
} */
break;
}
}
}
void min_init()
{
minu++;
if (minu>=MINUTE)
{ minu=0;
PORTB.F0 =0;
T1CON = 0;
}
// return 0;
}
void OFF()
{if(PORTC.F0==1)
{ PORTB=0;
T1CON = 0;
//INTCON.RBIF=0;
}
}
this is the programm for the 1min timer , operated when key is pressed.
it works fine ..... i m using mikro c compiler.....
but my problem is that after timer starts in between key is pressed microcontroller should be reset.....
or itshould go to the OFF () function and exicute it............
please any budy help me..............
Ajay
Jun 25 2008, 11:39 PM
are you sure its working fine?
try this small change in main program..
I hope this is what you wanted
try this small change in main program..
CODE:
while(1){
while(PORTB.F0==0); //Wait for keypress
check_button(); //Keypressed start timer
while(PORTB.F0); //Wait for release
while(PORTB.F0==0); //wait for keypress again
OFF(); //key pressed stop timer
while(PORTB.F0); //wait for release
}
while(PORTB.F0==0); //Wait for keypress
check_button(); //Keypressed start timer
while(PORTB.F0); //Wait for release
while(PORTB.F0==0); //wait for keypress again
OFF(); //key pressed stop timer
while(PORTB.F0); //wait for release
}
I hope this is what you wanted

electronicfreak
Jun 26 2008, 8:59 PM
Ajay wrote ...
are you sure its working fine?
try this small change in main program..
CODE:
while(1){
while(PORTB.F0==0); //Wait for keypress
check_button(); //Keypressed start timer
while(PORTB.F0); //Wait for release
while(PORTB.F0==0); //wait for keypress again
OFF(); //key pressed stop timer
while(PORTB.F0); //wait for release
}
while(PORTB.F0==0); //Wait for keypress
check_button(); //Keypressed start timer
while(PORTB.F0); //Wait for release
while(PORTB.F0==0); //wait for keypress again
OFF(); //key pressed stop timer
while(PORTB.F0); //wait for release
}
I hope this is what you wanted
sir , my problem is that portB is zero when key is pressed timer starts , when it complete the given time timer reset, at that time key is pressed it works fine............
when timer is running in between key is pressed it won't take it , untill unless specified time will exicute .............
but software works fine..........
above mentioned problem occurs only when i burn hex to uC .
electronicfreak
Jul 4 2008, 9:36 PM
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........
i mentioned my problem in previous post...........
electronicfreak
Jul 4 2008, 9:49 PM
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........
i mentioned my problem in previous post...........