Page 327 - Programming Microcontrollers in C
P. 327
312 Chapter 6 Large Microcontrollers
/* initialize the SCI */
SCCR0.SCBR=BAUD_SET;/* set baud rate to 9600 */
SCCR2.TE=ON; /* enable the transmit and */
SCCR2.RE=ON; /* receiver of the SCI */
cli(); /* enable the system interrupts */
/* the applications portion of the program */
FOREVER
{
if (SCSR.RDRF==ON) /* read in data if it is there */
{
new_character=SCDR; /* get new byte,
reset RDRF */
while(SCSR.TDRE==OFF)
; /* wait until transmit
buffer empty */
SCDR=new_character; /* send out byte and
Reset TDRE */
/* got an input, process it */
if(new_character>=’0'&&new_character<=’9')
new_input=10*new_input+new_character-’0';
else if(new_character==’\r’)
{
/* reject any number out of range */
/* and start over again */
if(new_input>=1 && new_input<=4048)
pwm_count=new_input;
new_input=0;
}
else
new_input=0; /*reject everything else*/
}
if(sec>MAX_SEC)
{
sec=0;
if(++mts>MAX_MIN)
{
mts=0;
if(++hrs>MAX_HOURS)
hrs=MIN_HOURS;
}
}
if(been_here && !new_input)
{