8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
electronicfreak
Wed Jun 25 2008, 02:39AM
 User Offline
Registered Member #7958
Joined: Tue May 20 2008, 04:48PM

Posts: 19
Thanked 0 times in 0 posts
hi friends,
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..............




[ Edited Wed Jun 25 2008, 11:20PM ]

SACHIN
http://belgaum.myminicity.com/
Back to top


Ajay
Wed Jun 25 2008, 11:39PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3375
Thanked 617 times in 584 posts
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
}
 


I hope this is what you wanted

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


electronicfreak
Thu Jun 26 2008, 08:59PM
 User Offline
Registered Member #7958
Joined: Tue May 20 2008, 04:48PM

Posts: 19
Thanked 0 times in 0 posts
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
}
 


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 .

SACHIN
http://belgaum.myminicity.com/
Back to top


electronicfreak
Fri Jul 04 2008, 09:36PM
 User Offline
Registered Member #7958
Joined: Tue May 20 2008, 04:48PM

Posts: 19
Thanked 0 times in 0 posts
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........

SACHIN
http://belgaum.myminicity.com/
Back to top


electronicfreak
Fri Jul 04 2008, 09:49PM
 User Offline
Registered Member #7958
Joined: Tue May 20 2008, 04:48PM

Posts: 19
Thanked 0 times in 0 posts
sir , u are suggested code is works as my code...............
i mentioned my problem in previous post...........

SACHIN
http://belgaum.myminicity.com/
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems