Atmel AVR microcontroller has typically three memories

- RAM (Random Access Memory):- In RAM i.e. static RAM/CRAM by the GCC compiler place for variables is reserved; also the stack is in the RAM. This memory is volatile, means contents of the variable are lost with switching off a collapse of voltage supply.
- Program memory:- Implementedas Flash memory, again- record ably by page. In it the application program is put down.
- EEPROM:- Not volatile memory i.e. once written contents remain without current supply. Bytes by bytes write/ read ably. In the EEPROM typically device-specific values are put down like calibration values of sensor.

Pointer:
Whenever we declare a variable, the system allocates somewhere in the memory, an appropriate location to hold the value of the variable. Every byte has a unique address number. The location will have its own address number
Example:- uint8_t myByte=8;
Let’s us assume that the system has chosen the address location 0x00f for myByte. Then the concept is

A pointer variable is nothing but a variable that contains an address, which is a location of another variable in memory.
Declaration of pointer variable
data_type *pointer_name;
i.e. uint8_t *p; /** unsigned 8 bit integer **/
This tells the compiler three things about the variable pointer_name-
- The asterisk(*) tells that the variable pointer_name is a pointer variable
- pointer_name needs a memory location
- pointer_name points to a variable of data type
Declaration style
style1 —-> int* p;
style2 —-> int *p;
style1 —-> int * p;

Pointers and arrays
C:/> int Data[4]={1,2,3,4,5};
Let the address begin with 0x0000H, than
If we declare p as an integer pointer, than we can make the pointer p to point to the array data by
p=x; // equivalent to p=&x[0]
Now we can access every value of Data variable using p++ to move from one element to another.

There is necessary special function in order to read/write data from this memory. The Header file to access this memory is
#include<avr/pgmspace.h>
Write data to flash memory
const data_type variable_name [] PROGMEM
Read data from flash memory
variable=pgm_read_X(& variable_name[++]);
where X represents the variable data type


Let’s build a wave to run a buzzer. Just connect the buzzer + terminal to PB0 pin of ATtiny13A and – terminal to ground. Here we store the value in Flash memory and read the data. It’s a simple program as follow-
/************************************************************************************************
*************************************************************************************************
This program will genarate a sound wave
*************************************************************************************************
Subeer Kumar Sarkar
Electrical & Electronic Engineer
************************************************************************************************
************************************************************************************************
***********************************************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include<avr/pgmspace.h>
const uint8_t sound[512] PROGMEM ={
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff
};
int main(void)
{
uint8_t generarion;
DDRB|=(1<<DDB0);
while(1)
{
for(int i=0;i<512;i++)
{
generarion=(uint8_t*)pgm_read_word(&sound[i]);
generarion ? (PORTB|=(1<<PB0)) : (PORTB&=~(1<<PB0));
_delay_ms(1);
}
}
return 0;
}







Visit Today : 35
Total Visit : 28450