How does AVR-GCC call a pointer to a function stored in Flash?

Publisher:楼高峰Latest update time:2016-01-13 Source: eefocusKeywords:AVR-GCC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//---------------------------------------------------------------
// Function: Demonstrate how AVR-GCC calls a pointer to a function stored in Flash (swinging light)
//---------------------------------------------------------------
#include
#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)))(); //Nothing else to say, the key is here
}

return 0;
Keywords:AVR-GCC Reference address:How does AVR-GCC call a pointer to a function stored in Flash?

Previous article:About correctly configuring AVR fuse bits
Next article:AVR Programming_How to set, clear and check if I/O is set in C language

Recommended ReadingLatest update time:2024-11-17 05:37

Puran Semiconductor: Ultra-low power NOR Flash helps XR expansion
Recently, at the "2023 Songshan Lake China IC Innovation Summit Forum", Feng Guoyou, senior director of Purui Semiconductor Design Center, introduced the industry's first 1.1V 6.5μJ/Mb ultra-low power NOR Flash. Purui Semiconductor's core strategy is divided into two parts, including memory and memory-b
[Embedded]
Puran Semiconductor: Ultra-low power NOR Flash helps XR expansion
NAND Flash driver design solution
NAND Flash driver design solution Taking Samsung K9F2808UOB as an example, the interface circuit between NAND Flash and S3C2410 is designed, and the design and implementation method of NAND Flash in ARM embedded system is introduced, and verified on UBoot. The designed driver is easy to transplant and can
[Analog Electronics]
NAND Flash driver design solution
AVR-GCC develops 5 software combinations
1.GCC+PN(WinAVR-20071221) Introduction: WinAVR-20071221 comes with Programmer's Notepad, which is an easy-to-use and powerful code editor with basic functions such as project management, syntax coloring, code folding, etc., and has perfect support for Chinese. Example: #include avr\io.h    //Header file included,
[Microcontroller]
STM32-Flash flash programming principles and steps
STM32 programming method: (1) ICP (JTAG/SWD protocol or system bootloader (serial port)) downloads the program to the microcontroller. (2) IAP: It is to download programs or data to the memory through any communication interface (IO port, USB, CAN, SPI, IIC, etc.). STM32 allows users to re-burn the contents of the fla
[Microcontroller]
Cortex-M3 (NXP LPC1788) Watchdog Timer's Impact on Flash Programming
        I have been learning about the windowed watchdog module these days. I had been debugging happily before, but this morning I suddenly could not enter the debugging mode, and could not erase the Flash or download the program. I was depressed for a long time, thinking that there was something wrong with the Keil s
[Microcontroller]
stm32.cube(六)——HAL.FLASH
1. On-chip Flash Features 1.1 Flash structure diagram   My development board is stm32f103xx, so the on-chip flash main memory size is 128K, and a single page is 1K. Different chips have different flash sizes and page sizes. Main Memory The area used to store Rom programs and burn them. Of course, it can also store o
[Microcontroller]
Application of NAND Flash in MSP430 Embedded System
NAND Flash is a non-volatile memory using NAND structure technology. It has the characteristics of ROM memory. The data stored in the chip can be maintained for 10 years without loss in the case of power failure, and the chip pins and access have similar characteristics to RAM. NAND FLASH memory multiplexes the da
[Microcontroller]
Application of NAND Flash in MSP430 Embedded System
What is the difference between EEPROM and flash in a microcontroller?
Flash is used to store code and cannot be changed during operation; EEPROM is used to store user data and can be changed during operation. For example, the alarm time of a clock is initially set to 12:00, and then changed to 6:00 during operation. This is stored in EEPROM and is not afraid of power failure. Even if the
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号