您的位置 首页 系统

AVR-GCC怎么调用存储于Flash中的指向函数的指针

—————————————————————功能:演示AVR-GCC如何调用存储于Flash中的指向函数的指针(摇

//—————————————————————
// 功用:演示AVR-GCC怎么调用存储于Flash中的指向函数指针 (摇晃灯)
//—————————————————————
#include <avr/io.h>
#include
#include
void ledrun(void);
typedef struct
{
void (*pFun)(void);
}Function;
const Function function PROGMEM={ledrun};
void ledrun(void)
{
static unsigned char light_on=0x01;
static unsigned char light_ddr=0;
PORTD=light_on;

if (light_ddr==0)
{
if (light_on==0x80)light_ddr=1;
else light_on<<=1;
}

else
{
if (light_on==0x01)light_ddr=0;
else light_on>>=1;
}

_delay_ms(50);
}

int main(void)
{
PORTD=0;
DDRD=~0;

//void (*pFun)(void) =ledrun;

while (1)
{
//pgm_read_word(&function.pFun);
(*((void(*)(void))pgm_read_word(&function.pFun)))(); //其他没什么说,要害就在这儿了
}

return 0;
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/xitong/261306.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部