'///////////////////////////////////////// ' pckeyb2.bas ' ' - Processor Atmel AT 89C52 ' - Implementation of the PC keyboard ' - Listing of scan codes to serial port ' - Crystal is 11.059 MHz, ' J. Nahtigal, ver 1.2 3/2000 '//////////////////////////////////////// 'directives $crystal = 11059000 $baud = 9600 'labels Clockline Alias P3.3 Dataline Alias P3.6 'global variables Dim Breakcode_flag As Byte Dim Key_code As Byte Dim Key_pressed_flag As Byte , A As Byte '..... start of the main program ....... On Int1 Ext_interrupt1 Enable Int1 Enable Interrupts 'control listing Print " pckeyb2 " 'program main loop Key_pressed_flag = 0 Breakcode_flag = 0 Do ' 'user program storage ' ' Loop '..... end of main program ......... '....................................... Ext_interrupt1: Disable Int1 'bit1 is start bit Call Wait_for_high 'read databits from 0 to 7 For A = 1 To 8 Call Wait_for_low $obj A2b6 'mov c,dataline Rotate Key_code , Right Call Wait_for_high Next 'read Parity bit Call Wait_for_low Call Wait_for_high 'read Stop bit Call Wait_for_low Call Wait_for_high 'verify Key_code and Breakcode_flag 'if Key_code equals E0h = 224 If Key_code = 224 Then Goto Exit_routine_ext1 End If If Breakcode_flag = 1 Then Breakcode_flag = 0 Goto Exit_routine_ext1 End If 'if Key_code equals F0h = 240 If Key_code = 240 Then Breakcode_flag = 1 Goto Exit_routine_ext1 End If 'Key_code = OK 'mark the flag, new key pressed 'and display key_code to serial port Key_pressed_flag = 1 Printhex Key_code Exit_routine_ext1: Enable Int1 Return '....................................... Sub Wait_for_high Bitwait Clockline , Set End Sub Sub Wait_for_low Bitwait Clockline , Reset End Sub '.......................................