Saturday 5 October 2013

ELECTRONIC VOTING MACHINE USING ATmega16

Now a days Electronic Voting Machine is used for elections. So make your own EVM from here.

Introduction :-
                      In this project we use ATmega16 controller and a 16x2 alphanumeric LCD and Toggle switches. Program is loaded in the ATmega16 and the voting machine is ready to use.


Lcd Interfacing :-
                              see.. LCD INTERFACING WITH ATmega16 IN 4-BIT MODE


ATmega16 :-
                       

Components required :-

  1. 10k ohm registance
  2. 10k ohm variable registance
  3. 8 MHZ crystal oscilltor
  4. 16x2 LCD
  5. ATmega16 IC
  6. 12v battery 
  7. Toggle button -5
  8. 7805 IC
  9. 330 ohm resistance
  10. 1N4007 diode
  11. 1000uf capacitor
  12. Green LED



Circuit Diagram :-
                               
3 buttons are for votes and 4th button is for result.


Code (compiled in CVAVR) :-  

                                                (see.. CVAVR TUTORIAL (CODE VISION AVR))

Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.

-----------------------------------------------------------------------------------------------------------------------

#include <mega16.h>
#include <delay.h>
#include <stdlib.h>
// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// Declaration of global variables
int i,j,k; 
char a[10], b[10], c[10];
void main(void)
{
    // Port A initialization    
    PORTA=0x00;
    DDRA=0x00;
    // Port C initialization
    PORTC=0x00;
    DDRC=0x00;
    
     i=j=k=0;
    
    // LCD module initialization
    lcd_init(16);

    while (1)
    {
      //your code
        lcd_gotoxy(0,0);
        lcd_putsf("ENTER YOUR VOTE");
        lcd_gotoxy(0,1);
        lcd_putsf("1>BJP 2>JP 3>BSP");
        if(PINA.0==1)
        {
            i=i+1;
            delay_ms(100);
            lcd_clear();
            lcd_putsf("vote accepted");
            delay_ms(100);
            lcd_clear();
            lcd_gotoxy(0,0);
        }
        if(PINA.1==1)
        {
            j=j+1;
            lcd_clear();
            delay_ms(100);
            lcd_putsf("vote accepted");
            delay_ms(100);
            lcd_clear();
            lcd_gotoxy(0,0);
        }
        if(PINA.2==1)
        {
            k=k+1;
            lcd_clear();
            delay_ms(100);
            lcd_putsf("vote accepted");
            delay_ms(100);
            lcd_clear();
            lcd_gotoxy(0,0);
        }
        if(PINA.3==1)
        {
            if(i>j)
            {
                if(i>k)
                {
                    lcd_clear();
                    itoa(i,a);
                    lcd_putsf("winner is BJP=");
                    lcd_puts(a);
                    delay_ms(500);
                }
            }
            else if(j>k)
            {
                lcd_clear();
                itoa(j,b);
                lcd_putsf("winner is JP=");
                lcd_puts(b);
                delay_ms(500);
            }
            else
            {
                lcd_clear();
                itoa(k,c);
                lcd_putsf("winner is BSP=");
                lcd_puts(c);
                delay_ms(500);
            }
        }
    }    
      
}

-----------------------------------------------------------------------------------------------------------------------

Proteus simulation:-











LCD INTERFACING WITH ATmega16 IN 4-BIT MODE

Here we interface a 16x2 alphanumeric LCD with ATmega16 which is a AVR controller.
                                       
Pin configuration is written behind this LCD as...

1       -   GND
2       -   VCC (+5V)
3       -   VEE  (FOR CONTRAST)
4       -    RS    (REGISTER SELECT)
5       -    RW   (READ/WRITE)
6       -    EN    (ENABLE)
7-14  -    DATA PINS D0-D7
15      -   LED PLUS
16      -   LED MINUS


Components required :-
  1. 10k ohm registance
  2. 10k ohm variable registance
  3. 8 MHZ crystal oscilltor
  4. 16x2 LCD
  5. ATmega16 IC
  6. 12v battery 
  7. Toggle button
  8. 7805 IC
  9. 330 ohm resistance
  10. 1N4007 diode
  11. 1000uf capacitor
  12. Green LED

Circuit diagram : - 

                                 


In  4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.


Code (compiled in AVR studio 4) :-
                                                       (see.. AVR STUDIO 4 TUTORIAL)

Note :- In AVR studio 4 for compiling the program a makefile is necessary to create.
                                     (see.. HOW TO CREATE A MAKEFILE)
          Add this makefile in STUDIO 4. This makefile and lcd.c and lcd.h files must be in the               same folder of project. Click below links go to file>download.
                                (download.. lcd.c and lcd.h from here)

-----------------------------------------------------------------------------------------------------------------------

#include<avr/io.h>
#include<util/delay.h>
#include"lcd.h"
int main(void)
{
lcd_init(LCD_DISP_ON);
lcd_clrscr();
while(1)
{
lcd_gotoxy(3,0);
lcd_putc('E');
_delay_ms(500);
lcd_gotoxy(6,0);
lcd_puts("FOR");
_delay_ms(500);
lcd_gotoxy(3,1);
lcd_puts("ENGINEERS");
_delay_ms(500);
}
}

-----------------------------------------------------------------------------------------------------------------------



Code (compiled in CVAVR) :-  
                                                (see.. CVAVR TUTORIAL (CODE VISION AVR))

Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.

 ----------------------------------------------------------------------------------------------------------------------

#include <mega16.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void main(void)
{

// LCD module initialization
lcd_init(16);

while (1)
      {
        lcd_gotoxy(0,0);
        lcd_putsf("ashish");
      }
}

-----------------------------------------------------------------------------------------------------------------------
Proteus simulation of both codes :-





Note :- If you have problem to see characters in LCD then reduce the contrast level of LCD by increasing the resistance of 10k variable resistor.                                       

CVAVR TUTORIAL (CODE VISION AVR)

This is the software for programming of AVR. This is developed by HP.

This software is very user friendly and it is very easy to make a program in this software. In short CVAVR is for beginners.

Follow all the steps.

1. Download and open CVAVR. Goto file>new.



2. Select file type Project and click ok.



3. Select your chip type and click ok.



4. Now a window opens for including various functions or header files in your program automatically. First select your controller from chip option.



5. If you used LCD in your project then go to LCD and select LCD port.



6. If you want to enable ADC in your code then goto ADC and enble it and select various options according to you requirement.



7. If you want to enable SPI mode then go to SPI and enable it and select various options according to your requirement. As it is you can include many other options in your program given in above window automatically.



8. After including all your requirements go to file>generate, save and exit.



9. Now this window opens 3 times save your project at the location you want and typr the file name like evm in all 3 windows. All 3 file names must be same.



10. Now a project window opens where necessary header files are included automatically. You also can include any header file you want from the CVAVR library.



11. Declare all the variables above and scroll down to see while(1) function and write your code in while(1).



12. Click the button as shown in window for building your project.



13. Now a windows open make sure there is no error and no warning.



14. You can find your HEX file in EXE folder.



GOOD LUCK