The microcontroller based voting machines made the process of voting and counting the voted lot easier than before. Previously the votes were marked in paper which are then stored safely in a box and inside a well secure room for days. The process of separating the votes and counting them manually may take a lot of days. But after finding the electronic voting machine the votes can be marked without using papers, which makes the voting process eco-friendly. Moreover it makes the counting process faster and the results can be announced in a comparatively shorter period of time.
This project is all about how we can make use of internal EEPROM of the AVR for storing data for future purpose. In this project we are making an Electronic Voting Machine (EVM) using the EEPROM of the AVR. As in the case of normal EVM, there is a control unit and a ballet unit. The ballet unit can be used to cast the vote only after it is enabled by pressing a key in the control unit. After casting a single vote the ballet unit will get disabled again. Each and every time a user press a key the LCD displays which candidate he voted for.
Project Source Code
###
#define F_CPU 8000000#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <avr/eeprom.h>#include "lcd.h"#include "usart.h"void switch_init ( void );void led_init ( void );void evm_init ( void );void evm_raedy_wait ( void );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 till any key is pressed// and read the current key pad valueswitch ( poll_result_mode ){case 0:while ( 1 ){evm_raedy_wait ();evm_vote ();}goto MENU;case 1:send_count_out ();goto MENU;case 2:reset_count ();goto MENU;}while ( 1 );}void switch_init ( void ){cli();DDRC &= 0xE0;PORTC = 0xFF;DDRD |= 0x80;PORTD |= 0x80;sei();}void led_init ( void ){cli();DDRD |= 0x80;PORTD |= 0x80;sei();}void evm_init (){led_init ();switch_init ();usart_init();lcd_init ();}void evm_raedy_wait ( void ){lcd_clear ();printf ( "_______EVM______" );//============ wait till evm unit enabled by external switch ===============//while ( ( PINC & 0x10 ) );_delay_ms ( 50 );while ( !( PINC & 0x10 ) );PORTD &= 0x7F;//============ wait till evm unit enabled by external switch ===============//lcd_clear ();printf ( "YOU CAN VOTE NOW" );}char read_key_wait ( void ){char button;while ( 0x0F == ( button = ( PINC & 0x0F ) ) ); // wait till any key is pressed// and read the current key pad value_delay_ms ( 50 );switch ( button ){case 0x0B:return 0;case 0x07:return 1;case 0x0D:return 2;case 0x0E:return 3;};return 0;}void evm_vote ( void ){char button;button = read_key_wait (); // wait till any key is pressed// and read the current key pad valueswitch ( button ){case 0:update_count ( 0 );lcd_clear ();printf ( "You voted for A" );break;case 1:update_count ( 1 );lcd_clear ();printf ( "You voted for B" );break;case 2:update_count ( 2 );lcd_clear ();printf ( "You voted for C" );break;case 3:update_count ( 3 );lcd_clear ();printf ( "You voted for D" );break;};PORTD |= 0x80;_delay_ms ( 3000 );}void update_count ( int candidate_address ){int base_address = 100;int 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#endif#include<avr/io.h>#include<util/delay.h>#include<inttypes.h>#include <stdio.h>#include <string.h>#define rs PA0#define rw PA1#define en PA2void lcd_init();void dis_cmd(char);void dis_data(char);void lcdcmd(char);void lcddata(char);void lcd_clear(void);void lcd_2nd_line(void);void lcd_1st_line(void);void lcd_string(const char *data);int lcd_print(char c, FILE *stream);int lcd_scroll(const char *data);FILE lcd_out = 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();elsedis_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;else;dis_data(disp_beg [i + j]);}j ++;_delay_ms(500);lcd_clear ();}return 0;}void lcd_string(const char *data){for(;*data;data++)dis_data (*data);}void lcd_clear(void){dis_cmd(0x01);_delay_ms(10);}void lcd_2nd_line(void){dis_cmd(0xC0);_delay_ms(1);}void lcd_1st_line(void){dis_cmd(0x80);_delay_ms(1);}void lcd_init() // fuction for intialize{DDRA=0xFF;dis_cmd(0x02); // to initialize LCD in 4-bit mode.dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit 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_value1 = cmd_value & 0xF0; //mask lower nibble because PA4-PA7 pins are used.lcdcmd(cmd_value1); // send to LCDcmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and masklcdcmd(cmd_value1); // 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){PORTA=cmdout;PORTA&=~(1<<rs);PORTA&=~(1<<rw);PORTA|=(1<<en);_delay_ms(1);PORTA&=~(1<<en);}void lcddata(char dataout){PORTA=dataout;PORTA|=(1<<rs);PORTA&=~(1<<rw);PORTA|=(1<<en);_delay_ms(1);PORTA&=~(1<<en);}#endif###
Project Source Code
###
#ifndef _USART_H#define _USART_H#ifndef F_CPU#define F_CPU 8000000#endif#define USART_BAUDRATE 9600#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)#include<avr/io.h>#include<util/delay.h>#include <stdio.h>void usart_init();void usart_putch(unsigned char send);unsigned int usart_getch();void usart_send_string(const char* data);int uart_print(char c, FILE *stream);FILE uart_out = 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 usart_init(){UCSRB |= (1 << RXEN) | (1 << TXEN);// Turn on the transmission and reception circuitryUCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);// Use 8-bit character sizesUBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..// into the low byte of the UBRR registerUBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..// into the high byte of the UBRR registerstdout = &uart_out;}void usart_putch(unsigned char send){while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..// for more data to be written to itUDR = send; // Send the byte}unsigned int usart_getch(){while ((UCSRA & (1 << RXC)) == 0);// Do nothing until data have been received and is ready to be read from UDRreturn(UDR); // return the byte}void usart_send_string(const char* data){for(; *data; data ++)usart_putch(*data);}#endif###
Circuit Diagrams
Project Components
Project Video
Filed Under: AVR, Electronic Projects
Filed Under: AVR, Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.