📄 ps2code.lst
字号:
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;---------------------------------------------------------------------------------------------
00002 ; HEADER:
00003 ;---------------------------------------------------------------------------------------------
00004 TITLE "PS/2 Keyboard Emulator"
00005 SUBTITLE "Copyright 2001, Adam Chapweske"
00006 LIST P=16F877
00007 INCLUDE "p16f877.inc"
00001 LIST
00002 ; P16F877.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
00373 LIST
00008 RADIX DEC
00009 ERRORLEVEL -224, 1
2007 3FF9 00010 __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC
00011
00012 ;---------------------------------------------------------------------------------------------
00013
00014 #DEFINE DATA PORTA, 2 ;May be assigned to any I/O pin
00015 #DEFINE CLOCK PORTA, 3 ;May be assigned to any I/O pin
00016
00017 #DEFINE KEY PORTB, 0
00018
00019
00020 #DEFINE PERIOD 20 ;Time between reading of inputs. Min=(osc frequency)/204800
00021
00022 ;---------------------------------------------------------------------------------------------
00023 ; RAM ALLOCATION:
00024 ;---------------------------------------------------------------------------------------------
00025
00026 cblock 0x20
00027
00000020 00028 TEMP0 ,TEMP1
00000022 00029 RECEIVE, PARITY, COUNTER ;Used in I/O routines
00000025 00030 OLDKEYCODE,NEWKEYCODE
00031 endc
00032
00033
00034 ;---------------------------------------------------------------------------------------------
00035
00036 cblock 0x30 ;Contains to-be-sent packet and last packet sent
00000030 00037 LENGTH
00000031 00038 SEND1
00000032 00039 SEND2
00000033 00040 SEND3
00041 endc
00042
00043 ;---------------------------------------------------------------------------------------------
00044 ; MACROS:
00045 ;---------------------------------------------------------------------------------------------
00046
00047 ;Delay "Cycles" instruction cycles
00048 Delay macro Time
00049 if (Time==1)
00050 nop
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 2
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00051 exitm
00052 endif
00053 if (Time==2)
00054 goto $ + 1
00055 exitm
00056 endif
00057 if (Time==3)
00058 nop
00059 goto $ + 1
00060 exitm
00061 endif
00062 if (Time==4)
00063 goto $ + 1
00064 goto $ + 1
00065 exitm
00066 endif
00067 if (Time==5)
00068 goto $ + 1
00069 goto $ + 1
00070 nop
00071 exitm
00072 endif
00073 if (Time==6)
00074 goto $ + 1
00075 goto $ + 1
00076 goto $ + 1
00077 exitm
00078 endif
00079 if (Time==7)
00080 goto $ + 1
00081 goto $ + 1
00082 goto $ + 1
00083 nop
00084 exitm
00085 endif
00086 if (Time%4==0)
00087 movlw (Time-4)/4
00088 call Delay_us
00089 exitm
00090 endif
00091 if (Time%4==1)
00092 movlw (Time-5)/4
00093 call Delay_us
00094 nop
00095 exitm
00096 endif
00097 if (Time%4==2)
00098 movlw (Time-6)/4
00099 call Delay_us
00100 goto $ + 1
00101 exitm
00102 endif
00103 if (Time%4==3)
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 3
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00104 movlw (Time-7)/4
00105 call Delay_us
00106 goto $ + 1
00107 nop
00108 exitm
00109 endif
00110 endm
00111 ;---------------------------------------------------------------------------------------------
00112 ; ORG 0x000:
00113 ;---------------------------------------------------------------------------------------------
00114
0000 00115 org 0x000
0000 2823 00116 goto Start
00117 ;---------------------------------------------------------------------------------------------
00118 ; EMULATE BAT:
00119 ;---------------------------------------------------------------------------------------------
0001 01A0 00120 BATdelay clrf TEMP0 ;Used for a 400 ms delay at power-on
0002 01A1 00121 clrf TEMP1
00122 DelayLoop Delay 6
M if (6==1)
M nop
M exitm
M endif
M if (6==2)
M goto $ + 1
M exitm
M endif
M if (6==3)
M nop
M goto $ + 1
M exitm
M endif
M if (6==4)
M goto $ + 1
M goto $ + 1
M exitm
M endif
M if (6==5)
M goto $ + 1
M goto $ + 1
M nop
M exitm
M endif
M if (6==6)
0003 2804 M goto $ + 1
0004 2805 M goto $ + 1
0005 2806 M goto $ + 1
M exitm
0006 0BA0 00123 decfsz TEMP0, f
0007 2803 00124 goto DelayLoop
0008 0BA1 00125 decfsz TEMP1, f
0009 2803 00126 goto DelayLoop
000A 3400 00127 retlw 0x00
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 4
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00128
00129 ;---------------------------------------------------------------------------------------------
00130 ; HANDLE COMMAND:
00131 ;---------------------------------------------------------------------------------------------
00132
00133 if (high Table1End != 0)
00134 ERROR "Command handler table must be in low memory page"
00135 endif
00136
000B 30ED 00137 Command movlw 0xED ;0xE6 is lowest code
000C 0222 00138 subwf RECEIVE, w
000D 1C03 2838 00139 bnc MainLoop
000F 0782 00140 HandlerTable addwf PCL, f ;Add offset
0010 2838 00141 goto MainLoop ;0xED
0011 288E 00142 goto KeyBd_EE ;0xEE
0012 2838 00143 goto MainLoop ;0xEF
0013 2838 00144 goto MainLoop ;0xF0
0014 2838 00145 goto MainLoop ;0xF1
0015 2838 00146 goto MainLoop ;0xF2
0016 2838 00147 goto MainLoop ;0xF3
0017 2898 00148 goto KeyBd_F4 ;0xF4
0018 2838 00149 goto MainLoop ;0xF5
0019 2838 00150 goto MainLoop ;0xF6
001A 2838 00151 goto MainLoop ;0xF7
001B 2838 00152 goto MainLoop ;0xF8
001C 2838 00153 goto MainLoop ;0xF9
001D 2838 00154 goto MainLoop ;0xFA
001E 2838 00155 goto MainLoop ;0xFB
001F 2838 00156 goto MainLoop ;0xFC
0020 2838 00157 goto MainLoop ;0xFD
0021 2860 00158 goto PacketOut ;0xFE - Resend
0022 282D 00159 Table1End goto Reset ;0xFF - Reset
00160
00161
00162 ;---------------------------------------------------------------------------------------------
00163 ; START:
00164 ;---------------------------------------------------------------------------------------------
00165
0023 0185 00166 Start clrf PORTA
0024 0186 00167 clrf PORTB
0025 1683 00168 bsf STATUS, RP0 ;(TRISA=TRISB=0xFF by default)
00169
0026 3057 00170 movlw 0x57 ;Timer mode, assign max. prescaler, enable pullups
0027 0081 00171 movwf OPTION_REG
0028 3007 00172 movlw 0x07
0029 009F 00173 movwf ADCON1
002A 0187 00174 clrf PORTC
002B 1283 00175 bcf STATUS, RP0
002C 282D 00176 goto Reset
00177
00178 ;---------------------------------------------------------------------------------------------
00179 ; Reset Mode:
00180 ;---------------------------------------------------------------------------------------------
MPASM 03.20.02 Released PS2CODE.ASM 6-30-2004 14:27:07 PAGE 5
PS/2 Keyboard Emulator
Copyright 2001, Adam Chapweske
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
002D 0187 00181 Reset clrf PORTC
002E 3000 00182 movlw 0x00
002F 00A5 00183 movwf OLDKEYCODE
0030 00A6 00184 movwf NEWKEYCODE
0031 30AA 00185 movlw 0xAA
0032 00B1 00186 movwf SEND1 ;Load BAT completion code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -