I am currently writing a piece of code for a PIC18F1229 microcontroller using the software MXLAB v3.45 .
I have been tasked with flashing the middle segment at a speed of 1 flash per second and to stop it after 4 seconds using a switch stamement. I have managed to get the middle segment to flash at one flash per second but I am unsure how to close the switch statement. Would this be with a else statement and if so else what? Else false as all my other values are "true" . I have trialled using the "end" statement which flags an error as undefined indentifier. would this be a local indentifier or global. Please see my code below and perhaps make you might see where I have made a simple mistae.
This is my timer loop :
insert
Code:
WriteTimer0(0);
INTCONbits.TMR0IF=0;
while(TRUE) //Loop forever
{
Display(ucCount);
ucCount++;
if(ucCount>7) ucCount=0;
while (INTCONbits.TMR0IF==0);
INTCONbits.TMR0IF=0;
WriteTimer0(46004);
//1/10Mhz x 4 x 64 = 25.6 us. 500000/25.6 = 19531. 65545 - 19531 = 46004
}
CloseTimer0();
this is my switch statement:
insert
Code:
{
switch (ucHexDigit)
{
case 0:
LATB=0b00101011;
LATA=0b11111111;
break;
case 1:
LATB=0b11111111;
LATA=0b11111111;
break;
case 2:
LATB=0b00101011;
LATA=0b11111111;
break;
case 3:
LATB=0b11111111;
LATA=0b11111111;
break;
case 4:
LATB=0b00101011;
LATA=0b11111111;
break;
case 5:
LATB=0b11111111;
LATA=0b11111111;
break;
case 6:
LATB=0b00101011;
LATA=0b11111111;
break;
case 7:
LATB=0b11111111;
LATA=0b11111111;
break;
default: //display turned off
LATB=0b11111111;
LATA=0b11111111;
break;
}
}
As can be seen above The last statement deault turns all LEDS off and after this I would like to stop the switch statement from looping around again.
Any advice would be appreciated.