简体   繁体   English

使用AVR时如何查找变量的地址?

[英]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. 我正在尝试编写一个程序,以在使用AVR-GCC编译的Teensy微控制器上检测位图的像素级冲突。 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. AVR没有printf,而且我不知道如何将其显示在屏幕上。 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. 使用snprintf并将字符串发送到终端。 It is very costly on the AVR uC. 在AVR uC上这非常昂贵。 If you use gcc address spaces extensions you may have to link the support for the long numbers. 如果使用gcc地址空间扩展名,则可能必须链接对长号的支持。

Assuming you have a working printf() , this should work: 假设您有一个有效的printf() ,这应该可以工作:

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

Where %p is how to print a void * . 其中%p是如何打印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. 为了匹配,其他指针类型应强制转换为void * ,但无论如何,我还是将void *用作了进入帧缓冲区的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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