I am working with MC9S08AW60 on the Board-DEMO9S08AW60E. I have written the following code to perform Serial Comm, LED sequence and Keyboard Tx-RX.
for(;;)
{
int i =0;
if(TPM1SC_TOF == 1)
{
// this part shows the percentage of the voltage regulator on Hterm
bob = ADC1RL; /*ADC*/
if((SCI1S1 & (1<<7)))
{
SCI1D = ((bob*100)/255);
}
if(SCI1S1_RDRF == 1 ) /*KEYBOARD RX- lights up a specific LED*/
{
bob = SCI1S1;
if(SCI1D_R7_T7 == 1) PTFD_PTFD7 =1;
else PTFD_PTFD7 = 0;
}
// the following LED sequence is the PROBLEM-A-
/*for (i=1;i<=8;i++)
{
if (i==8) i = 1;
if (i==1) PTFD_PTFD0 = 0;else PTFD_PTFD0 = 1;
if (i==2) PTFD_PTFD1 = 0;else PTFD_PTFD1 = 1;
if (i==3) PTFD_PTFD2 = 0;else PTFD_PTFD2 = 1;
if (i==4) PTFD_PTFD3 = 0;else PTFD_PTFD3 = 1;
if (i==5) PTFD_PTFD4 = 0;else PTFD_PTFD4 = 1;
if (i==6) PTFD_PTFD5 = 0;else PTFD_PTFD5 = 1;
if (i==7) PTFD_PTFD6 = 0;else PTFD_PTFD6 = 1;
}*/
TPM1SC_TOF = 0;
}
}
Now, board performs the 2 actions really well: the Keyboard RX and Voltage regulator to percentage conversion. But as soon as I bring in the LED sequence part, it stops working on other two.
the logic for TIMER control is check for the overflow flag.
logic for Keyboard Rx is to check for hte RX-Flag.
logic for ADC is to check for the ADC data register.
I don't know how to place this question more accurately. If any ambiguity please let me know.
EDIT: the keboard RX and ADC percentage conversion is happening once per second whereas I want the LED sequence to occur at a rate of 250ms, i.e. once every 250ms, led changes state (1 to 0 and 0 to 1).
Links:
Newer code with respect to Oli Glaser's suggestions
for(;;)
{
if(TPM1SC_TOF < 1)
{
bob = ADC1RL; /*ADC*/
if((SCI1S1 & (1<<7)))
{
SCI1D = ((bob*100)/255);
}
if(SCI1S1_RDRF == 1 ) /*KEYBOARD RX*/
{
bob = SCI1S1;
if(SCI1D_R7_T7 == 1) PTFD_PTFD7 =1;
else PTFD_PTFD7 = 0;
}
TPM1C1SC_CH1IE = 0; // channel interrupt flag is reset
TPM1SC_TOF = 0; //timer overflow flag is reset
}
}
void ledseq()
{
for (i=1;i<=8;i++)
{
if (i==8) i = 1;
if (i==1) PTFD_PTFD0 = 0;else PTFD_PTFD0 = 1;
if (i==2) PTFD_PTFD1 = 0;else PTFD_PTFD1 = 1;
if (i==3) PTFD_PTFD2 = 0;else PTFD_PTFD2 = 1;
if (i==4) PTFD_PTFD3 = 0;else PTFD_PTFD3 = 1;
if (i==5) PTFD_PTFD4 = 0;else PTFD_PTFD4 = 1;
if (i==6) PTFD_PTFD5 = 0;else PTFD_PTFD5 = 1;
if (i==7) PTFD_PTFD6 = 0;else PTFD_PTFD6 = 1;
}
}
ISR
__interrupt void isrVtpm1ch1(void)
{
void ledseq();
/* Write your interrupt code here ... */
}
/* end of isrVtpm1ch1 */