PDA

View Full Version : Small great problem



Darklakebridge7
- 7th December 2009, 15:15
Hi to everybody!
I would like to realize a device that converses with a PC through the door PS2, using a PIC 16F877A.

The device should send to the PC, the letter "r" if the key P1 is pressed on RD0, the letter "c" if the key P2 is pressed on RD1 and the letter "s" if the key P3 is pressed on RD2.

I have realized the following code, but it doesn't work... where is the error?

Thanks everybody!
Best regards!

@ DEVICE HS_OSC
@ DEVICE pic16F877A
DEFINE OSC 20
DEFINE SHIFT_PAUSEUS 15

INCLUDE "modedefs.bas"

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_LINES 2

symbol P1 = PORTD.2
SYMBOL P2 = PORTD.1
SYMBOL P3 = PORTD.0
symbol LED = PORTA.0
Symbol dat = PORTC.0
symbol clk = PORTC.1

i var byte
Value Var word
clear

ADCON1 = 7
dat = 1
clk = 1

lcdout $fe,1,"** Test PS2 **"
LCDOUT $fe,$c0,"Value: ",Value," "

FOR i = 0 TO 5
TOGGLE LED
PAUSE 200
NEXT i
GOTO Main

Main:
if P1 = 0 THEN
Dato = $73
lcdout $fe,$c0,"Key: ",Value," "
Pause 50
GOSUB TX
endif

if P2 = 0 then
Dato = $63
lcdout $fe,$c0,"Key: ",Value," "
Pause 50
GOSUB TX
endif

if P3 = 0 then
Dato = $72
lcdout $fe,$c0,"Key: ",Value," "
Pause 50
GOSUB TX
endif

goto Main

TX:
shiftout dat,clk,0,[Value\11]
pause 50
return

aratti
- 7th December 2009, 16:41
Variable Value is not loaded with the character that you load into byte Dato, if you want it to be displayed than either you print also variable Dato or as in the example below you transfer Dato into Value.

correct your ascii code for the letters c;r and s




'$63 = c
'$72 = r
'$73 = s

if P1 = 0 THEN
'Dato = $73 '
Dato = $72
Value=Dato
lcdout $fe,$c0,"Key: ",Value," "
Pause 50
GOSUB TX
endif


Al.

Darklakebridge7
- 8th December 2009, 10:09
Variable Value is not loaded with the character that you load into byte Dato, if you want it to be displayed than either you print also variable Dato or as in the example below you transfer Dato into Value.

correct your ascii code for the letters c;r and s




'$63 = c
'$72 = r
'$73 = s

if P1 = 0 THEN
'Dato = $73 '
Dato = $72
Value=Dato
lcdout $fe,$c0,"Key: ",Value," "
Pause 50
GOSUB TX
endif


Al.

Thanks Aratti! Thanks very much!
I have effected the changes from you signalled and in effects we are now all some right ... It's still me impossible to send the data on the PS/2. Is it possible that the error is in the command SHIFTOUT?

Thanks very very muche for your irreplaceable help!

aratti
- 8th December 2009, 14:00
.... Is it possible that the error is in the command SHIFTOUT?

I think you have spotted the problem. Read the thread @ the given link, it will help you in understanding the ps2 protocol.

http://www.picbasic.co.uk/forum/showthread.php?t=2736&highlight=communication

Al.

Darklakebridge7
- 8th December 2009, 16:19
I think you have spotted the problem. Read the thread @ the given link, it will help you in understanding the ps2 protocol.

http://www.picbasic.co.uk/forum/showthread.php?t=2736&highlight=communication

Al.

Thank you very much!