CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Reading in an RS232 barcode scanner

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Simnix



Joined: 18 Oct 2006
Posts: 7

View user's profile Send private message

Reading in an RS232 barcode scanner
PostPosted: Sun Jan 07, 2007 8:17 am     Reply with quote

Hi

I am trying to read in data coming from a barcode scanner and display the result on an 2x16 LCD, when I activate the scanner nothing happens, but, when I connect the barcode scanner to my PC and use "Hyper Turminal" it works OK.

Where am I going wrong?

The code is as follows
Code:
//////////////////////////////////////////////////////////////////////////
///  @file BarcodeScanner.C
///  Author: Simon Nixon
///  IDE: MPLAB
///  Compiler: CCS
///  Test Harness: Barcode_scanner
///
///  Description:
///  This is the main file that will read a string from a barcode
///  scanner and display it on a 2x16 LCD screen.
//////////////////////////////////////////////////////////////////////////
#include <18F458.h>
#use delay(clock=8000000)

#FUSES NOWDT                     //No Watch Dog Timer
#FUSES WDT128                    //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                        //High speed Osc (> 4mhz)
#FUSES NOPROTECT                 //Code not protected from reading
#FUSES NOOSCSEN                  //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT                //No brownout reset
#FUSES BORV20                    //Brownout reset at 2.0V
#FUSES PUT                       //Power Up Timer
#FUSES NOCPD                     //No EE protection
#FUSES NOSTVREN                  //Stack full/underflow will not cause reset
#FUSES NODEBUG                   //No Debug mode for ICD
#FUSES NOLVP                     //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                     //Program memory not write protected
#FUSES NOWRTD                    //Data EEPROM not write protected
#FUSES NOWRTB                    //Boot block not write protected
#FUSES NOCPB                     //No Boot Block code protection
#FUSES NOWRTC                    //configuration not registers write protected
#FUSES NOEBTR                    //Memory not protected from table reads
#FUSES NOEBTRB                   //Boot block not protected from table reads

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include <lcd.c>
#include <stdio.h>

////////////////////////////////////////////
// declare global variables
////////////////////////////////////////////
char Barcode[17];
char Buffer[17];


void main()
{
    ////////////////////////////////////////////
    // initialise hardware
    ////////////////////////////////////////////
    lcd_init();

    ////////////////////////////////////////////
    // create local variables
    ////////////////////////////////////////////


    ////////////////////////////////////////////
    // initialise local variables
    ////////////////////////////////////////////


    // mainloop
    while(true)
    {
        sprintf(Buffer, "Ready...");
        printf(lcd_putc, Buffer);

        gets(Barcode);
        printf(lcd_putc, Barcode);
    }
}


Please can anybody help me with this project?
Ttelmah
Guest







PostPosted: Sun Jan 07, 2007 9:55 am     Reply with quote

Have you got a MAX232 or equivalent inverter/level translator present. Remember the PIC is 5v serial, inverted from what is coming out of the PC.
Second comment, what is the output format of the scanner?. Are you sure that the 'lines' are never more than 16 characters in length, and is terminated with a CR?. Hyperterminal, won't mind if the strings are longer.
Personally, I'd include 'input.c', in the code, and use 'get_string', rather than 'gets', with a maximum of 16. This is always safer.

Best Wishes
Simnix



Joined: 18 Oct 2006
Posts: 7

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 10:20 am     Reply with quote

I am using the millennium board at the moment, C6 & C7 (xmit & rcv) are connected to TX1 & RX1 respectfully, so the voltage levels are handled by the on-board max232.

The scanner is a Touch65 Pro with a RS232 connector and the scanner terminates with CR. I think barcode are in general 11 characters long.

No I haven't used input.c, I will give it a try, you see I am new to PIC programming and have never dealt with serial before, so this is going to be a steep hill for me to clime. Sad

Regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group