EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Could u plz help me in code

Could u plz help me in code

|

Projects › Projects › project on nuvoton arm cortex m0 › Could u plz help me in code

June 9, 2015 at 5:31 am #12970
Megha J V
Participant

Could u plz help me in code of voting machine whr the code has to be done with some modifications.

the control according to the code is taking many votes at a time but in voting the control shud go back to the entry state where it takes only one input

Code is :

#include<stdint.h>
#include<stdio.h>
#include "scankey.h"
#include "NUC1xx.h"
#include "DriverDrvSYS.h"
#include "NUC1xx-LB_002LCD_Driver.h"
 
 
 
int32_t main (void)
{
int8_t arr[4];
int8_t vote_amt[3],j;
int8_t vote1,vote2,vote3,vote4;
int8_t i;
char T[1]=":";
int8_t carry;
int8_t max=0;
 
char p1[50]=":";
char p2[50]="::";
int8_t candidate;
 
        int8_t number8;
 
      char t1[50]="a";
      char t2[50]=": ";
        char TEXT0[50]="Press 8 to vote ";
        char TEXT1[50]="WELCOME! VOTE P1  P2 P3 P4"; 
vote1 = vote2 = vote3 = vote4 = 0;
        UNLOCKREG();
    DrvSYS_Open(48000000); // set MCU to run at 48MHz
        LOCKREG();
 
        Initial_panel();
        clr_all_panel();
 
        OpenKeyPad();       // initialize 3×3 keypad
        print_lcd(0,TEXT0); // print title
 
                 
 
while(1)
{
number8=Scankey();
//number9=Scankey();
 
while(number8 == 8)
{
Initial_panel();
clr_all_panel();
print_lcd(0,TEXT1);
 DrvSYS_Delay(5000000);
Initial_panel();
clr_all_panel();
 
while(1)
{
 
candidate=Scankey();
 
sprintf(t2,"%d",candidate);
print_lcd(2,t2);
DrvSYS_Delay(5000000); 
   //function
 
while(candidate==1)
     {
Initial_panel();
    clr_all_panel();
  sprintf(p1,"%d",candidate);
  print_lcd(2,p1);
  DrvSYS_Delay(5000000);
while(candidate==1)
{
  Initial_panel();
    clr_all_panel();
print_lcd(0,"Candidate1");
    vote1 = vote1 + 1;
  sprintf(p2,"%d",vote1);
  print_lcd(2,p2);
  DrvSYS_Delay(5000000);
break;
}
break;
}
 
 
while(candidate==2)
     {
Initial_panel();
    clr_all_panel();
  sprintf(p1,"%d",candidate);
  print_lcd(2,p1);
  DrvSYS_Delay(5000000);
while(candidate==2)
{
  Initial_panel();
    clr_all_panel();
print_lcd(0,"Candidate2");
    vote2 = vote2 + 1;
  sprintf(p2,"%d",vote2);
  print_lcd(2,p2);
  DrvSYS_Delay(5000000);
break;
}
break;
}
 
 
while(candidate==3)
     {
Initial_panel();
    clr_all_panel();
  sprintf(p1,"%d",candidate);
  print_lcd(2,p1);
  DrvSYS_Delay(5000000);
while(candidate==3)
{
  Initial_panel();
    clr_all_panel();
print_lcd(0,"Candidate3");
    vote3 = vote3 + 1;
  sprintf(p2,"%d",vote3);
  print_lcd(2,p2);
  DrvSYS_Delay(5000000);
break;
}
break;
}
 
while(candidate==4)
     {
Initial_panel();
    clr_all_panel();
  sprintf(p1,"%d",candidate);
  print_lcd(2,p1);
  DrvSYS_Delay(5000000);
while(candidate==4)
{
  Initial_panel();
    clr_all_panel();
print_lcd(0,"Candidate4");
    vote4 = vote4 + 1;
  sprintf(p2,"%d",vote4);
  print_lcd(2,p2);
  DrvSYS_Delay(5000000);
break;
}
break;
}
 
if(candidate==9)
break;
 
}
 
 
while(candidate==9)
{
 
while(1)
{
Initial_panel();
    clr_all_panel();
print_lcd(0,"RESULTS ARE OUT");
print_lcd(1,"P1 P2 P3 P4");
sprintf(T,"%d  %d  %d  %d",vote1,vote2,vote3,vote4);
print_lcd(2,T);
DrvSYS_Delay(90000000);//delay(300);
    
 
 
 
arr[0] = vote1;
arr[1] = vote2;
arr[2] = vote3;
arr[3] = vote4;
 
for( i=0; i<4; i++)
{
  if(arr>=max)
  max = arr;
}
while(1){
if ( (vote1 == max) && ( vote2 != max) && (vote3 != max)&& (vote4 != max) )
{
  carry = 1;
 
Initial_panel();
    clr_all_panel();
print_lcd(2,"P1 WON!");
DrvSYS_Delay(300000000);
}
if ( (vote1 != max) && ( vote2 == max) && (vote3 != max)&& (vote4 != max) )
{
  carry = 1;
 
Initial_panel();
    clr_all_panel();
print_lcd(2,"P2 WON!");
DrvSYS_Delay(300000000);
}
if ( (vote1 != max) && ( vote2 != max) && (vote3 == max)&& (vote4 != max) )
{
  carry = 1;
 
Initial_panel();
    clr_all_panel();
print_lcd(2,"P3 WON!");
DrvSYS_Delay(300000000);
}
if ( (vote1 != max) && ( vote2 != max) && (vote3 != max)&& (vote4 == max) )
{
  carry = 1;
 
Initial_panel();
    clr_all_panel();
print_lcd(2,"P4 WON!");
DrvSYS_Delay(300000000);
}
}
 
}
}
}
}
 
}

RSS Recent Posts

  • Projector focus circuit May 18, 2026
  • Relay question May 18, 2026
  • Phone Charger 5v to 12v May 17, 2026
  • reviving old swordfish program but? May 17, 2026
  • Assistance locating a 'trail' camera gadget, please ? May 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise