Vad är fel? *löst*

PIC, AVR, Arduino, Raspberry Pi, Basic Stamp, PLC mm.
ROLA
Inlägg: 41
Blev medlem: 6 augusti 2004, 10:05:53

Vad är fel? *löst*

Inlägg av ROLA »

Koden funkar i debuggern, men inte i PIC:en.

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'
Senast redigerad av ROLA 11 april 2005, 08:25:30, redigerad totalt 1 gång.
ROLA
Inlägg: 41
Blev medlem: 6 augusti 2004, 10:05:53

Inlägg av ROLA »

Ja, det är inte perfekt kod.
Jag har precis börjar knåpa asm för PIC:en.
Det finns en del onödiga rader..

Som sagt. Det funkar i debuggern, men inte i "verkligheten".

Kollen för att kolla om "knappen" är nertryckt är inte skyddad mot "studs", men dioderna borde rimligen åt det ena hållet iaf.
Användarvisningsbild
Hedis
Inlägg: 2493
Blev medlem: 8 december 2003, 15:10:44
Ort: Vänersborg
Kontakt:

Inlägg av Hedis »

Hur har du gjort med MCLR benet? har för mig det skall till Vcc (+5v) med typ 1kohm i serie.
jonkers
Inlägg: 37
Blev medlem: 16 oktober 2004, 15:04:52

Inlägg av jonkers »

Har tyvärr inget svar på din fråga men blev hemskt nyfiken på raden:

#include "pause.inc"

skulle inte du kunna pm:a mig koden i den filen då det verkar vara sjukt användbara grejjer.

det vore :tumupp:
ROLA
Inlägg: 41
Blev medlem: 6 augusti 2004, 10:05:53

Inlägg av ROLA »

MCLR-benet är kopplat via 10kOhm till 5V, precis som vanligt.
Samma koppling fungerar med andra program.

timer.inc är hämtad från http://www.mikroelektronika.co.yu/engli ... 0_Uvod.htm
ROLA
Inlägg: 41
Blev medlem: 6 augusti 2004, 10:05:53

Inlägg av ROLA »

Hehe, PIC:en hade gått sönder. Gick kalas med en ny.
Skriv svar