vkey.asm
1 | ; *
| 2 | ; Filename: VirtualKeyboard.asm *
| 3 | ; Date: 26.12.2007 *
| 4 | ; File Version: 1.0 *
| 5 | ; *
| 6 | ; Author: Martin Matysiak *
| 7 | ; Contact: mail@k621.de *
| 8 | ; www.k621.de *
| 9 | ; *
| 10 | ;**********************************************************************
| 11 | ; *
| 12 | ; Pinbelegung: *
| 13 | ; PORT A *
| 14 | ; 0 <-- CLK IN *
| 15 | ; 1 <-- DATA IN *
| 16 | ; 2 --> CLK OUT *
| 17 | ; 3 --> DATA OUT *
| 18 | ; *
| 19 | ; PORT B *
| 20 | ; 0 --> LED (Status) *
| 21 | ; 1 --> LED (NumLock) *
| 22 | ; 2 --> LED (CapsLock) *
| 23 | ; 3 --> LED (ScrollLock) *
| 24 | ; *
| 25 | ;**********************************************************************
| 26 |
| 27 | list p=16f628A
| 28 | #include <p16F628A.inc>
| 29 |
| 30 | errorlevel -302
| 31 |
| 32 | __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT
| 33 |
| 34 |
| 35 | ;***** VARIABLEN DEFINITIONEN
| 36 | Loops1 equ 0x20
| 37 | Loops2 equ 0x21
| 38 | ScanCode equ 0x22
| 39 | BitPos equ 0x23
| 40 | PariTemp equ 0x24
| 41 | InputCode equ 0x25
| 42 | Loops3 equ 0x26
| 43 |
| 44 |
| 45 | ;***** PROGRAMM CODE::MAIN
| 46 | ORG 0x000
| 47 | goto main
| 48 |
| 49 |
| 50 | main
| 51 | bsf CMCON, CM0
| 52 | bsf CMCON, CM1
| 53 | bsf CMCON, CM2
| 54 |
| 55 | bsf STATUS, RP0
| 56 | bcf TRISA, 2
| 57 | bcf TRISA, 3
| 58 | clrf TRISB
| 59 | bcf STATUS, RP0
| 60 |
| 61 | ;** Virtuelle Tastatur initalisieren
| 62 | call InitKeyboard
| 63 |
| 64 | ;** Hauptschleife, die die Tasten "drueckt"
| 65 | mainLoop
| 66 |
| 67 | ;** Überprüfen, ob Input vom PC kommt
| 68 | btfss PORTA, 0
| 69 | call ReadCode
| 70 |
| 71 | bsf PORTB, 0
| 72 | ;** Taste 8 drücken
| 73 | movlw 0x3E
| 74 | movwf ScanCode
| 75 | call SendCode
| 76 |
| 77 | movlw D'100'
| 78 | movwf Loops1
| 79 | call SleepMS
| 80 |
| 81 | movlw 0xF0
| 82 | movwf ScanCode
| 83 | call SendCode
| 84 | movlw 0x3E
| 85 | movwf ScanCode
| 86 | call SendCode
| 87 | bcf PORTB, 0
| 88 |
| 89 | ;** 3 Sekunden warten
| 90 | movlw D'3'
| 91 | movwf Loops3
| 92 | call SleepS
| 93 |
| 94 | bsf PORTB, 0
| 95 | ;** Taste 9 drücken
| 96 | movlw 0x46
| 97 | movwf ScanCode
| 98 | call SendCode
| 99 |
| 100 | movlw D'100'
| 101 | movwf Loops1
| 102 | call SleepMS
| 103 |
| 104 | movlw 0xF0
| 105 | movwf ScanCode
| 106 | call SendCode
| 107 | movlw 0x46
| 108 | movwf ScanCode
| 109 | call SendCode
| 110 | bcf PORTB, 0
| 111 |
| 112 | ;** 3 Sekunden warten
| 113 | movlw D'3'
| 114 | movwf Loops3
| 115 | call SleepS
| 116 |
| 117 | bsf PORTB, 0
| 118 | ;** Taste 0 drücken
| 119 | movlw 0x45
| 120 | movwf ScanCode
| 121 | call SendCode
| 122 |
| 123 | movlw D'100'
| 124 | movwf Loops1
| 125 | call SleepMS
| 126 |
| 127 | movlw 0xF0
| 128 | movwf ScanCode
| 129 | call SendCode
| 130 | movlw 0x45
| 131 | movwf ScanCode
| 132 | call SendCode
| 133 | bcf PORTB, 0
| 134 |
| 135 | ;** 3 Sekunden warten
| 136 | movlw D'3'
| 137 | movwf Loops3
| 138 | call SleepS
| 139 |
| 140 | bsf PORTB, 0
| 141 | ;** Taste P drücken
| 142 | movlw 0x4D
| 143 | movwf ScanCode
| 144 | call SendCode
| 145 |
| 146 | movlw D'100'
| 147 | movwf Loops1
| 148 | call SleepMS
| 149 |
| 150 | movlw 0xF0
| 151 | movwf ScanCode
| 152 | call SendCode
| 153 | movlw 0x4D
| 154 | movwf ScanCode
| 155 | call SendCode
| 156 | bcf PORTB, 0
| 157 |
| 158 | ;** 10 Sekunden warten
| 159 | movlw D'10'
| 160 | movwf Loops3
| 161 | call SleepS
| 162 |
| 163 | goto mainLoop
| 164 |
| 165 | ;***** PROGRAMM CODE::TASTATUR INITALISIERUNG
| 166 | InitKeyboard
| 167 | ;** LEDs aufleuchten lassen
| 168 | movlw 0x0F
| 169 | movwf PORTB
| 170 |
| 171 | ;** 500 ms warten
| 172 | movlw D'250'
| 173 | call SleepMS
| 174 | movlw D'250'
| 175 | call SleepMS
| 176 |
| 177 | ;** Selbsttest bestanden, Ack. senden
| 178 | movlw 0xAA
| 179 | movwf ScanCode
| 180 | call SendCode
| 181 |
| 182 | ;** LEDs ausschalten
| 183 | clrf PORTB
| 184 | return
| 185 |
| 186 | ;***** PROGRAMM CODE::SENDE FUNKTIONEN
| 187 | SendCode
| 188 | ;** Parität des zu sendenden Bytes ermitteln
| 189 | movlw D'7'
| 190 | movwf Loops1
| 191 | movf ScanCode, W
| 192 | movwf PariTemp
| 193 | movf ScanCode, W
| 194 | ParityCheck
| 195 | rrf PariTemp, F
| 196 | xorwf PariTemp, W
| 197 | decfsz Loops1, F
| 198 | goto ParityCheck
| 199 | movwf PariTemp
| 200 |
| 201 | ;** Übeprüfen, ob Input von Tastatur kommt
| 202 | ;btfss PORTA, 0
| 203 | ;goto ReadCode
| 204 |
| 205 | ;** START-Bit senden
| 206 | bsf PORTA, 3
| 207 | call SendClock
| 208 |
| 209 | ;** DATEN-Bits Senden
| 210 | movlw D'0'
| 211 | movwf BitPos
| 212 | SendBits
| 213 | btfsc ScanCode, BitPos
| 214 | goto DataSetHigh
| 215 | goto DataSetLow
| 216 |
| 217 | DataSetHigh
| 218 | bcf PORTA, 3
| 219 | goto GoOn
| 220 |
| 221 | DataSetLow
| 222 | bsf PORTA, 3
| 223 |
| 224 | GoOn
| 225 | ;btfss PORTA, 0
| 226 | ;call ReadCode
| 227 | call SendClock
| 228 | incf BitPos, F
| 229 | movlw D'8'
| 230 | subwf BitPos, W
| 231 | btfss STATUS, Z
| 232 | goto SendBits
| 233 |
| 234 | ;** PARITY-Bit senden
| 235 | btfsc PariTemp, 0
| 236 | goto PariHigh
| 237 | goto PariLow
| 238 |
| 239 | PariHigh
| 240 | bcf PORTA, 3
| 241 | goto PariOn
| 242 |
| 243 | PariLow
| 244 | bsf PORTA, 3
| 245 |
| 246 | PariOn
| 247 | call SendClock
| 248 | ;** STOP-Bit senden
| 249 | bcf PORTA, 3
| 250 | call SendClock
| 251 | return
| 252 |
| 253 | SendClock
| 254 | movlw D'10'
| 255 | movwf Loops1
| 256 | call SleepUS
| 257 | bsf PORTA, 2
| 258 | movlw D'20'
| 259 | movwf Loops1
| 260 | call SleepUS
| 261 | bcf PORTA, 2
| 262 | movlw D'10'
| 263 | movwf Loops1
| 264 | call SleepUS
| 265 | return
| 266 |
| 267 |
| 268 | ;***** PROGRAMM CODE::EMPFANGS FUNKTIONEN
| 269 | ReadCode
| 270 | btfss PORTA, 0
| 271 | goto ReadCode
| 272 |
| 273 | movlw D'0'
| 274 | movwf BitPos
| 275 |
| 276 | BitLoop
| 277 | call GetClock
| 278 | btfss PORTA, 1
| 279 | goto InputLow
| 280 | goto InputHigh
| 281 |
| 282 | InputLow
| 283 | bcf InputCode, BitPos
| 284 | goto InputOn
| 285 |
| 286 | InputHigh
| 287 | bsf InputCode, BitPos
| 288 |
| 289 | InputOn
| 290 | movlw D'10'
| 291 | movwf Loops1
| 292 | call SleepUS
| 293 |
| 294 | incf BitPos, F
| 295 | movlw D'8'
| 296 | subwf BitPos, W
| 297 | btfss STATUS, Z
| 298 | goto BitLoop
| 299 |
| 300 | ;** Parity und Stop Bit "einlesen"
| 301 | call GetClock
| 302 | call GetClock
| 303 |
| 304 | ;** ACK-Bit senden
| 305 | bsf PORTA, 3
| 306 | call GetClock
| 307 | bcf PORTA, 3
| 308 |
| 309 | call InterpretInput
| 310 |
| 311 | return
| 312 |
| 313 | GetClock
| 314 | bsf PORTA, 2
| 315 |
| 316 | movlw D'15'
| 317 | movwf Loops1
| 318 | call SleepUS
| 319 |
| 320 | bcf PORTA, 2
| 321 |
| 322 | movlw D'5'
| 323 | movwf Loops1
| 324 | call SleepUS
| 325 | return
| 326 |
| 327 | ;***** PROGRAMM CODE::BEFEHLE INTERPRETIEREN
| 328 | InterpretInput
| 329 | movlw 0xEE
| 330 | subwf InputCode, W
| 331 | btfsc STATUS, Z
| 332 | goto InputIsEcho
| 333 |
| 334 | movlw 0xFF
| 335 | subwf InputCode, W
| 336 | btfsc STATUS, Z
| 337 | goto InputIsReset
| 338 |
| 339 | movlw 0xED
| 340 | subwf InputCode, W
| 341 | btfsc STATUS, Z
| 342 | goto InputIsLed
| 343 |
| 344 | movlw 0xF2
| 345 | subwf InputCode, W
| 346 | btfsc STATUS, Z
| 347 | goto InputIsGetID
| 348 |
| 349 | movlw 0xFA
| 350 | movwf ScanCode
| 351 | call SendCode
| 352 | return
| 353 |
| 354 | InputIsEcho
| 355 | movlw 0xEE
| 356 | movwf ScanCode
| 357 | call SendCode
| 358 | return
| 359 |
| 360 | InputIsReset
| 361 | movlw 0xFA
| 362 | movwf ScanCode
| 363 | call SendCode
| 364 |
| 365 | movlw 0x0F
| 366 | movwf PORTB
| 367 |
| 368 | movlw D'250'
| 369 | movwf Loops1
| 370 | call SleepMS
| 371 |
| 372 | clrf PORTB
| 373 |
| 374 | movlw 0xAA
| 375 | movwf ScanCode
| 376 | call SendCode
| 377 |
| 378 | return
| 379 |
| 380 | InputIsLed
| 381 | movlw 0xFA
| 382 | movwf ScanCode
| 383 | call SendCode
| 384 |
| 385 | call ReadCode
| 386 |
| 387 | btfss InputCode, 0
| 388 | goto ScrollOn
| 389 | goto ScrollOff
| 390 |
| 391 | ScrollOn
| 392 | bsf PORTB, 3
| 393 | goto NumCheck
| 394 |
| 395 | ScrollOff
| 396 | bcf PORTB, 3
| 397 |
| 398 | NumCheck
| 399 | btfss InputCode, 1
| 400 | goto NumOn
| 401 | goto NumOff
| 402 |
| 403 | NumOn
| 404 | bsf PORTB, 3
| 405 | goto CapsCheck
| 406 |
| 407 | NumOff
| 408 | bcf PORTB, 3
| 409 |
| 410 | CapsCheck
| 411 | btfss InputCode, 2
| 412 | goto CapsOn
| 413 | goto CapsOff
| 414 |
| 415 | CapsOn
| 416 | bsf PORTB, 2
| 417 | goto FinCheck
| 418 |
| 419 | CapsOff
| 420 | bcf PORTB, 2
| 421 |
| 422 | FinCheck
| 423 | movlw 0xFA
| 424 | movwf ScanCode
| 425 | call SendCode
| 426 | return
| 427 |
| 428 | InputIsGetID
| 429 | movlw 0xAB
| 430 | movwf ScanCode
| 431 | call SendCode
| 432 |
| 433 | movlw 0x83
| 434 | movwf ScanCode
| 435 | call SendCode
| 436 |
| 437 | return
| 438 |
| 439 | ;***** PROGRAMM CODE::SLEEP
| 440 | SleepMS
| 441 | movlw .110 ; Zeitkonstante für 1ms
| 442 | movwf Loops2
| 443 | WaitLoop
| 444 | nop
| 445 | nop
| 446 | nop
| 447 | nop
| 448 | nop
| 449 | decfsz Loops2, F ; 1 ms vorbei?
| 450 | goto WaitLoop ; nein, noch nicht
| 451 |
| 452 | decfsz Loops1, F ; 250 ms vorbei?
| 453 | goto SleepMS ; nein, noch nicht
| 454 | return ; das Warten hat ein Ende
| 455 |
| 456 | SleepUS
| 457 | nop
| 458 | decfsz Loops1, F
| 459 | goto SleepUS
| 460 | return
| 461 |
| 462 | SleepS
| 463 | movlw D'250'
| 464 | movwf Loops1
| 465 | call SleepMS
| 466 |
| 467 | movlw D'250'
| 468 | movwf Loops1
| 469 | call SleepMS
| 470 |
| 471 | movlw D'250'
| 472 | movwf Loops1
| 473 | call SleepMS
| 474 |
| 475 | movlw D'250'
| 476 | movwf Loops1
| 477 | call SleepMS
| 478 |
| 479 | decfsz Loops3, F
| 480 | goto SleepS
| 481 |
| 482 | return
| 483 |
| 484 | ;***** EEPROM STELLEN INITALISIEREN
| 485 |
| 486 | ORG 0x2100
| 487 | DE 0x00, 0x01, 0x02, 0x03
| 488 |
| 489 |
| 490 | END
|
|