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
#define max_character 18 // length of barcode
/*******************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;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
///////////////////////////////////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;
}
}
}
#define max_character 18 // length of barcode
/*******************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;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
unsigned short keydata = 0, special = 0, down = 0;
///////////////////////////////////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(barcode);
UART1_Write_Text(barcode);
}
else if (down && (keydata == 16))
{
counter--;
barcode[counter] = 0;
// set previous charater to 0
UART1_Write(barcode);
UART1_Write_Text(barcode);
}
else if (down && !special && keydata)
{ // other keys
barcode[counter++] = keydata;
UART1_Write(barcode);
UART1_Write_Text(barcode);
}
}
}
void main() {
Barcodescan();
}
#define max_character 18 // length of barcode
/*******************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;
int counter = 0; // counter of barcode characters
char barcode [max_character]; // barcode string
unsigned short keydata = 0, special = 0, down = 0;
///////////////////////////////////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(barcode);
UART1_Write_Text(barcode);
}
else if (down && (keydata == 16))
{
counter--;
barcode[counter] = 0;
// set previous charater to 0
UART1_Write(barcode);
UART1_Write_Text(barcode);
}
else if (down && !special && keydata)
{ // other keys
barcode[counter++] = keydata;
UART1_Write(barcode);
UART1_Write_Text(barcode);
}
}
}
void main() {
Barcodescan();
}
#define max_character 18 // length of barcode
/*************************SDCARD************************/
sbit Mmc_Chip_Select at RC0_bit;
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
/**************************lcd******************************/
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_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;
char byte_read, error;
///////////////////////////////////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);
Soft_UART_Write(cnics);
i = 0;
col = 0;
for(i=0;i<count;i++) {
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);
Soft_UART_Write(tmp2);
UART1_Write_Text("txt = ");
UART1_Write_Text(txt);
UART1_Write(10);
UART1_Write(13);
Soft_UART_Write(txt);
row++;
j++;
k = 0;
col = 0;
for(i=0;i<15;i++) {
if(txt[i] == tmp2[i]) {
match_counter++;
// repeat[i]=1;
}
}
i = 0;
if(match_counter == 15 && repeat[ctr] ==0) {
repeat[ctr]=1;
UART1_Write_Text("txt[] matches with tmp2[]");
UART1_Write_Text(13);
Soft_UART_Write("cnic matched");
Lcd_Cmd(_LCD_CLEAR);
lcd_out_cp("CNIC matched!!!");
b_duplicate = 1;
UART1_Write('1');
break;
delay_ms(10);
}
else
{
UART1_Write_Text("txt[] doesn't match with tmp2[]");
repeat[ctr]=0;
Soft_UART_Write("cnic not matched");
Lcd_Cmd(_LCD_CLEAR);
lcd_out_cp("CNIC not matched!!!");
b_duplicate = 0;
UART1_Write('0');
delay_ms(10);
}
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= 0x93;
// TRISC.F7 = 1;
PORTC = 0x02;
UART1_Init(9600);
error = Soft_UART_Init(&PORTA, 7, 6, 9600, 0); // Initialize Soft UART at 14400 bps
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Ps2_Config();
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();
}
else if (Mmc_Fat_Init()== 1)
{
UART1_Write('y');
}
else
{
UART1_Write('z');
}
}
Soft_UART_Write_Text(unsigned char text[]);
Soft_UART_Write_Text(unsigned char text[]) {
unsigned int str_len = 0;
unsigned int i = 0;
str_len = strlen(text);
for(i=0;i<str_len;i++) {
Soft_UART_Write(text[i]);
}
}
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?