Re: microcontroller AT89S52 programing advice
- From: Dave <dave@xxxxxxxxxxx>
- Date: Mon, 10 Jul 2006 03:32:58 -0500
On Sun, 09 Jul 2006 16:44:34 -0700, GaryKato@xxxxxxx wrote:
bromio wrote:
LED[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,125,0x07,0x7F,111};
unsigned char AMPM[2]={119,115};
timer1() interrupt 3
{
hmin=min/10;
lmin=min%10;
hhour=hour/10;
lhour=hour%10;
while(c<=4000)
{
le++;
c++;
switch(le)
{
<case stmt deleted>
}
}c=0;
sec++;
if(sec==60)
{sec=0;
min++;
}
if(min==60)
{min=0;
hour++;
}
}
main()
{
EA=1;
am=0;
le=0;
sec = 0;
min = 0;
hour= 0;
c=0;
init_timer();
for(;;)
{}
}
A loop in an interrupt service routine? No. Interrupt service routines
should do what is needed at that time and nothing more. They should be
as quick as possible.
He's using the loop to refresh the LEDs and provide a delay, I think.
Commented code is usually required for assignments--Profs and TAs hate
to guess what code is supposed to do. That code should not be in the ISR.
If you are trying to adjust the ISR rate to once per second this way, give
up. There are other ways to get a one second (more or less) tick for your
clock, and none of them involve running off a second in your ISR. Hint:
think in terms of averages for one approach.
How does am ever change? How do you expect to reset this clock--wait
until midnight and plug it in? Why do you use different bases for values
in LED? Why does LED use a different base than (some of) AMPM? The
if-clauses at the end of the ISR should logically be nested--only if
sec==60 does min need to be checked for 60.
I wouldn't expect much of a grade out of this effort. :-/ _Rethink_
then rewrite.
~Dave~
.
- References:
- Re: microcontroller AT89S52 programing advice
- From: GaryKato@xxxxxxx
- Re: microcontroller AT89S52 programing advice
- Prev by Date: Re: OneAgain - Which Development Board to Chose?
- Next by Date: Re: About EZ-USB FX2 Using external clock
- Previous by thread: Re: microcontroller AT89S52 programing advice
- Index(es):
Relevant Pages
|