extern int address;
int status=0;
void number(int val)
{
switch(val)
{
case 0: PORTA=0x05; PORTC=0x0F; break;
case 1: PORTA=0x05; PORTC=0x00; break;
case 2: PORTA=0x06; PORTC=0x0D; break;
case 3: PORTA=0x07; PORTC=0x09; break;
case 4: PORTA=0x07; PORTC=0x02; break;
case 5: PORTA=0x03; PORTC=0x0B; break;
case 6: PORTA=0x03; PORTC=0x0F; break;
case 7: PORTA=0x05; PORTC=0x01; break;
case 8: PORTA=0x07; PORTC=0x0F; break;
case 9: PORTA=0x07; PORTC=0x03; break;
case 10: PORTA=0x00; PORTC=0x00; break;
default: break;
}
}
void test(void)
{
int j=0;
for(j=0;j<11;j++)
{
number(j);
__delay_ms(300);
}
PORTA=0x01;
__delay_ms(100);
PORTA=0x02;
__delay_ms(100);
PORTA=0x04;
__delay_ms(100);
PORTA=0x00;
PORTC=0x01;
__delay_ms(100);
PORTC=0x02;
__delay_ms(100);
PORTC=0x04;
__delay_ms(100);
PORTC=0x08;
__delay_ms(100);
}
void putch(unsigned char ch)
{
TXREG=ch;
while((TXSTA&0x02)==0){}
}
void menu(char ch)
{
if (ch==0xAF) //packet start byte
status=1;
else if (status==1 && ch==address)
status=2;
else if (status==2)
{
number(ch);
status=0;
}
else
status=0;
}
void init(void)
{
//Osc
OSCCON=0x70;
//Ports
TRISA=0xF8; //0,1,2 is output
TRISC=0xF0; //0,1,2,3 is output
//UART
TXSTA=0x24; //Enable TX
RCSTA=0x90; //Enable RX
BRGH=1;
BRG16=1;
SPBRG=16;
GIE=1; //Enable interrups
PEIE=1; //Peripheral interrups
RCIE=1; //receive interrupts
}