請大家幫我看一下,這程式那裡錯了
|
||||
---|---|---|---|---|
新會員
|
這是一個用pic16f84去模擬鍵盤傳送按鍵值的程式(空白鍵連點)
我本來不想寫的,可是我朋友一直拿鍵盤來叫我幫他改空白鍵連點 (他們在玩奇蹟online遊戲一個報一個,改到我都快手軟了) 逼不得已才想說用這個變通的方法試看看 我是照一個老美的程式下去改的,組譯ok可是run不起來 原始網頁在這 http://panda.cs.ndsu.nodak.edu/%7Each ... icro/code/ps2/Device.html ;---------------------------------------------------------------------;------------------------ ; HEADER: ;--------------------------------------------------------------------------------------------- TITLE "KEYBOARD PLUG" SUBTITLE "By paul tseng" LIST P=16F84A INCLUDE "p16f84A.inc" RADIX DEC ERRORLEVEL -224, 1 __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC ;--------------------------------------------------------------------------------------------- ; DEFINES: ;--------------------------------------------------------------------------------------------- #DEFINE DATA PORTB, 3 #DEFINE CLOCK PORTB, 2 #DEFINE KEY PORTB, 1 #DEFINE LED PORTB, 0 ;--------------------------------------------------------------------------------------------- ; RAM ALLOCATION: ;--------------------------------------------------------------------------------------------- cblock 0x0c TEMP0 RECEIVE PARITY COUNTER endc org 0x000 goto START ;-------------------------------------------------------------------------------- ;Required Routines & Macros: ;--------------------------------------------------------------------------------------------- ; MACROS: ;--------------------------------------------------------------------------------------------- delay macro Time ;Delay "Cycles" instruction cycles if (Time==1) nop exitm endif if (Time==2) goto $ + 1 exitm endif if (Time==3) nop goto $ + 1 exitm endif if (Time==4) goto $ + 1 goto $ + 1 exitm endif if (Time==5) goto $ + 1 goto $ + 1 nop exitm endif if (Time==6) goto $ + 1 goto $ + 1 goto $ + 1 exitm endif if (Time==7) goto $ + 1 goto $ + 1 goto $ + 1 nop exitm endif if (Time%4==0) movlw (Time-4)/4 call Delay_Routine exitm endif if (Time%4==1) movlw (Time-5)/4 call Delay_Routine nop exitm endif if (Time%4==2) movlw (Time-6)/4 call Delay_Routine goto $ + 1 exitm endif if (Time%4==3) movlw (Time-7)/4 call Delay_Routine goto $ + 1 nop exitm endif endm ;--------------------------------------------------------------------------------------------- ; DELAY: ;--------------------------------------------------------------------------------------------- ;Delays 4w+4 cycles (including call,return, and movlw) (0=256) Delay_Routine addlw -1 ;Precise delays used in I/O btfss STATUS, Z goto Delay_Routine return ;--------------------------------------------------------------------------------------------- ; START: ;--------------------------------------------------------------------------------------------- START bcf STATUS,RP0 clrf PORTB bsf STATUS,RP0 movlw 0xF2 ;定義I/O movwf TRISB bsf LED ;flash LED delay 300 bcf LED goto CHECK_KEY CHECK_KEY btfsc KEY goto CHECK_KEY delay 100 goto SINGAL_OUT SINGAL_OUT delay 1000 ;delay 1 sec movlw 0x29 ;空白鍵scan code call BYTEOUT delay 100 ;delay 100 u sec movlw 0xF0 ;空白鍵brake code call BYTEOUT movlw 0x29 ;空白鍵brake code call BYTEOUT goto LIGHT_ON LIGHT_ON bsf LED delay 200 bcf LED goto STOP_SEND STOP_SEND btfsc KEY goto SINGAL_OUT delay 100 goto CHECK_KEY ;-------------------------------------------------------------------------------- ;ByteOut: ;Sends a byte in w to the host. Returns 0xFE if inhibited during transmission. ;Returns 0xFF if host interrupts to send its own data. ;Returns 0x00 if byte sent successfully. ;--------------------------------------------------------------------------------------------- ; OUTPUT ONE BYTE: - TIMING IS CRITICAL!!! ;--------------------------------------------------------------------------------------------- BYTEOUT movwf TEMP0 InhibitLoop btfss CLOCK ;Test for inhibit goto InhibitLoop delay 50 btfss CLOCK goto InhibitLoop btfss DATA ;Check for request-to-send retlw 0xFF clrf PARITY movlw 0x08 movwf COUNTER movlw 0x00 call BitOut ;Start bit (0) btfss CLOCK ;Test for inhibit goto ByteOutEnd delay 4 ByteOutLoop movf TEMP0, w xorwf PARITY, f call BitOut ;Data bits btfss CLOCK ;Test for inhibit goto ByteOutEnd rrf TEMP0, f decfsz COUNTER, f goto ByteOutLoop delay 2 comf PARITY, w call BitOut ;Parity bit btfss CLOCK ;Test for inhibit goto ByteOutEnd delay 5 movlw 0xFF call BitOut ;Stop bit (1) delay 48 retlw 0x00 ByteOutEnd bsf STATUS, RP0 bsf DATA bsf CLOCK bcf STATUS, RP0 retlw 0xFE BitOut bsf STATUS, RP0 andlw 0x01 btfss STATUS, Z bsf DATA btfsc STATUS, Z bcf DATA delay 21 bcf CLOCK delay 45 bsf CLOCK bcf STATUS, RP0 delay 5 return end
發表於: 2005/1/4 17:44
|
|||
|