
The example shows the connection of a device from the dsPIC30F family to a standard PS/2 keyboard. It is important to note that all pins of the PS/2 keyboard connected to the dsPIC30F device are connected to the power supply by the pull-up resistors. The realization is carried out by using the mikroBasic compiler for dsPIC30F microcontrollers.
program ps2_test
dim
keydata, special, down as word
main:
ADPCFG=$FFFF
keydata = 0
special = 0
down = 0
Ps2_Config(PORTC, 14, 13)
Uart1_Init(9600)
Uart1_Write_Text("You can type now!") ' Ready
while TRUE
if Ps2_Key_Read(keydata, special, down) <> 0 then
if ((down<>0) and (keydata = 16)) <> 0 then
Uart1_Write_Char(0x08)
else
if ((down<>0) and (keydata = 13)) <> 0 then
' Enter
Uart1_Write_Char(13)
Uart1_Write_Char(10)
else
if ((down<>0) and (special=0) and (keydata<>0)) <> 0 then
Uart1_Write_Char(keydata)
end if
end if
end if
end if
Delay_ms(1) ' debounce
wend
end.