Jag har testat med andra program som funkar i samma koppling.
Kod: Markera allt
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
Cblock 0x0C ;Beginning of RAM
HIcnt
LOcnt
LOOPcnt
direction
ledpos
endc ;No variables
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
goto main
#include "pause.inc"
main
banksel TRISB ;Select the bank containing TRISB
clrf TRISB ;Port B is output
banksel PORTB ;Select the bank containing PORTB
banksel TRISA
bsf TRISA,3
banksel PORTA
clrf direction
movlw B'00000001'
movwf ledpos
Loop
goto nobutton
btfsc PORTA,3 ;Check if pin 3 on port A is clear (0)
goto nobutton ;if bit = 1, then no button was pressed
incf direction,1 ;Increse direction-variable.
movlw B'00000001'
andwf direction,0 ;Mask bits, store result in w-reg.
movwf direction ;store new value in direction-variable
nobutton
movf direction,1 ;Check if direction = 0
btfsc STATUS,Z ;Check zeroflag in STATUS-register.
goto down ;if zeroflag is set, goto down
movf ledpos,0 ;Get ledpos into w-reg
movwf PORTB
pausems .50 ;500ms
rlf ledpos,1 ;Rotate bits left, store in ledpos.
movfw ledpos
addlw 0
btfss STATUS,Z
goto Loop ;Jump to label Loop
movlw B'00000001'
movwf ledpos
goto Loop
down
movf ledpos,0 ;Get ledpos into w-reg
movwf PORTB
pausems .50 ;500ms
rrf ledpos,1 ;Rotate bits right, store in ledpos.
btfss STATUS,Z
goto Loop
movlw B'01000000'
movwf ledpos
goto Loop
END ; directive 'end of program'