avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fw: [avr-gcc-list] Re: placing a variable in flash


From: Royce & Sharal Pereira
Subject: Fw: [avr-gcc-list] Re: placing a variable in flash
Date: Tue, 23 Nov 2004 10:48:39 +0530

Hi,
----- Original Message -----
> > >Say I place the Oscillator Calib. byte at 0x1fff. How can retreive it
in my
> > >program? I have to 'tell' GCC to look for it at (byte)location 0x1fff;
which
> > >means I need to have a variable(or const) located at 0x1fff.

>   Are you trying to set the oscillator calibration register to some
>   value you determined at compile time?
>
>   If so, how about this code?
>
>   #define CALIBRATION 0x10    // For example
>
>   #include <avr/io.h>
>
>   main () {
>       outb(OSCCAL, CALIBRATION);
>   }
>
>   That sets the OSCCAL register in the processor to a value of 16.
>
>   Is that what you are trying to do, or something else?
=========================================================
Let me explain what I needed (I eventually got it done):

To operate the Mega8 @ 4MHz, the relevant osc. cal. byte has to be read *at
program time* & stored somewhere, for the device to find it & write it into
OSCCAL at startup(run time).
I use SP12 for programming, which has these 2 relevant features:
    1)One can read any one of the 4 osc.calib. bytes from the signature
location.
    2)One can programme *a single location* in flash or eeprom, by
specifying address & data, taking care it is initially 0xff. (SP12 doesn't
check for this).

I first program the entire device. This automatically erases it, setting
0x1fff to 255.
Now, using feature (1), I read the calib. byte for 4MHz, & pipe SP12 output
to a stream editor, sed, which extracts the calib byte.
Using feature (2), I write the extracted calib byte to 0x1fff in
flash(program) memory.

My challenge was creating a variable in flash at 0x1fff so that the Mega8
could read this byte at reset & save it in OSCCAL.
I then realised that I really didn't need a 'label'.
So this works:

          OSCCAL=pgm_read_byte(0x1fff))
giving:

 bc6: ef ef        ldi r30, 0xFF ; 255
 bc8: ff e1        ldi r31, 0x1F ; 31
 bca: 84 91        lpm r24, Z
 bcc: 81 bf        out 0x31, r24 ; 49

Thanks & regards,
--Royce.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]