Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

using PIC to interface serial transmision

Status
Not open for further replies.

patroclus

New Member
I want to build an interface for standar PS/2 mouse, in order to make a converter to an old computer mouse interface.
I have detailed info about protocols, so I know how to translate one protocol into the other.

the problem is.. how ca I use a PIC or other device, to "listen" to serial data from Ps/2 mouse, process it, and send it to another serial data out, that goes into the old computer?? Both data channels have to be syncronized with a clock.
Data comunication clock is about 10-20Khz.

Thank you!
 
patroclus said:
I want to build an interface for standar PS/2 mouse, in order to make a converter to an old computer mouse interface.
I have detailed info about protocols, so I know how to translate one protocol into the other.

the problem is.. how ca I use a PIC or other device, to "listen" to serial data from Ps/2 mouse, process it, and send it to another serial data out, that goes into the old computer?? Both data channels have to be syncronized with a clock.
Data comunication clock is about 10-20Khz.

Only the PS2 side has to be syncronised (it's a syncronous serial protocol), the RS232 side is an asyncronous protocol.

By choosing a PIC with a hardware USART (like the 16F628) you can receive the PS2 data using software routines, then simply transfer it to the UART transmit register (where the hardware will do the rest).

The UK magazine EPE did a series about PS2 interfacing, you can download the software from their website.

However, quite a lot of mice were already designed to work with either PS2 or serial, they automatically detect which by the connections in the adaptor.
 
I don't want to interface PS2 with an RS-232. I want to connect PS2 mouse to a non-standar mouse protocol, designed for an old videoconsole system. This protocol has a clock signal, and all data sent to it, must be syncronized with this clock.
This is a summary
**broken link removed**

How can I read/store the data bits from PS2 in the PIC, in an efficient way, in order to process them, and then send them bit by bit trought an output pin??
thank you
 
patroclus said:
I don't want to interface PS2 with an RS-232. I want to connect PS2 mouse to a non-standar mouse protocol, designed for an old videoconsole system. This protocol has a clock signal, and all data sent to it, must be syncronized with this clock.
This is a summary
**broken link removed**

How can I read/store the data bits from PS2 in the PIC, in an efficient way, in order to process them, and then send them bit by bit trought an output pin??
thank you

In that case I would suggest you use a serial mouse, rather than a PS2 one - you can use the hardware UART to receive the data from the mouse, and output to the SNES in software. This way you won't miss anything from the mouse while you're outputing to the SNES.
 
Yes, that might be great idea, as I could use the hardware capabilities of PIC.
By the way... how can I output data correctly, bit by bit, to SNES?? loading a register with an 8bit value and then rotating it??
I never did these things with PICs.

also, where can I find info about rs-232 mouse protocol?? I can only find PS/2...

thanks.
 
patroclus said:
Yes, that might be great idea, as I could use the hardware capabilities of PIC.
By the way... how can I output data correctly, bit by bit, to SNES?? loading a register with an 8bit value and then rotating it??
I never did these things with PICs.

Check my PIC tutorials, the RS232 one should give you a good idea, but instead of including specific length start and stop bits, you simply rotate the bit to the output pin, then toggle the clock pin accordingly, then do the next bit and so on. It's actually VERY similar to programming a PIC!.

also, where can I find info about rs-232 mouse protocol?? I can only find PS/2...

It's just standard RS232 serial data, presumably the actual data is similar to that of a PS2 mouse?.

Do you mean you have to convert the data to something completely different in your program as well?.
 
I see your tutorial.
This can be done by any PIC I suppose. What is the difference if you use a USARt capable PIC?? What are the advantages?? A Max232 is always needed I suppose.

Do you mean you have to convert the data to something completely different in your program as well?.

Well, I need to convert data to another mouse protocol (SNES).
the problem about serial mouse protocol, is that I see no way of sending data to mouse (PS/2 mouse can accept lots of commands to set resolution, etc..).
Serial mouse seems to work all the time at 1200 bps... and I can't find such complete info as for the Ps/2 protocol.
 
patroclus said:
I see your tutorial.
This can be done by any PIC I suppose. What is the difference if you use a USARt capable PIC?? What are the advantages?? A Max232 is always needed I suppose.

A MAX232 is only needed if you need true RS232, that uses +/-12V signal levels. The advantage of a hardware UART is that it's far faster, and allows the processor to do other things - in your case the software could be sending one byte to the SNES, while the hardware UART is receiving the next byte from the mouse (without you even knowing it's happening!). When your software routine has finished sending the byte to the SNES it simply checks the UART flag to see if a byte has been received, if not it loops until one is!.

Do you mean you have to convert the data to something completely different in your program as well?.

Well, I need to convert data to another mouse protocol (SNES).
the problem about serial mouse protocol, is that I see no way of sending data to mouse (PS/2 mouse can accept lots of commands to set resolution, etc..).
Serial mouse seems to work all the time at 1200 bps... and I can't find such complete info as for the Ps/2 protocol.

Plug one into your serial port, run a comms program (hyperterminal 'may' do?, it depends if it's binary or not?) and move the mouse - read the data off the screen. It's nothing complicated, it can only send fairly small amounts of data - I may have it somewhere in a book at home?, I can remember doing DOS based mouse programming in Pascal years back!.
 
A PIC with UART capabilities (16F628, for example) is just what I need.

Could you tell me where I can find an easy sample of how to use the UART capabilities. I mean, there are different data types and speeds used for RS232. Can you select 7N1, 8N1, etc..? and also, does bit rate affect??

In your tutorial, you talk about 9600, but most rs232 mice use 1200.
Thank you very much, you're helping me a lot! :)
 
patroclus said:
A PIC with UART capabilities (16F628, for example) is just what I need.

Could you tell me where I can find an easy sample of how to use the UART capabilities. I mean, there are different data types and speeds used for RS232. Can you select 7N1, 8N1, etc..? and also, does bit rate affect??

It's all explained in the datasheet, it's simply a question of setting a register or two.

In your tutorial, you talk about 9600, but most rs232 mice use 1200.
Thank you very much, you're helping me a lot! :)

For the hardware UART you just need to alter the value in the SPBRG and BRGH registers - for the software version you would need to alter the bit timing of Start_Delay and Bit_Delay, again it's quite simple to do.
 
Ok, I understand now.
But according to datasheet, it can only be set as 8 or 9 databits. What if I need to recieve 7 databits?? could this be done? If only 7 bits for data are sent, the following bit would be stop bit, but PIC would be waiting for 1 or 2 more bits... am I messing something around??

**broken link removed**
according to this web, microsoft mouse sends 7 databits + 1 stop bit...

thank you
 
patroclus said:
Ok, I understand now.
But according to datasheet, it can only be set as 8 or 9 databits. What if I need to recieve 7 databits?? could this be done? If only 7 bits for data are sent, the following bit would be stop bit, but PIC would be waiting for 1 or 2 more bits... am I messing something around??

**broken link removed**
according to this web, microsoft mouse sends 7 databits + 1 stop bit...

The UART is only really 8 bit, the 9th 'bit' is an optional parity bit, and is rarely used in this day and age.

As far as I'm aware, you can't set the UART for 7 bits?, personally I'd set it for 8 bits and see what happens :lol: it depends on how fast the bytes from the mouse follow each other!.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top