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.

PIC18F45K20 with barcode reader

Status
Not open for further replies.

alvinthen

Member level 2
Joined
Apr 15, 2010
Messages
51
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,628
Hi,
I'm doing my final year project which part of it involved obtaining data from a barcode scanner to the PIC
It's a RS232 barcode scanner which i supposed it's necessary to use the UART of the PIC.
I've not studied anything on UART and the protocol of RS232. (planning to)

So, the question is,
Do I directly connect both the barcode scanner and PIC? (I heard about MAX232 but not sure what it is about)
Do I just read the data via the input ports like how it was done with normal input ports?

I'll be much appreciate if any help or information can be provided.
Thank you very much!

alvin
 

I have used a hand held barcode scanner with a PIC18F97J60 - the interface was serial RS232 as it was to be connected to an existing system with equiped with a MAX232 driver.
Interfaceing was simple, as the barcode was scanned a character stream was recieved via the USART and then sent using UDP datagrams over ethernet to a server.
It would be worth looking for a serial scanner with 3.3v interface. You could then connect it directly to the PIC.
 
hi

as you said, please study RS-232 protocol
whether it's rs-232 level or TTl level, it's better to understand the protocol first
check the data sheet of the scanner.
if the scanner is to be connected directly to the serial port of the PC, it's rs 232 level so you need to use the rs232 level convertor (ie max 232) at the PIC

ml
 
The barcode scanner is meant for the PC, so i supposed i'll need the max232
i'll read up the rs232 protocol now.
Thanks for the help, might come back for further assistance :)
 

you probably don't even need to understand RS232
if you are using a modern version of Visual Studio it comes with a serial component and you simply call methods to send and receive
 

you probably don't even need to understand RS232
if you are using a modern version of Visual Studio it comes with a serial component and you simply call methods to send and receive

hmm but i'm interfacing the barcode reader with PIC18, i didn't VS can be used to program PIC?
 

hi

visual studio is for PC side program, of course you won't be needing that if your device does not connect to PC ie. it is stand alone. :)
 
hmm but i'm interfacing the barcode reader with PIC18, i didn't VS can be used to program PIC?
what is the PIC18 doing? if all you need is to read barcodes into a PC you don't need the PIC18, just plug the barcode reader ino a PC COM port, either a hardware port (such as COM1:) or if you don't have a hardware COM port use a RS232 to USB converter such as
USB RS232 Cables
 

what is the PIC18 doing? if all you need is to read barcodes into a PC you don't need the PIC18, just plug the barcode reader ino a PC COM port, either a hardware port (such as COM1:) or if you don't have a hardware COM port use a RS232 to USB converter such as
USB RS232 Cables

i building something for portable barcode reader, the PIC is used to read and store the barcodes scanned and then transfer to PC for other purposes. It's either the PIC store the barcodes scanned into a memory card through SPI then the memory card is plugged into the PC, or through zigbee or other communications (I planned to go with the first option, then proceed with second option if time allows)
 

you can connect a serial barcode reader to a PIC UART either directly if you can get a 3.3V version or via a MAX232 chip if it is normal RS232.
You could then store the barcodes in an array in RAM
If there are too many to store in RAM you could use an FRAM, e.g.
FM33256 F-RAM Memory Product | Ramtron International

or a USB flash drive
**broken link removed**

you could then connect to a PC using a serial port, WiFI or USB
 
ok i get it, thanks alot! so now all i need to do is get familiar with UART?
what else do i need?
 

have a look at section 18 of the PIC18F45K20 data sheet
**broken link removed**

you will find plenty of example USART code on the internet

you need some means of checking the barcode is being read correctly - I would usualy do this by sending results to a PC over a serial line. The PIC18F45K20 only has one USART but you could use the Rx for the barcode reader and the Tx for PC so long as the baud rate etc is the same, very limited and one of the reasons why I now use PIC24s - they are far more powerful and flexible.
 
have a look at section 18 of the PIC18F45K20 data sheet
**broken link removed**

you will find plenty of example USART code on the internet

you need some means of checking the barcode is being read correctly - I would usualy do this by sending results to a PC over a serial line. The PIC18F45K20 only has one USART but you could use the Rx for the barcode reader and the Tx for PC so long as the baud rate etc is the same, very limited and one of the reasons why I now use PIC24s - they are far more powerful and flexible.

Hmmm, I do have a 16x2 LCD to be interfaced with the PIC, however I'm still studying how to do 4bit interfacing with the LCD.
Is there any header files available like keil's arm does? thanks again!
 

what is the LCD? I have some code for a PC1602-J in 4 bit mode but is was attached to a dsPIC30F3011
 

hmmm it's jhd162a lcd, if it's possible i would not want to reinvent the wheel if someone already done it.
 

take a look at this link on the jhd162a
https://www.edaboard.com/threads/31781/

looking at the code the controller seems similar to the PC1602-J devide I used.
I used the following source of information
**broken link removed**

he is my sample code for 4 bit mode of the PC1602-J on a dsPIC30F3011 - should give you some idea where to start
Code:
// LCD display ports etc
#define LCDdata LATE		// data port
#define LCDstatus LATDbits    	// control/status port
#define RS LATD0				// read/write bit in LCDstatus
#define E  LATD1   				// enable bit in LCDstatus

void lcd_delay() { DelayNmSec(2); }  // if LCD does not work make this longer

// Write a nibble to the LCD
void lcdNibble(int n)
{
  	LCDdata = ((n & 0x0f));			// send out lower Nibble
    LCDstatus.E=1;					// take clock E high 
	lcd_delay();
    LCDstatus.E=0;
	lcd_delay();
 }

// Write a Control Command to the LCD
// This is written as two nibbles
void lcdCmd(int c)
{
 	LCDstatus.RS=0;			        // Take RS pin low for command
	lcdNibble(c >>4);		        // Makeup Upper Nibble
	lcdNibble(c);			        // Makeup Lower Nibble
}

// write a data byte to LCD
int lcdPutchar(int d)
{
	LCDstatus.RS=1; 				// Take RS pin high for data
	lcdNibble(d >>4);     		    // Makeup Upper Nibble
	lcdNibble(d);		            // Makeup Lower Nibble
    return 1;
}

// Initialise the LCD in 4bit Mode
void lcdInit()
{
    TRISDbits.TRISD0=0;  	// set RS and E bits output
    TRISDbits.TRISD1=0;  	// set RS and E bits output
    TRISE &= 0xf0;          // set bits 0-3 output for data
 	LCDstatus.RS=0;			// Take RS pin low for command
	lcdNibble(0x3);		// This put the LCD into Soft Reset 
	lcdNibble(0x3);
	lcdNibble(0x3);
	lcdNibble(0x2);
	lcdCmd(0x28);			// 2 line, 4 bit mode 
    lcdCmd(0x6);			// increment cursor after each write
    lcdCmd(0x1);			// clear display
    lcdCmd(0x2);			// home
    lcdCmd(0xF);			// turn disply on
}

once you have the LCD working you can connect the barcode reader and check the data received by displaying it on the LCD
 
this really does help! Thanks a million!!
 

Hey, I failed to show something on the LCD. Should it be just calling lcdInit() in my main function?
And the cursor should start blinking am I right?
All I get on the LCD is just random characters and black squares showing up. The closest I get is the first line showed up but without any character on it.
Thanks in advance!
 

lcdInit() should initialise the device and then calls to lcdPutchar(int d) should display the characters.
as something is happening on the display check
1. the connections between the microprocessor and the LCD, e.g. I was using port E bits 0 to 3 for the 4 bit data, and port D bit 0 for RS and bit 1 for eanble
2. the timing - I have calls to lcd_delay(); between changing the enable line etc. If this is too low you will drive the device too fast and it display rubbish.
 

I tried setting the delay to 20ms, i'm using RB0 and RB1 for RS and EN, RA0 to RA3 for the data bits.
I'll try again with the delay tomorrow. Thanks alot again, you've been a big help to me :)
By the way, I'm using pic18f2220 right now, i've set OSC = INTIO2, the internal oscillator is 8MHz, do i need to set anything else? I'm using #pragma config OSC = INTIO2
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top