Simple routine how to store data in microcontroller flash and read from it using WinAVR

I’ve been asked about how to store data table in flash memory using winavr toolset. I decided to post an answer here. Might be someone find this useful.

To demonstrate this I have set up a project using VMLAB simulator. The files you can download from here: Small project using VMLAB simulator

So I created project in VMLAB. You should read my previous article ho to do this: Using VMLAB as virtual oscilloscope

In project window I have connected 8 LED’s to port D by typing this:

D1 VDD PD0

D2 VDD PD1

D3 VDD PD2

D4 VDD PD3

D5 VDD PD4

D6 VDD PD5

D7 VDD PD6

D8 VDD PD7

Then I wrote a simple C program:

c_program.PNG

In program you see, that data can be stored in flash memory using data describing sentence:

const uint8_t digits[] PROGMEM={your data};

To make PROGMEM macro work you have to include library pgmspace.h.

Bellow you see result of simulation in VMLAB environment:

leds.gif

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

To submit your comment, click the image below where it asks you to...