Re: microcontroller AT89S52 programing advice



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~
.



Relevant Pages

  • Re: Why does this freeze?
    ... A scope, some LEDs and ... Liberal use of LEDs is recommended to help trace what is ... is what is getting him by causing the ISR to be reentered recursively. ... Manually enabling interrupts while inside an ISR is ...
    (sci.electronics.misc)
  • Re: How do I get the program counter of another process (PowerPC)?
    ... I solved the problem by using an interrupt service routine instead of ... I attach my ISR to the clock ticker IRQ vector ... special register SRR0 contains the program counter to which the ISR ...
    (comp.os.os9)
  • Re: NMI isr
    ... If you can tell us why you're trying to write an *interrupt service routine* ... for a *non-maskable interrupt* (NMI) on Linux then maybe we can help. ... > Can someone show me how to setup NMI ISR under Linux for x86 arch? ...
    (alt.os.linux)
  • Which functions can I call from an ISR(Interrupt Service Routine)
    ... functions that can be called from an interrupt service routine, ISR. ... Standard functions like printf and so on cannot be used because blocking can ...
    (microsoft.public.windowsce.platbuilder)