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 mikroPascal compiler for dsPIC30F microcontrollers.
program ps2_test; var keydata, special, down : word; txt: array[20] of char; begin nop; ADPCFG:=$FFFF; // PORTB to be digital on 30F4013 keydata := 0; special := 0; down := 0; Ps2_Config(PORTC, 14, 13); Uart1_Init(9600); txt := 'You can type now!'; Uart1_Write_Text(txt); // Ready while true do begin if Ps2_Key_Read(keydata, special, down)=1 then begin if (down<>0) and (keydata = 16) then begin Uart1_Write_Char(0x08); end else if (down<>0) and (keydata = 13) then begin // Enter Uart1_Write_Char(13); Uart1_Write_Char(10); end else if (down<>0) and (special=0) and (keydata<>0) then begin Uart1_Write_Char(keydata); end; end; Delay_ms(1); // debounce end; end.