Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f84a assembly debugging

Status
Not open for further replies.

ProFPGA

Banned
I am trying to capture the current value of portb , but somehow w-reg retains a different value .

please see the attachment.
 

Attachments

  • simu.jpg
    simu.jpg
    144.6 KB · Views: 224
  • simu1.jpg
    simu1.jpg
    148.8 KB · Views: 195
Hi,

The debugger is right - your code is wrong.

You have defined Portb as 06 , its seeing that, 'Portb' as a variable, not what I assume you mean as the system register PORTB, so when you load it, movlw Portb, it does just that, moves Portb contents of 06 or 00000110 to the W reg.

If you look at the 16F84A.inc file found in Mplabs Asmsuite directory you will see all the system registers, as long as you "include" this file in your code there is no need to define any of these registers unless you specifically need to change any - which are nornally olny the Config registers.

hth
 
It's nothing to do with the equates. He just needs to change movlw portb to movfw portb.

Mike.
 
hi , i tried it with the inc file , still the same result :-(

even inside the inc file it is still an equ .

like

PORTA EQU H'0005'
PORTB EQU H'0006'

????
 
hi there ,

here's the whole code listing :

#include P16F84A.inc
cpostn equ 10
nsn equ B'00000000' ; no sun shine
pos equ B'00100000' ; facing sun
lft equ B'01000000' ; sun on left
rht equ B'00010000' ; sun on right
pp equ B'00000001'
;Portb equ 06
;Porta equ 05
;trisa equ 05
;trisb equ 06
;status equ 03
delcntr1 equ 11
org 00
;--------initialization process------------------------------
start bsf STATUS, 5 ; select bank 1
movlw B'11110000' ; bits 7,6,5 & 4 as inputs
movwf TRISB
movlw 00
movwf TRISA ; all o/ps
movlw 00
movwf cpostn ; reseting
bcf STATUS, 5 ;select bank0
;----------- Main Routine -----------------------------------
align movlw PORTB
movwf cpostn
btfsc cpostn ,pos
goto stay ; its the right position
btfsc cpostn ,lft ; check the for left turn
goto mvlft ; sub-routine to move left
btfsc cpostn ,rht
goto mvrht
btfsc cpostn ,nsn
goto park
goto align

;------------------------------------------------
;Move left sub-routine
;
mvlft nop
agaan movlw B'10000'; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
movlw cpostn
btfsc cpostn ,lft ; compare current position
goto agaan
return
; -----------End of subroutine-------------------
;
;
;------------------------------------------------
;Move right sub-routine
;
mvrht nop
again movlw B'01000'; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
movlw cpostn
btfsc cpostn ,rht
goto again
return
; -----------End of subroutine-----
;------------------------------------------------
;just stay here
;
stay nop
; Charging and power managment sub-routine will be added in future
; here we sense main grid supply
; if present = continue charging, jump to CHARGING subroutine
; else = check charge level of batteries
; if charge level = ok
; switch over ( DC-to-AC converstion )
; else = indicate charge level down
; return from sr
nop
goto align
; -----------End of subroutine-----
;
;Parking towards Next morning sun , facing towards left
;
park nop
adjt movlw B'10000' ; start motor
movwf PORTA
call delay ; time delay subroutine
movlw B'00000'
movwf PORTA ; stop motor
movlw PORTB ; refresh position
btfsc cpostn ,nsn
goto adjt
return
; -----------End of subroutine-----
;
;---------Delay subroutine----------
;
;
;Introduces delay of 1ms approx, for 1 MHz clock
delay movlw D'200' ;200 cycles called,
movwf delcntr1
del1 nop ;5 inst cycles in this loop
nop
decfsz delcntr1,1
goto del1
return

;-----------------------------------
end
 
As I said in the fourth post of this thread, you need to use movfw instead of movlw.

Code:
align		movlw	PORTB   [COLOR="Red"]<<--- change this[/COLOR]
		movwf	cpostn
		btfsc	cpostn ,pos
		goto	stay		; its the right position 
		btfsc	cpostn,lft	; check the for left turn
		goto	mvlft		; sub-routine to move left
		btfsc	cpostn ,rht
		goto	mvrht
		btfsc	cpostn ,nsn 
		goto	park 
		goto	align

You also need to change it in a few other places.

Mike.
 
but left me confiused , why have "movlw" woked else where .
and not here ????

Read what the commands do - MOVLW is MOVe Literal to W - this moves the fixed number following it into the W register. In the case of PORTB, as that has the value 6, it will move 6 to W, and nothing but 6.

MOVFW means MOVe File to W - this moves the contents of the file register specified to W, which will vary depening on it's contents.

Probably my fault (OK definitely my fault), but when you post code use the 'Code' tags to maintain the formatting, you need to click on 'go advanced' in order to get the icon for it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top