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.

PS/2 Barcode Scanner with PIC18F2220

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 trying to interface a PS/2 barcode scanner (CS-600 from Code-Soft) with PIC18F2220.
I've several doubts needed to be cleared.

I've tried supplying 5v directly from power supply to the PS/2 port and observe the signal at the data and clock lines using an oscilloscope. Then I tried to scan several barcodes, the data and clock are held high, no signal coming out. I've tried using the barcode scanner with PC and it worked without any problem. Do I need any initialization before I use the barcode scanner?

I've read Adam Chapweske's article on PS/2 article, he did mention initialization for PS/2 keyboard, but does it apply to barcode scanner as well?

I'm using C-18 compiler as my development tools. Are there any available library ready to be used? I knew that mikroC has a library for PS/2, does C-18 have its own?

Thank you very much!

Alvin
 

I connected a PS/2 barcode scanner to the AT keyboard input of a MikroElekronika EasydsPIC 2
the processor was a dsPIC30F3011 - code is below - it may give you some ideas
to make life simpler in the end we switched to using a RS232 serial barcode scanner
Code:
// define the clock and data bits
#define AT_CLK PORTCbits.RC14					// clock on RC14
#define AT_CLK_ENABLE  TRISCbits.TRISC14
#define AT_DATA PORTCbits.RC13					// data on RC13
#define AT_DATA_ENABLE  TRISCbits.TRISC13

// initialise the AT keyboard clock and data bits for input
void ATkbdInitialise(void)
{
   AT_CLK_ENABLE=1;				// enable keyboard CLK input
   AT_DATA_ENABLE=1;			// enable keyboard DATA input 
}

// decode the CLK and DATA lines into an integer - polled version
static int ATkbdRead(int debug)
{
    int i=0, scanCode=0;;
    char data[20]={0};
	while(AT_DATA);				// wait for start bit - high to low transition
    while(AT_CLK);				// wait for clock high to low transition
	//printf("START BIT");
    // read 8 bits of data + parity + stop bit
    for(i=0; i< 10; i++)
      {
       while(!AT_CLK);				// wait for clock low to high
       while(AT_CLK);				// wait for clock high to low
	   data[i]=AT_DATA+'0';			// read the next data bit
      }
    if(debug)printf("%s ", data);
    // convert the pattern into an 8 bit scan code
    for(i=7; i>=0; i--)
      {
       scanCode=(scanCode<<1) | (data[i]-'0');
      }
    if(debug)printf("scan code %x ", scanCode);
    return scanCode;
}
 
I was doing RS232 barcode scanner at first, but half way through my supervisor asked me switch to PS/2 and leave the RS232 for PIC to PC communication.
Anyways, are there any necessary initialization like LCD? Do I need to initialize it before it can start transmitting signals? Because from what I saw from the oscilloscope, the DATA and CLOCK lines are held high, showing 5V all the while since power-on and when barcodes are scanned.
Thanks!
 

it is several years since I did this code but it appears to need no initialisation apart from the PIC IO pins being set to digital input.
looking at the ATkbdRead() function it appears to
1. wait for a Start bit
2. wait for clock
3. then reads 10 data bits
4. then converts the scan code

what I did with PIC18s with one USART I used the Rx for the RS232 barcode input and the Tx to send data to the PC (we did not need the PC to talk to the PIC). One reason why I use PIC24s these days they are more flexible.
 

Hmmm, I guess I might as well test it on the PIC, but the thing that bother me most is the result from the oscilloscope.
Anyways, there's only PIC16 and 18 in my college.
 

I was doing RS232 barcode scanner at first, but half way through my supervisor asked me switch to PS/2 and leave the RS232 for PIC to PC communication.
Anyways, are there any necessary initialization like LCD? Do I need to initialize it before it can start transmitting signals? Because from what I saw from the oscilloscope, the DATA and CLOCK lines are held high, showing 5V all the while since power-on and when barcodes are scanned.
Thanks!
it is strange that the Data and Clock are 5volts when the barcode is scanned. check
1. with an AT keyboard
2. you don't have the digital IO lines as outputs and are driving them to 5volts

I have found the source of the PS/2 material I used when writing the code
Index of /microchip/projects/keyboard/v1xx

in particular
Simple AT Keyboard Interface V1.04 for Microchip PIC16F84 Microcontroller

and there is a circuit for a PIC16
https://electronic-engineering.ch/microchip/projects/keyboard/v1xx/Keyboard_V1xx.pdf
 

Well, the thing is I didn't even connect the barcode scanner to the PIC, I was merely supplying 5V to the barcode scanner from the project board and probe the clock and data line. Is that the right thing to do?
I'll go ahead trying with the keyboard now, thanks for the advice!
 

until you scan a barcode the DATA and CLOCK lines will be at idle
scan a barcode or press a key on the keyboard should show data
 

Gosh, I just found out I was doing something dumb, the cable supplied with barcode scanner contains one male and one female PS/2 port, and I thought both of them are connected internally so I probe the female sides which is totally not connected. -.-
I'll proceed with coding now, thank you very much!
 

may i get the schematic of your project about PS/2 barcode scanner with PIC18F2220??? ;-)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top