Máquina de votação eletrônica usando EEPROM interna do AVR

Electronic voting machine using AVR's internal EEPROM

The microcontroller based voting machines have made the process of voting and counting the voted batch easier than before. Previously, votes were marked on paper and then stored safely in a box in a well-protected room for days. The process of separating votes and manually counting them can take many days. But after finding the electronic ballot box, votes can be marked without using paper, which makes the voting process environmentally friendly. Furthermore, it makes the counting process faster and results can be announced in a comparatively shorter period of time.

There must be a controller within the Electronic Voting Machine ( EVM ) that controls the process and there must be a storage medium where the voting data is stored. There should be a ballet unit that was used in such a way that whoever came to vote could only vote one. There must also be a keyboard that can be used by those who wish to vote. In this project, the AVR microcontroller is used to demonstrate the operation of a simpler voting machine that can communicate serially with a PC and that can store the vote count in its internal memory.

This project is about how we can make use of AVR's internal EEPROM capabilities for storing data for future purposes. In this project we are making an Electronic Voting Machine (EVM) using the AVR's EEPROM. As with the normal EVM, there is a control unit and a ballet unit. The ballet unit can be used to vote only after it is enabled by pressing a key on the control unit. After casting a single vote, the ballet unit will be deactivated again. Each time a user presses a key, the LCD screens which candidate they voted for.

The interesting thing is that each time a vote is cast, the count will be automatically updated in the internal EEPROM. This way, once the vote has taken place, we can disconnect the unit from the power supply and keep it safe until counting day. We can turn on the board and even after a long period of time we can read the number of votes cast for each candidate by connecting the EVM to the HyperTerminal via serial communication with AVR .

Project source code

###


 #define F_CPU 8000000
#include #include #include #include #include "lcd.h" #include "usart.h" void switch_init(void); empty led_init (empty); empty evm_init ( empty ); empty evm_raedy_wait ( empty ); void evm_vote (void); char read_key_wait(void); void update_count (int candidate_address); void send_count_out(void); void reset_count(void); int main (void) { char poll_result_mode = 1; evm_init; MENU: //-----------------------------------------// stdout = &lcd_out; lcd_clear; printf("A-POLL B-COUNT"); printf("nRESET COUNT-C"); //-----------------------------------------// poll_result_mode=read_key_wait ; //wait until any key is pressed // and read the current value from the keyboard change ( poll_result_mode ) { case 0: while (1) { evm_raedy_wait ; evm_vote; } go to MENU; case 1: send_count_out; go to MENU; case 2: reset_count; go to MENU; } while (1); } empty switch_init (empty) { cli; DDRC &= 0xE0; PORTC = 0xFF; DDRD = 0x80; PORTD = 0x80; know ; } empty led_init (empty) { cli; DDRD = 0x80; PORTD = 0x80; know ; } empty evm_init { led_init; switch_init; usert_init; lcd_init; } empty evm_raedy_wait (empty) { lcd_clear; printf("_______EVM______"); //============ wait until the evm unit is enabled by the external switch ===============// while (( PINC & 0x10 ) ); _delay_ms(50); while ( !( PINC & 0x10 ) ); PORTD &= 0x7F; //============ wait until the evm unit is enabled by the external switch ===============// lcd_clear; printf("YOU CAN VOTE NOW"); } char read_key_wait (void) { char button; while (0x0F == (button = (PINC & 0x0F))); //wait until any key is pressed // and read the current value from the keyboard _delay_ms(50); switch (button) { case 0x0B: return 0; case 0x07: return 1; case 0x0D: return 2; case 0x0E: return 3; }; return 0; } empty evm_vote (empty) { char button; button=read_key_wait; //wait until any key is pressed // and read the current value from the keyboard switch (button) { case 0: update_count(0); lcd_clear; printf("You voted for A"); to break; case 1: update_count(1); lcd_clear; printf("You voted for B"); to break; case 2: update_count(2); lcd_clear; printf("You voted for C"); to break; case 3: update_count(3); lcd_clear; printf("You voted for D"); to break; }; PORTD = 0x80; _delay_ms(3000); } void update_count (int candidate_address) { int base_address = 100; internal count = 0; count = eeprom_read_byte ((unsigned char *) (base_address + candidate_address)); count++; eeprom_write_byte ((unsigned char *) (base_address + candidate_address), count); } void send_count_out(void) { int base_address = 100; int i = 0; stdout = &uart_out; printf("n________________________EVM______________________"); for (i = 0; i < 4; i++) printf("nCANDIDATE: %c, NO. VOTES: %d", ('A' + i), eeprom_read_byte ((unsigned char *) (base_address + i))); } void reset_count(void) { int base_address = 100; int i = 0; for (i = 0; i < 4; i++) eeprom_write_byte ((unsigned char *) (base_address + i), 0); lcd_clear; printf("RESET(OK)"); _delay_ms (2000); } ########## LCD ##########

#ifndef _LCD_H #define _LCD_H #ifndef F_CPU #define F_CPU 8000000 #end if #include #include #include #include #include #define lol PA0 #define rw PA1 #define in PA2 empty lcd_init; void dis_cmd(char); void dis_data(char); void lcdcmd(char); void lcddata(char); empty lcd_clear(empty); empty lcd_2nd_line(empty); empty lcd_1st_line(empty); void lcd_string(const char *data); int lcd_print(char c, FILE *stream); int lcd_scroll(const char *data); lcd_out FILE = FDEV_SETUP_STREAM(lcd_print, NULL, _FDEV_SETUP_WRITE); char disp_beg = " "; int lcd_print(char c, FILE *stream) { if('n' ==c) lcd_2nd_line ; other dis_data(c); return 0; } int lcd_scroll(const char *data) { int i; int j = 0; strcat(disp_beg, data); for(i = 0; i < 14; i++) strcat(disp_beg, " "); while(1) { for(i = 0;i < 16;i++) { if(!disp_beg(i + j)) return 0; other; dis_data(disp_beg(i + j)); } j++; _delay_ms(500); lcd_clear; } return 0; } void lcd_string(const char *data) { to(;*data;data++) dis_data (*data); } empty lcd_clear(empty) { dis_cmd(0x01); _delay_ms(10); } empty lcd_2nd_line(empty) { dis_cmd(0xC0); _delay_ms(1); } empty lcd_1st_line(empty) { dis_cmd(0x80); _delay_ms(1); } void lcd_init // function to initialize { DDRA=0xFF; dis_cmd(0x02); // to initialize the LCD in 4-bit mode. dis_cmd(0x28); //to initialize the LCD in 2 lines, 5X7 points and 4-bit mode. dis_cmd(0x0C); dis_cmd(0x06); dis_cmd(0x80); dis_cmd(0x01); _delay_ms(500); stdout = &lcd_out; } void dis_cmd(char cmd_value) { char cmd_value1; cmd_valor1 = cmd_valor & 0xF0; //masks the bottom nibble because pins PA4-PA7 are used. lcdcmd(cmd_valor1); //send to LCD cmd_valor1 = ((cmd_valor<<4) & 0xF0); //shift 4 bits and mask lcdcmd(cmd_valor1); //send to LCD } void dis_data(char data_value) { char data_value1; data_value1=data_value&0xF0; lcddata(data_value1); data_value1=((data_value<<4)&0xF0); lcddata(data_value1); } void lcdcmd(char cmdout) { PORT=cmdout; DOOR&=~(1< DOOR&=~(1< PORT =(1< _delay_ms(1); DOOR&=~(1< } void lcddata(char dataout) { PORT=data output; PORT =(1< DOOR&=~(1< PORT =(1< _delay_ms(1); DOOR&=~(1< } #end if

###

Project source code

###


 #ifndef _USART_H
#define _USART_H #ifndef F_CPU #define F_CPU 8000000 #end if #define USART_BAUDRATE 9600 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#include #include #include void usert_init ; void usert_putch(unsigned character send); unsigned int user_getch; void usert_send_string(const char* data); int uart_print(char c, FILE *stream); uart_out FILE = FDEV_SETUP_STREAM(uart_print, NULL, _FDEV_SETUP_WRITE); int uart_print(char c, FILE *stream) { if (c == 'n') uart_print('r', stream); loop_until_bit_is_set(UCSRA, UDRE); UDR = c; return 0; } void user_init { UCSRB = (1 << RXEN) (1 << TXEN); //Activates the transmit and receive circuit UCSRC = (1 << URSEL) (1< //Use 8-bit character sizes UBRRL = BAUD_PRESCALE; // Loads the lower 8 bits of the baud rate value. //in the low byte of the UBRR register UBRRH = (BAUD_PRESCALE >> 8); // Loads the upper 8 bits of the baud rate value. //in the high byte of the UBRR register stdout = &uart_out; } void usert_putch(unsigned character send) { while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until the UDR is ready. // for more data to be written to it UDR = send; // Send the byte } unsigned int usat_getch { while ((UCSRA & (1 << RXC)) == 0); // Do nothing until the data has been received and is ready to be read into the UDR return(UDR); //returns the byte } void usert_send_string(const char* data) { to(; *data; data++) usert_putch(*data); } #end if

###

Circuit diagrams

the circuit

Project Components

  • ATmega16
  • LCD
  • Resistor

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.