简体   繁体   中英

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

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?

ie 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);

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM