RS232 communication between two pic18f452

Status
Not open for further replies.
if the vote is casted then can i have a function of vote count i-e after all votes are casted then after that can i get toatal count of all vote casted for say candidate A.
 

i will look into this. i m right now trying to let my lcd backlight to be on but i m not getting any help for that on internet

- - - Updated - - -

ok . simple is that at the end when all votes would be casted for different candidates with cnic not duplicated suppose
fisrst cnic cast vote for candidate A and second cnic also cast vote for candidate A

then after vote casting how can i check how many votes Candidate A get.
 

i uaed counter for vote casting like this
Code:
#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);


        }

}

the above code is for ballot unit that is whenever the voter cast vote for candidate A the count gets incremented.
noe how can i display in the end when all votes have been casted for different candidates that how many votes candidate A or B or c ETC GETS.
 

If you have int variable counter and string variable myString[23] then the below code will convert int to string.

Code:
unsigned int counter = 0;
unsigned char myString[23];

void main() {

         IntToStr(counter, myString);
         Lcd_Out(1,1,myString);
}
 

ok i get it and on uart terminal is this the way to send string
Uart1_Write(mystring);

- - - Updated - - -

i m trying but not getting any idea. i needed that code for sending simple string through soft uart to pc urgently.
 

I thin UART1_Write() only send characters and not string. Check if the compiler has UART1_Write_Text() function if not write your own function using UART1_Write() function to send strings.

Try this

Code:
unsigned char myString[] = "Hello";


void UART1_Write_String(unsigned char myString1[]);



void UART1_Write_String(unsigned char myString1[]) {

	unsigned int i;

	for(i=0;i<strlen(myString1);i++) {

		UART1_Write(myString[i]);


	}

}

void main() {

	while(1) {

		UART1_Write_string(myString);
		Delay_ms(1000);


	}

}
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…