Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Watching variables

3 posters

Go down  Message [Page 1 of 1]

1Watching variables Empty Watching variables Mon Jul 25, 2022 3:03 pm

terumi



Hello people,
I'm trying to watch a variable on a program but I cannot find a way

my code is:
Code:
#ifndef F_CPU
#define F_CPU 16000000UL //clock speed is 16MHz
#endif

#include <avr/io.h>
#include <util/delay.h>

int asd = 0;

int main(void) //main starts
{
 
 DDRD = DDRD | ( 1<<4) ; //Make pin 4 of port D as a output
 DDRC = DDRC & ~(1<<5) ; // Make pin 5 of port C as a input
 
 while (1) //initialize while loop
 {

 if(PINC & (1<<5) ) //if PIN5 of port C is high
 {
 PORTD = PORTD | ( 1<<4) ; //PIN4 of port D is high
 asd = 54;
 }
 else //otherwise
 {
 PORTD = PORTD &  ~( 1<<4) ; //PIN4 of port D will remain low
 }
 } // while loop ends
} //main end

and I'm trying to see the value of asd, but I cannot find it anywhere.

What  are my options for such a problem?
Thank you!

2Watching variables Empty Re: Watching variables Tue Jul 26, 2022 11:15 am

arcachofo

arcachofo

Hi.

In many cases variables are optimized out by the compiler.
In your code that variable does nothing so the compiler just ignores it.

terumi likes this post

3Watching variables Empty Re: Watching variables Tue Jul 26, 2022 11:31 am

terumi



So the question remains, how can you print some variables in order to see their values?

Thank you

4Watching variables Empty Re: Watching variables Tue Jul 26, 2022 11:58 am

Defran

Defran

5Watching variables Empty Re: Watching variables Tue Jul 26, 2022 3:17 pm

arcachofo

arcachofo

terumi wrote:So the question remains, how can you print some variables in order to see their values?

In general to watch Ram values you can use Mcu Monitor:
- Right-click in the Mcu -> Open Mcu Monitor.
- Add register names or addresses in the "Reg" column.
- When you use the debugger you can add variable names as well.

Depending on simulide version you can debug or not for some compilers.
In vesion 0.4.15 avr-gcc is not supported, so there are not much options.
You can use the Serial Monitor or the Mcu Monitor if you know the Ram address used for that variable.

From version 1.0.0 you can use the debugger for many compilers.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum