Problem har uppstått vid användning av den knapp som sitter på LPC Demo Board. Har laddat in >PICkit 2 Lesson 6 - Switch Debounce< för att testa innan jag försöker skriva om det. men får inte någon respons när jag trycker in knappen. Endast en lysdiod lyser hela tiden.
I filen readme.txt kan man läsa:
Detta är gjort. Programmet funkar i MPLABSIM som det ska. Programmet ser utsom följer:MPLAB WARNING:
If these lessons are programmed from within MPLAB using
the PICkit 2 as a programmer, the Demo Board Switch (SW1)
will not work unless a change is made to the default
PICkit 2 Programmer Settings.
In the MPLAB IDE, after selecting PICkit 2 as the Programmer,
select "Programmer > Settings". In the Settings dialog,
Check the box marked '3-State on "Release from Reset"'
Kod: Markera allt
; *******************************************************************
; PICkit 2 Lesson 6 - Switch Debounce
;
; This shows one method to debounce switches.
; Samples the line every 1mS, and waits for 5 in a row before
; acting on the change of state.
;
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F690 requires the AC162061 header for debugging *
; *******************************************************************
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay ; Assign an address to label Delay1
Display ; define a variable to hold the diplay
LastStableState ; keep track of switch state (open-1; closed-0)
Counter
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
movlw 0xFF
movwf TRISA ; Make PortA all input
clrf TRISC ; Make PortC all output
bcf STATUS,RP0 ; address Register Page 2
bsf STATUS,RP1
movlw 0xF7 ; PortA3 pin is digital
movwf ANSEL
bcf STATUS,RP0 ; address Register Page 0
bcf STATUS,RP1
clrf Display
clrf PORTC
movlw 1
movwf LastStableState ; Assume the Switch is up.
clrf Counter
MainLoop:
btfsc LastStableState,0
goto LookingForUp
LookingForDown:
clrw ; assume it's not, so clear
btfss PORTA,3 ; wait for switch to go low
incf Counter,w ; if it's low, bump the counter
movwf Counter ; store either the 0 or incremented value
goto EndDebounce
LookingForUp:
clrw ; assume it's not, so clear
btfsc PORTA,3 ; wait for switch to go low
incf Counter,w
movwf Counter
EndDebounce:
movf Counter,w ; have we seen 10 in a row?
xorlw 5
btfss STATUS,Z
goto Delay1mS
comf LastStableState,f ; after 10 straight, reverse the direction
clrf Counter
btfss LastStableState,0 ; Was it a key-down press?
goto Delay1mS ; no: take no action
incf Display,f ; if it's the down direction,
movf Display,w ; take action on the switch
movwf PORTC ; (increment counter and put on display)
Delay1mS:
movlw .71 ; delay ~1000uS
movwf Delay
decfsz Delay,f ; this loop does 215 cycles
goto $-1
decfsz Delay,f ; This loop does 786 cycles
goto $-1
goto MainLoop
end