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.

Viewing variables in MPLAB Sim

Status
Not open for further replies.

gregmcc

Member
I am busy using the mplab sim and stepping through code to try and get a understanding of exactly whats going on. Is there an easy way to view variables in the debugger.

If I have for eg.
Code:
MOVLW   0xFF		
MOVWF   Var1

Where can I view Var1? - I can find the memory location for Var1 and then watch that as I step through thru the code, but is there a easier way. There's view eeprom, file registers, hardware stack, but why no view variables or something like that?

Update: Doh - Think I found it :) - There's a watch - I just add the variables I want to view to this.
 
Last edited:
This thread wasn't too old and my issue is the same thing with one addition.

When I add a variable to the watch list the value never changes. I've got it watching the PORTA and TRISA and they are changing fine in the watch window. However, I have a delay counter decrementing and when I'm stepping through it never loads the number or decrements the number in the watch window. The delay in the simulator is acting as it should but it won't show the current values of the variables in the watch window.

If anybody knows what I may be doing wrong please help me.

Thanks,
Joe
 
Are you in the correct bank?
What happens if you hover over the variable?
Does it change in the file register view?

Mike.
 
Pommie said:
Are you in the correct bank?
What happens if you hover over the variable?
Does it change in the file register view?

Mike.

When it gets to the point in the program that it is looping for the delay the status bar tells me I'm in bank2.

When I hover over the variable in the code while single stepping through, it has a value of 0x00 which is the same as it's reporting in the watch window.

I'm not sure where I need to be looking in the file register window. I'm programming for a 16F628A, and I'm declaring the variable Timer1 to be at 0x20 and Timer2 to be at 0x21 if that helps?
 
If you are in bank 2 then it is changing location 0x120. You need to be in bank 0 for it to work correctly.

Mike.
 
Pommie said:
If you are in bank 2 then it is changing location 0x120. You need to be in bank 0 for it to work correctly.

Mike.

I'm using
TIMER1 EQU 0x20
TIMER2 EQU 0x21

to declare the variable locations. Is that where I need to make a change at? If so what would I need to change to?

Or I guess a better question would be, is there a problem with it writing to that bank? I'm still pretty green behind the ears on the PIC programming.
 
Last edited:
To view the contents of variables;
- Go to the menu bar, and click "View"
- Then select "File Registers"
- In the resulting window, click on the "Symbolic" tab on the bottom of the window

Now you can scroll thru, and find all your variables, in all the banks.
You can even change their contents right there, on-the-fly. :D

P.S. You can do the same for Special Function Registers. Select "View"->"Special Function Registers" from the menu bar.
 
Last edited:
Why are you in bank 2? It is normal to default to bank 0 and only switch banks when needed, such as when you write to Trisa etc.

EG
Code:
		bsf	STATUS,RP0	;bank 1
		movlw	b'11111100'
		movwf	TRISA
		movlw	b'11110000'
		movwf	TRISB
		movlw	b'00000111';	disable comparator
		movwf	CMCON
		bcf	STATUS,RP0	;bank 0

The bank bits (RP0 & RP1) become the 8th and 9th bits of the ram (SFR) address, the lower 7 bits are contained in the instruction. So, when you access location 0x20 it will access 0x20 in bank 0, 0xa0 in bank 1, 0x120 in bank 2 and 0x1a0 in bank 3.

HTH

Mike.
 
Pommie said:
Why are you in bank 2? It is normal to default to bank 0 and only switch banks when needed, such as when you write to Trisa etc.

EG
Code:
		bsf	STATUS,RP0	;bank 1
		movlw	b'11111100'
		movwf	TRISA
		movlw	b'11110000'
		movwf	TRISB
		movlw	b'00000111';	disable comparator
		movwf	CMCON
		bcf	STATUS,RP0	;bank 0

The bank bits (RP0 & RP1) become the 8th and 9th bits of the ram (SFR) address, the lower 7 bits are contained in the instruction. So, when you access location 0x20 it will access 0x20 in bank 0, 0xa0 in bank 1, 0x120 in bank 2 and 0x1a0 in bank 3.

HTH

Mike.


Upon reading this message, I realized what was happening. When I cleared out of setting up the ports, I was clearing the RP0 flag and then setting the RP1 flag. I didn't realize this before.:eek:

Thanks everyone for the help and I have it fixed in my code now. It also shows on the watch window under the address 0x20 and 0x21.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top