#define sw1 PORTD.F0
#define sw2 PORTD.F1
#define sw3 PORTD.F2
#define sw4 PORTD.F3
#define sw5 PORTD.F4
#define led1 PORTB.F0
#define led2 PORTB.F1
#define led3 PORTB.F2
#define led4 PORTB.F3
#define led5 PORTB.F4
int keypressed =0;
unsigned char key_char, received_char;
void voteCount();
int count1=count2=count3=count4=count5=0;
void main() {
TRISD=0xFF;
//TRISC=0x00;
TRISB = 0x00;
PORTB = 0x00;
TRISC.F6 = 1;
TRISC.F7 = 0;
UART1_Init(9600);
sw1=sw2=sw3=sw4=sw5=0;
voteCount();
}
void votecount()
{
while(1) {
// If data is ready, read it:
if (UART1_Data_Ready() == 1) {
received_char = UART1_Read();
}
if(received_char == '0') {
keypressed = 1;
}
else if(received_char == '1') {
keypressed = 0;
}
if(keypressed == 0) {
if((sw1 == 1) && (sw2 == 0) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 0) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 1;led2 = 0;led3 = 0;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = '1';
[QUOTE]like this[/QUOTE]
[QUOTE]count1++;[/QUOTE]
//UART1_Write_Text("switch 1 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 1;led3 = 0;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = '2';
count2++;
//UART1_Write_Text("switch 2 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 1;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = '3';
count3++;
// UART1_Write_Text("switch 3 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 0) && (sw4 == 1) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 0) && (sw2 == 0) && (sw3 == 0) && (sw4 == 1) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 0;led4 = 1;;led5 = 0;
keypressed = 1;
key_char = '4';
count4++
//UART1_Write_Text("switch 4 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 0) && (sw4 == 0) && (sw5 == 1)) {
Delay_ms(100);
if((sw1 == 0) && (sw2 == 0) && (sw3 == 0) && (sw4 == 0) && (sw5 == 1)) {
led1 = 0;led2 = 0;led3 = 0;led4 = 0;;led5 = 1;
keypressed = 1;
key_char = '5';
count5++;
//UART1_Write_Text("switch 5 pressed!");
}
}
}
UART1_Write(key_char);
}
}