0

I am learning to debug AVR in AtmelStudio. So I have written a simple program to test. But it compiles correctly but not executes as expected. I had written following code ATmega32

#include <avr/io.h>   
int main(void)
{
DDRA = 0xFF;
PORTA = (10/100)*255;
return 0;
}

And from the debug menu selected Start Debugging and Break. In IO window I have selected I/O Port (PORTA). I pressed F11 key for step by step execution. Only DDRD is written with required value but porta is not assigned any value and it completes debuging. Why PORTA is not written any thing.

Ganesh S
  • 21
  • 1
  • 4

1 Answers1

2

Because of the way integer division works in C, 10/100 evaluates to 0, so you are actually assigning 0 to PORTA. If you see that the value of PORTA is 0 then your program is behaving as expected. It's hard to believe your statement that "porta is not assigned any value" without seeing a screenshot or short video.

You might consider writing this instead:

PORTA = 255 * 10 / 100;
David Grayson
  • 84,103
  • 24
  • 152
  • 189