program KeyTunes; const MAX_PERIOD = 250; var keydata, special, down : byte; procedure PlayNote(Num: Byte); begin Sound_Play(MAX_PERIOD - Num * 2, 150); end; begin OSCCON := OSCCON or $70; // 8 MHz internal oscillator. CMCON0 := $07; // Disable analog comparators (comment this for P18) INTCON := 0; // Disable all interrupts ANSEL := 0; // Disable A/D Sound_Init(PORTA, 5); // Init sound output on port, pin WPUA := $03; // Set up keyboard bus pins for weak pullups. Ps2_Init(PORTA, 0, 1); // Init PS/2 Keyboard port, clock and data Delay_ms(100); // Wait for keyboard to finish Sound_Play(MAX_PERIOD, 300); Sound_Play(110, 150); repeat if Ps2_Key_Read(keydata, special, down) = 1 then if down = 1 then PlayNote(keydata); Delay_ms(10); // debounce until FALSE; end.