Discussion in "PIC Microcontroller Discussion" started by    electronicfreak    Jun 25, 2008.
Wed Jun 25 2008, 03:09 pm
#1
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..............


[ Edited Thu Jun 26 2008, 11:50 am ]
Thu Jun 26 2008, 12:09 pm
#2
are you sure its working fine?

try this small change in main program..
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
}


I hope this is what you wanted
Fri Jun 27 2008, 09:29 am
#3


are you sure its working fine?

try this small change in main program..

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
}


I hope this is what you wanted

Ajay




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 .
Sat Jul 05 2008, 10:06 am
#4
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........
Sat Jul 05 2008, 10:19 am
#5
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am