sobia sarwar
Member level 5
- Joined
- Nov 15, 2012
- Messages
- 81
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,883
when any of the switch connected with ballot unit is pressed the glcd connected with the control unit display that vote is casted and also check no switch is pressed more than once
when any of the switch connected with ballot unit is pressed the glcd connected with the control unit display that vote is casted and also check no switch is pressed more than once and its not happening.simple transfer is happening
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;
}
}
else if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 1;led3 = 0;led4 = 0;;led5 = 0;
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 1;led4 = 0;;led5 = 0;
}
}
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;
}
}
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;
}
}
also check no switch is pressed more than once
and its not happening
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;
}
}
else if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 1;led3 = 0;led4 = 0;;led5 = 0;
keypressed = 1;
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 1;led4 = 0;;led5 = 0;
keypressed = 1;
}
}
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;
}
}
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;
}
}
}
PIC with buttons code
unsigned char key_char;
void main() {
UART_Init(9600);
while(1) {
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;
}
}
else if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 1;led3 = 0;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = 2;
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 1;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = 3;
}
}
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;
}
}
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;
}
}
}
UART1_Write(key_char);
}
}
PIC with GLCD code
unsigned char key_char;
Void main() {
while(1) {
// If data is ready, read it:
if (UART_Data_Ready() == 1) {
key_char = UART_Read();
}
switch(key_char) {
case '1':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '2'
.
.
.
default:
break;
}
}
}
#include"image.h"
#define max_character 18 // length of barcode
/*************************SDCARD************************/
sbit Mmc_Chip_Select at RC0_bit;
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
/**************************glcd***************************/
char Glcd_DataPort at PORTD;
sbit Glcd_CS1 at RB5_bit; // GLCD chip select 1
sbit Glcd_CS2 at RB6_bit; // GLCD chip select 2
sbit Glcd_RS at RB2_bit; // GLCD data/instruction
sbit Glcd_RW at RB3_bit; // GLCD read/write
sbit Glcd_EN at RB4_bit; // GLCD enable
sbit Glcd_RST at RB7_bit; // GLCD reset
sbit Glcd_CS1_Direction at TRISB5_bit;
sbit Glcd_CS2_Direction at TRISB6_bit;
sbit Glcd_RS_Direction at TRISB2_bit;
sbit Glcd_RW_Direction at TRISB3_bit;
sbit Glcd_EN_Direction at TRISB4_bit;
sbit Glcd_RST_Direction at TRISB7_bit;
/*******************BARCODE****************************/
sbit PS2_Data at RA3_bit;
sbit PS2_Clock at RA4_bit;
sbit PS2_Data_Direction at TRISA3_bit;
sbit PS2_Clock_Direction at TRISA4_bit;
/*********************************************************/
void UART_Write_2DArray(char _2DArray[10][16], unsigned int _row, unsigned int _col);
unsigned short keydata = 0, special = 0, down = 0;
char fat_txt[20] = "FAT16 not found";
char filename[11] = "voter1.txt"; // File names
char character='l';
unsigned long size;
char Buffer[512];
char txt[] = "34101-9764655-9";
//char txt1[] = "34101-9764655-9";
char cnics[16];
char tmp2[16];
char cnics_array[10][16];
int res;
unsigned int count, row, col, _row, _col = 0;
unsigned char TwoDArray[10][16];
unsigned int k = 0;
unsigned int match_counter = 0, read_counter = 0;
int b_duplicate = 0;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
char repeat[10]={0,0,0,0,0,0,0,0,0,0};
int ctr=-1;
char ctrtxt[10];
int row1;
//unsigned char received_text[50];
unsigned char key_char;
int di;
///////////////////////////////////barcode scan///////////////////////////////
void Barcodescan()
{ memset(barcode, 0, max_character); // all character set to 0
if (Ps2_Key_Read(&keydata, &special, &down))
{
if (down && (keydata == 13))
{ // Enter
// Glcd_Fill(0);
//Glcd_Write_Text(barcode, 0, 0, 1);
memset(barcode, 0, max_character);
counter = 0;
// UART1_Write(text);
}
else if (down && (keydata == 16))
{
counter--;
barcode[counter] = 0;
// set previous charater to 0
}
else if (down && !special && keydata)
{ // other keys
barcode[counter++] = keydata;
}
}
}
///////////////////////////file read & compare//////////////////////////////////
void M_Open_File_Read()
{
Mmc_Fat_Assign(&filename, 0);
Mmc_Fat_Reset(&size);
row = 0;
j = 0;
do {
ctr++;
Mmc_Fat_Read(&character);
while(character!= ' ') {
cnics[count] = character;
count++;
Mmc_Fat_Read(&character);
}
if(character == ' ') {
while(character != '\n') {
Mmc_Fat_Read(&character);
}
}
cnics[count] = '\0';
UART1_Write_Text("cnics = ");
UART1_Write_Text(cnics);
UART1_Write(10);
UART1_Write(13);
i = 0;
col = 0;
for(i=0;i<count;i++) {
/*
if(cnics[i] == '\0')
{
cnics_array[row][col]='\0';
}
else {
*/ cnics_array[row][col]= cnics[i];
col++;
//}
}
count = 0;
//UART1_Write_Text("cnics array = ");
//UART_Write_2DArray(cnics_array, row, col);
UART1_Write(10);
UART1_Write(13);
for (k=0;k<15;k++) {
tmp2[k] = cnics_array[row][k];
}
//tmp2[15] = '\0';
//UART1_Write_Text("tmp2 = ");
//UART1_Write_Text(tmp2);
UART1_Write(10);
UART1_Write(13);
//UART1_Write_Text("txt = ");
//UART1_Write_Text(txt);
UART1_Write(10);
UART1_Write(13);
row++;
j++;
k = 0;
col = 0;
for(i=0;i<15;i++) {
if(txt[i] == tmp2[i]) {
match_counter++;
// repeat[i]=1;
}
}
i = 0;
/* UART1_Write_Text("ctr = ");
IntToStr(ctr, ctrtxt); // txt is " -4220" (one blank here)
UART1_Write_Text(ctrtxt);
*/
if(match_counter == 15 && repeat[ctr] ==0) {
repeat[ctr]=1;
UART1_Write_Text("txt[] matches with tmp2[]");
// UART1_Write_Text("repeat = ");
/*for(row1=0;row1<10;row1++)
{
IntToStr(repeat[row1], repeattxt);
UART1_Write_Text(repeattxt);
UART1_Write_Text(" ");
}*/
UART1_Write_Text(13);
Glcd_Write_Text("Welcome To Voting Machine", 3, 3, 0);
b_duplicate = 1;
break;
}
else
{
UART1_Write_Text("txt[] doesn't match with tmp2[]");
repeat[ctr]=0;
Glcd_Write_Text("Oops! can't cast vote", 3, 3, 0);
b_duplicate = 0;
}
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
match_counter = 0;
} while(row < 10);
}
///////////////////////////////////verification/////////////////////////////////
int VerifyDuplicateVoter()
{ M_Open_File_Read();
}
void UART_Write_2DArray(char _2DArray[][16], unsigned int _row, unsigned int _col) {
for(i=0;i<=_col;i++) {
TXREG = _2DArray[_row][i];
while(!PIR1.TXIF); //(while(!TXSTA.TRMT); TXSTA>TRMT = 0;
PIR1.TXIF = 0;
PIE1.TXIE = 1;
}
}
//-------------- Main. Uncomment the function(s) to test the desired operation(s)
void main()
{
PORTB = 0x00;
TRISB = 0X00;
PORTA = 1;
TRISA = 1;
TRISD=0;
TRISC =0;
PORTC = 0x02;
TRISC.F6 = 0;
TRISC.F7 = 1;
PORTC = 0x02;
UART1_Init(9600);
Ps2_Config();
Glcd_Init();
Glcd_Fill(0xff);
Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);
Ps2_Config();
delay_ms(1000);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init ()==0)
{
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//M_Open_File_Read();
res = VerifyDuplicateVoter();
while(1) {
// If data is ready, read it:
if (UART1_Data_Ready() == 1) {
key_char = UART1_Read();
}
switch(key_char) {
case '1':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '2':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '3':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '4':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '5':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
default:
break;
}
}
}
else if (Mmc_Fat_Init()== 1)
{
UART1_Write('y');
}
else
{
UART1_Write('z');
}
}
#define sw1 PORTD.F0
#define sw2 PORTD.F1
#define sw3 PORTD.F2
#define sw4 PORTD.F3
#define sw5 PORTD.F4
#define led1 PORTC.F0
#define led2 PORTC.F1
#define led3 PORTC.F2
#define led4 PORTC.F3
#define led5 PORTC.F4
int keypressed =0;
unsigned char key_char;
void voteCount();
int count=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(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;
//UART1_Write_Text("switch 1 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 1) && (sw3 == 0) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 1;led3 = 0;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = 2;
//UART1_Write_Text("switch 2 pressed!");
}
}
else if((sw1 == 0) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
Delay_ms(100);
if((sw1 == 1) && (sw2 == 0) && (sw3 == 1) && (sw4 == 0) && (sw5 == 0)) {
led1 = 0;led2 = 0;led3 = 1;led4 = 0;;led5 = 0;
keypressed = 1;
key_char = 3;
// 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;
//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;
//UART1_Write_Text("switch 5 pressed!");
}
}
}
UART1_Write(key_char);
}
}
#include"image.h"
#define max_character 18 // length of barcode
/*************************SDCARD************************/
sbit Mmc_Chip_Select at RC0_bit;
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
/**************************glcd***************************/
char Glcd_DataPort at PORTD;
sbit Glcd_CS1 at RB5_bit; // GLCD chip select 1
sbit Glcd_CS2 at RB6_bit; // GLCD chip select 2
sbit Glcd_RS at RB2_bit; // GLCD data/instruction
sbit Glcd_RW at RB3_bit; // GLCD read/write
sbit Glcd_EN at RB4_bit; // GLCD enable
sbit Glcd_RST at RB7_bit; // GLCD reset
sbit Glcd_CS1_Direction at TRISB5_bit;
sbit Glcd_CS2_Direction at TRISB6_bit;
sbit Glcd_RS_Direction at TRISB2_bit;
sbit Glcd_RW_Direction at TRISB3_bit;
sbit Glcd_EN_Direction at TRISB4_bit;
sbit Glcd_RST_Direction at TRISB7_bit;
/*******************BARCODE****************************/
sbit PS2_Data at RA3_bit;
sbit PS2_Clock at RA4_bit;
sbit PS2_Data_Direction at TRISA3_bit;
sbit PS2_Clock_Direction at TRISA4_bit;
/*********************************************************/
void UART_Write_2DArray(char _2DArray[10][16], unsigned int _row, unsigned int _col);
unsigned short keydata = 0, special = 0, down = 0;
char fat_txt[20] = "FAT16 not found";
char filename[11] = "voter1.txt"; // File names
char character='l';
unsigned long size;
char Buffer[512];
char txt[] = "34101-9764655-9";
//char txt1[] = "34101-9764655-9";
char cnics[16];
char tmp2[16];
char cnics_array[10][16];
int res;
unsigned int count, row, col, _row, _col = 0;
unsigned char TwoDArray[10][16];
unsigned int k = 0;
unsigned int match_counter = 0, read_counter = 0;
int b_duplicate = 0;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
char repeat[10]={0,0,0,0,0,0,0,0,0,0};
int ctr=-1;
char ctrtxt[10];
int row1;
//unsigned char received_text[50];
unsigned char key_char;
int di;
///////////////////////////////////barcode scan///////////////////////////////
void Barcodescan()
{ memset(barcode, 0, max_character); // all character set to 0
if (Ps2_Key_Read(&keydata, &special, &down))
{
if (down && (keydata == 13))
{ // Enter
// Glcd_Fill(0);
//Glcd_Write_Text(barcode, 0, 0, 1);
memset(barcode, 0, max_character);
counter = 0;
// UART1_Write(text);
}
else if (down && (keydata == 16))
{
counter--;
barcode[counter] = 0;
// set previous charater to 0
}
else if (down && !special && keydata)
{ // other keys
barcode[counter++] = keydata;
}
}
}
///////////////////////////file read & compare//////////////////////////////////
void M_Open_File_Read()
{
Mmc_Fat_Assign(&filename, 0);
Mmc_Fat_Reset(&size);
row = 0;
j = 0;
do {
ctr++;
Mmc_Fat_Read(&character);
while(character!= ' ') {
cnics[count] = character;
count++;
Mmc_Fat_Read(&character);
}
if(character == ' ') {
while(character != '\n') {
Mmc_Fat_Read(&character);
}
}
cnics[count] = '\0';
UART1_Write_Text("cnics = ");
UART1_Write_Text(cnics);
UART1_Write(10);
UART1_Write(13);
i = 0;
col = 0;
for(i=0;i<count;i++) {
/*
if(cnics[i] == '\0')
{
cnics_array[row][col]='\0';
}
else {
*/ cnics_array[row][col]= cnics[i];
col++;
//}
}
count = 0;
//UART1_Write_Text("cnics array = ");
//UART_Write_2DArray(cnics_array, row, col);
UART1_Write(10);
UART1_Write(13);
for (k=0;k<15;k++) {
tmp2[k] = cnics_array[row][k];
}
//tmp2[15] = '\0';
//UART1_Write_Text("tmp2 = ");
//UART1_Write_Text(tmp2);
UART1_Write(10);
UART1_Write(13);
//UART1_Write_Text("txt = ");
//UART1_Write_Text(txt);
UART1_Write(10);
UART1_Write(13);
row++;
j++;
k = 0;
col = 0;
for(i=0;i<15;i++) {
if(txt[i] == tmp2[i]) {
match_counter++;
// repeat[i]=1;
}
}
i = 0;
/* UART1_Write_Text("ctr = ");
IntToStr(ctr, ctrtxt); // txt is " -4220" (one blank here)
UART1_Write_Text(ctrtxt);
*/
if(match_counter == 15 && repeat[ctr] ==0) {
repeat[ctr]=1;
UART1_Write_Text("txt[] matches with tmp2[]");
// UART1_Write_Text("repeat = ");
/*for(row1=0;row1<10;row1++)
{
IntToStr(repeat[row1], repeattxt);
UART1_Write_Text(repeattxt);
UART1_Write_Text(" ");
}*/
UART1_Write_Text(13);
Glcd_Write_Text("Welcome To Voting Machine", 3, 3, 0);
b_duplicate = 1;
UART1_Write('1');
break;
}
else
{
UART1_Write_Text("txt[] doesn't match with tmp2[]");
repeat[ctr]=0;
Glcd_Write_Text("Oops! can't cast vote", 3, 3, 0);
b_duplicate = 0;
UART1_Write('0');
}
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
match_counter = 0;
} while(row < 10);
}
///////////////////////////////////verification/////////////////////////////////
int VerifyDuplicateVoter()
{ M_Open_File_Read();
}
void UART_Write_2DArray(char _2DArray[][16], unsigned int _row, unsigned int _col) {
for(i=0;i<=_col;i++) {
TXREG = _2DArray[_row][i];
while(!PIR1.TXIF); //(while(!TXSTA.TRMT); TXSTA>TRMT = 0;
PIR1.TXIF = 0;
PIE1.TXIE = 1;
}
}
//-------------- Main. Uncomment the function(s) to test the desired operation(s)
void main()
{
PORTB = 0x00;
TRISB = 0X00;
PORTA = 1;
TRISA = 1;
TRISD=0;
TRISC =0;
PORTC = 0x02;
TRISC.F6 = 0;
TRISC.F7 = 1;
PORTC = 0x02;
UART1_Init(9600);
Ps2_Config();
Glcd_Init();
Glcd_Fill(0xff);
Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);
Ps2_Config();
delay_ms(1000);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init ()==0)
{
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//M_Open_File_Read();
res = VerifyDuplicateVoter();
while(1) {
// If data is ready, read it:
if (UART1_Data_Ready() == 1) {
key_char = UART1_Read();
}
switch(key_char) {
case '1':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '2':
GLCD_Write_Text("Switch 2 Pressed", 3, 0, 1);
break;
case '3':
GLCD_Write_Text("Switch 3 Pressed", 3, 0, 1);
break;
case '4':
GLCD_Write_Text("Switch 4 Pressed", 3, 0, 1);
break;
case '5':
GLCD_Write_Text("Switch 5 Pressed", 3, 0, 1);
break;
default:
break;
};
}
}
else if (Mmc_Fat_Init()== 1)
{
UART1_Write('y');
}
else
{
UART1_Write('z');
}
}
#define sw1 PORTD.F0
#define sw2 PORTD.F1
#define sw3 PORTD.F2
#define sw4 PORTD.F3
#define sw5 PORTD.F4
#define led1 PORTC.F0
#define led2 PORTC.F1
#define led3 PORTC.F2
#define led4 PORTC.F3
#define led5 PORTC.F4
int keypressed =0;
unsigned char key_char, received_char;
void voteCount();
int count=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';
//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';
//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';
// 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';
//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';
//UART1_Write_Text("switch 5 pressed!");
}
}
}
UART1_Write(key_char);
}
}
GLCD_Write_Text(" ", 3,0,1);
// If data is ready, read it:
if (UART1_Data_Ready() == 1) {
key_char = UART1_Read();
GLCD_Write_Text(" ", 3,0,1);
}
#define max_character 18 // length of barcode
/*************************SDCARD************************/
sbit Mmc_Chip_Select at RC0_bit;
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
/**************************glcd***************************/
char Glcd_DataPort at PORTD;
sbit Glcd_CS1 at RB5_bit; // GLCD chip select 1
sbit Glcd_CS2 at RB6_bit; // GLCD chip select 2
sbit Glcd_RS at RB2_bit; // GLCD data/instruction
sbit Glcd_RW at RB3_bit; // GLCD read/write
sbit Glcd_EN at RB4_bit; // GLCD enable
sbit Glcd_RST at RB7_bit; // GLCD reset
sbit Glcd_CS1_Direction at TRISB5_bit;
sbit Glcd_CS2_Direction at TRISB6_bit;
sbit Glcd_RS_Direction at TRISB2_bit;
sbit Glcd_RW_Direction at TRISB3_bit;
sbit Glcd_EN_Direction at TRISB4_bit;
sbit Glcd_RST_Direction at TRISB7_bit;
/*******************BARCODE****************************/
sbit PS2_Data at RA3_bit;
sbit PS2_Clock at RA4_bit;
sbit PS2_Data_Direction at TRISA3_bit;
sbit PS2_Clock_Direction at TRISA4_bit;
/*********************************************************/
void UART_Write_2DArray(char _2DArray[10][16], unsigned int _row, unsigned int _col);
unsigned short keydata = 0, special = 0, down = 0;
char fat_txt[20] = "FAT16 not found";
char filename[11] = "voter1.txt"; // File names
char character='l';
unsigned long size;
char Buffer[512];
char txt[] = "34101-9764655-9";
//char txt1[] = "34101-9764655-9";
char cnics[16];
char tmp2[16];
char cnics_array[10][16];
int res;
unsigned int count, row, col, _row, _col = 0;
unsigned char TwoDArray[10][16];
unsigned int j,i,k = 0;
unsigned int match_counter = 0, read_counter = 0;
int b_duplicate = 0;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
char repeat[10]={0,0,0,0,0,0,0,0,0,0};
int ctr=-1;
char ctrtxt[10];
int row1;
//unsigned char received_text[50];
unsigned char key_char;
int di;
///////////////////////////////////barcode scan///////////////////////////////
void Barcodescan()
{ memset(barcode, 0, max_character); // all character set to 0
if (Ps2_Key_Read(&keydata, &special, &down))
{
if (down && (keydata == 13))
{ // Enter
// Glcd_Fill(0);
//Glcd_Write_Text(barcode, 0, 0, 1);
memset(barcode, 0, max_character);
counter = 0;
// UART1_Write(text);
}
else if (down && (keydata == 16))
{
counter--;
barcode[counter] = 0;
// set previous charater to 0
}
else if (down && !special && keydata)
{ // other keys
barcode[counter++] = keydata;
}
}
}
///////////////////////////file read & compare//////////////////////////////////
void M_Open_File_Read()
{
Mmc_Fat_Assign(&filename, 0);
Mmc_Fat_Reset(&size);
row = 0;
j = 0;
do {
ctr++;
Mmc_Fat_Read(&character);
while(character!= ' ') {
cnics[count] = character;
count++;
Mmc_Fat_Read(&character);
}
if(character == ' ') {
while(character != '\n') {
Mmc_Fat_Read(&character);
}
}
cnics[count] = '\0';
UART1_Write_Text("cnics = ");
UART1_Write_Text(cnics);
UART1_Write(10);
UART1_Write(13);
i = 0;
col = 0;
for(i=0;i<count;i++) {
/*
if(cnics[i] == '\0')
{
cnics_array[row][col]='\0';
}
else {
*/ cnics_array[row][col]= cnics[i];
col++;
//}
}
count = 0;
//UART1_Write_Text("cnics array = ");
//UART_Write_2DArray(cnics_array, row, col);
UART1_Write(10);
UART1_Write(13);
for (k=0;k<15;k++) {
tmp2[k] = cnics_array[row][k];
}
//tmp2[15] = '\0';
//UART1_Write_Text("tmp2 = ");
//UART1_Write_Text(tmp2);
UART1_Write(10);
UART1_Write(13);
//UART1_Write_Text("txt = ");
//UART1_Write_Text(txt);
UART1_Write(10);
UART1_Write(13);
row++;
j++;
k = 0;
col = 0;
for(i=0;i<15;i++) {
if(txt[i] == tmp2[i]) {
match_counter++;
// repeat[i]=1;
}
}
i = 0;
/* UART1_Write_Text("ctr = ");
IntToStr(ctr, ctrtxt); // txt is " -4220" (one blank here)
UART1_Write_Text(ctrtxt);
*/
if(match_counter == 15 && repeat[ctr] ==0) {
repeat[ctr]=1;
UART1_Write_Text("txt[] matches with tmp2[]");
// UART1_Write_Text("repeat = ");
/*for(row1=0;row1<10;row1++)
{
IntToStr(repeat[row1], repeattxt);
UART1_Write_Text(repeattxt);
UART1_Write_Text(" ");
}*/
UART1_Write_Text(13);
GLCD_Write_Text(" ", 2, 3, 0);
Glcd_Write_Text("Welcome To Voting Machine", 3, 3, 0);
b_duplicate = 1;
UART1_Write('1');
break;
}
else
{
UART1_Write_Text("txt[] doesn't match with tmp2[]");
repeat[ctr]=0;
Glcd_Write_Text("Oops! can't cast vote", 3, 3, 0);
b_duplicate = 0;
UART1_Write('0');
}
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
match_counter = 0;
} while(row < 10);
}
///////////////////////////////////verification/////////////////////////////////
int VerifyDuplicateVoter()
{ M_Open_File_Read();
}
void UART_Write_2DArray(char _2DArray[][16], unsigned int _row, unsigned int _col) {
for(i=0;i<=_col;i++) {
TXREG = _2DArray[_row][i];
while(!PIR1.TXIF); //(while(!TXSTA.TRMT); TXSTA>TRMT = 0;
PIR1.TXIF = 0;
PIE1.TXIE = 1;
}
}
//-------------- Main. Uncomment the function(s) to test the desired operation(s)
void main() {
PORTB = 0x00;
TRISB = 0X00;
PORTA = 1;
TRISA = 1;
TRISD=0;
TRISC =0;
PORTC = 0x02;
TRISC.F6 = 0;
TRISC.F7 = 1;
PORTC = 0x02;
UART1_Init(9600);
Ps2_Config();
Glcd_Init();
Glcd_Fill(0xff);
Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);
Ps2_Config();
delay_ms(1000);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init ()==0)
{
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//M_Open_File_Read();
res = VerifyDuplicateVoter();
while(1) {
// If data is ready, read it:
if (UART1_Data_Ready() == 1) {
key_char = UART1_Read();
GLCD_Write_Text(" ", 3, 5, 1);
}
switch(key_char) {
case '1':
GLCD_Write_Text("Switch 1 Pressed", 3, 0, 1);
break;
case '2':
GLCD_Write_Text("Switch 2 Pressed", 3, 0, 1);
break;
case '3':
GLCD_Write_Text("Switch 3 Pressed", 3, 0, 1);
break;
case '4':
GLCD_Write_Text("Switch 4 Pressed", 3, 0, 1);
break;
case '5':
GLCD_Write_Text("Switch 5 Pressed", 3, 0, 1);
break;
default:
break;
};
}
}
else if (Mmc_Fat_Init()== 1)
{
UART1_Write('y');
}
else
{
UART1_Write('z');
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?