How to find the address of a variable when using AVR?

痞子三分冷 提交于 2019-12-11 06:02:29

问题


I am trying to write a program that detects pixel level collision of bitmaps on a Teensy micro controller compiling with AVR-GCC. I am trying to work out how to calculate the position of a single byte of the bitmap on the screen and have been told I should be using pointers. I don't see the relationship between the physical address of a bitmap byte and it's position on the screen, but I would like to investigate. The problem is, I have no way of printing this address. AVR doesn't have printf and I don't know how to get it to display on the screen. Does anyone have a way of producing this address somehow in the terminal?

i.e. if I have a bitmap and want to print out the address of the first byte, what would I need to write to complete this:

??? *bit = &car_bitmap[1]; 
???("%??? ", bit);

回答1:


Use snprintf and send the string to the terminal. It is very costly on the AVR uC. If you use gcc address spaces extensions you may have to link the support for the long numbers.




回答2:


Assuming you have a working printf(), this should work:

void * const bit = &car_bitmap[1]; 
printf("%p\n", bit);

Where %p is how to print a void *. Other pointer types should be cast to void * in order to match, but I used a void * for the address into the framebuffer anyway.



来源:https://stackoverflow.com/questions/50464420/how-to-find-the-address-of-a-variable-when-using-avr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!