Re: 8051 and a C switch statement
- From: Martin Griffith <mart_in_medina@xxxxxxxx>
- Date: Sun, 30 Dec 2007 18:45:20 +0100
On Sun, 30 Dec 2007 19:18:32 +0200, in comp.arch.embedded Anton
Erasmus <nobody@xxxxxxxxxxxxxxxx> wrote:
On Fri, 28 Dec 2007 23:39:04 +0100, Martin GriffithAh, there was I happily writing a 16 case switch.
<mart_in_medina@xxxxxxxx> wrote:
Got a 4k8 serial biphase signal being decoded by a at85c52 with an
external non retrig monostable (hc221), and I'm running out of time
occasionally waiting for the generic 2*8 LCD to clear it's busy flag.
The LCD is fed with the info from the incoming biphase
To reduce the "reaction time" I could use a long switch statement on
the signal's clock interrupt bitcount from the sync word, 80 per
frame, do just a little bit each interrupt.
The real question is
" how big can I make the switch statement?"
Whats the limit?
I'm using the rasionance C compiler.
There can be another problem, depending on your compiler.
The older IAR C51 Compilers generated thread unsafe code for
a switch statement for more than about 3 items, hence if one used
big switch statements inside an interrupt routine and outside, the
code crashed. This was for IAR C51 V4 and V5. I do not know whether
this has been fixed, or if an option had been added to force the
compiler to generate thread safe code.
You can always split a big switch statement into multiple smaller
ones. This is a bit slower than one big one.
i.e.
switch (var) /* Check bottom bits */
{
case 0:
break;
case maxsize:
break;
default:
switch(var)
{
case maxsize+1:
break;
}
}
Regards
Anton Erasmus
Generally speaking, should you keep code in a case statement short?
I was thinking that it should be like a interrupt, short and sweet
case 7:
{
temp=temp<<1;
temp=temp&0xff;
*LCDdata=temp+47;
break;
}
sort of thing
Sorry if the question seems a bit 101ish, but they didn't have
computers for humans when I was a lad.
martin
.
- Follow-Ups:
- Re: 8051 and a C switch statement
- From: Anton Erasmus
- Re: 8051 and a C switch statement
- References:
- 8051 and a C switch statement
- From: Martin Griffith
- Re: 8051 and a C switch statement
- From: Anton Erasmus
- 8051 and a C switch statement
- Prev by Date: Re: Why Google Is Failing as a Online Advertising Company
- Next by Date: Re: Report: Primates in Danger of Extinction
- Previous by thread: Re: 8051 and a C switch statement
- Next by thread: Re: 8051 and a C switch statement
- Index(es):
Relevant Pages
|