Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RS232 communication between two pic18f452

Status
Not open for further replies.
ok i got it about GLCD clearing. i wanted to use thermal printer in my project so that when GLCD displays any switch pressed then a slip is printed from thermal printer that vote casted for pressing particular switch.
 

I m interfacing the thermal printer by using max232 with a connecter D-25F. I m basically using soft_uart for thermal printer.

- - - Updated - - -

thermal printer number is CBM-1000

- - - Updated - - -

Is it possible that instead of using thermal printer I can use pc that is after the vote have been casted I can send data to pc and priter connected to pc can print it.

- - - Updated - - -

I need to know one thing more. I m using barcode scanner (LS5500) for scanning cnic of voters. my barcode interfacing with micro controller is PS/2 keyboard interfacing. I have done code for that but i m not sure that when a card is scanned from barcode did it return ascii or hex. because i wanted to compare the value from barcode with value from sdcard (i-e CNIC).
Code:
#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;


           }
        }

}
 

Yes, you can interface your board with PC using Software UART and get the print from Printer connected to PC. Can you post the datasheet of thermal printer? Check your barcode scanned data with ascii. If it doesn't match then check it with hex values.
 
Last edited:

it's the code and schematic of checking barcode values to be ascii or hex
Code:
#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();
}

barcode.png

- - - Updated - - -

it's the code and schematic of checking barcode values to be ascii or hex
Code:
#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();
}

barcode.png
 

my bar code scanner model number is ZQ-LS5500 and i have searched alot but doesn't get datasheet of barcode
 

i m getting problem in interfacing barcode on hardware because i have no datasheet of barcode and not finding it on internet.
 

i tried barcode. it gives hex values. now how can i convert hex into ascii so that i can compare it with values those in cnics_array
 

How did you check that barcode gives hex values. What string did you scan and what value did you get in barcode[]?
See this http://www.asciitable.com/

If you scanned something like "1-234567-890" and you got "1-234567-890" on uart then you don't have to do anything.
if you want to convet the values in barcode[] to string then terminate the barcode[] with '\0' and add decimal 48 or 0x30 to each element of the barcode[] array. Then print the barcode[] on UART. See what you get on the Virtual Terminal.
 

OK i will try it.
how can i do coding for sending data to pc using soft_uart. i have to do soft_uart just because i have used uart once now i can only use soft_uart.
 

I tried soft uart but it is not displaying anything on terminal
code:
Code:
#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(cnics); and Soft_UART_Write(txt); is wrong. You can only pass single character to the Soft_UART_Write() function. You are passing array and string to it. Which pins are you using for Soft_UART communication. Chane the TRISA value according to it. Post your project files and proteus .dsn file.

Use the below function to Write Text using Soft_UART.
Code:
 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]);

	}

}
 
Last edited:

my project file and my proteus stimulation
 

Attachments

  • pro.rar
    201.1 KB · Views: 56
  • proteus.rar
    14.1 KB · Views: 58

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top