AVR EEPROM

AVR has an inbult EEPROM. Here we are trying to interface that EEPROM .We are using the EEPROM to write a data on the EEPROM and then read back the EEPROM and display the data in our LCD. The AVR AT Mega 16 has an EEPROM of 512 bytes and needs and addressing of 10 bits.

Read more about LCD

 The EEPROM

EEPROM stands for Electrically Erasable Programmable Read Only Memory. This is a non-volatile memory which means any data which will be written to the EEPROM will remain in the memory even when no power is supplied and it can be read at any time to retrieve the data.

The registers associated with EEPROM of the AVR are

EEAR : EEPROM Address Registers

The EEPROM module needs a 9 bit address to access the 512 Bytes of memory. So the address Register is divided into two registers the EEARH and EEARL for high and low bits.

EEAR Register

Bits 15 to 9 are reserved

Bits 8 to 0 are R/W bits and are used to specify the location where the data is to be written or the data has to be read from.

EEDR

The EEDR is the EEPROM data register and any kind of value can be written. This register value will be written to the EEPROM.

EECR

This is the EEPROM Control Register.

EECR Register

Bits 7 to 4 are reserved.

EERIE : The 3rd bit is EEPROM Ready Interrupt Enable. Writing EERIE to one enables the EEPROM Ready Interrupt if the I bit in SREG is set.Writing EERIE to zero disables the interrupt. The EEPROM Ready interrupt generates a constant interrupt when EEWE is cleared.

EEMWE: EEPROM Master Write Enable. This bit must be made 1 to write data to the EEPROM

EEWE: EEPROM Write Enable. To write data to the EEPROM this bit must be made 1 but only after EEMWE is made 1.

EERE: EEPROM read enable. This bit must be made 1 to read from the AVR.

Interfacing LCD with AVR

Please Sign Up or Register with us to view the code. Don’t Worry its free.

/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project : 
Version : 
Date    : 9/5/2013
Author  : 
Company : 
Comments: 

Chip type           : ATmega16
Program type        : Application
Clock frequency     : 8.000000 MHz
Memory model        : Small
External RAM size   : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>

// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>

void lcd_initt();
void lcd_comm(int);
void lcd_data_single(unsigned char);
void EEPROM_write(unsigned int, unsigned char);
unsigned char EEPROM_read(unsigned int);

// Declare your global variables here
unsigned char a[11]="Embed Idea";
unsigned char b;

void main(void)
{
// Declare your local variables here
   int i;
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

i=0;

      lcd_initt();
      while(a[i]!='\0')
      {      
      EEPROM_write(0x50+i,a[i]);
      delay_ms(10);
      i++;
      }
      i=0;
      while(a[i]!='\0')
      {
      b = EEPROM_read(0x50+i);
      delay_ms(10);
      lcd_data_single(b);
      i++;
      };
          while(1);
}
void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
/* Set up address and data registers */
EEAR = uiAddress;
EEDR = ucData;
/*Write logical one to EEMWE */
EECR =0x04;
/* Start eeprom write by setting EEWE */
EECR =0x02;
}

unsigned char EEPROM_read(unsigned int uiAddress)
{
/* Set up address register */
EEAR = uiAddress;
/* Start eeprom read by writing EERE */
EECR=0x01;
/* Return data from data register */
return EEDR;
}

void lcd_initt()
{
int x;
lcd_comm(0x38);
for(x=0;x<5000;x++);
lcd_comm(0x01);
for(x=0;x<5000;x++);
lcd_comm(0x0E);
for(x=0;x<5000;x++);
}

void lcd_comm(int x)
{
int i;
PORTD.4=0;
PORTD.6=1;
PORTB=x;
PORTD.6=0;
for(i=0;i<5000;i++);
}

void lcd_data_single(unsigned char y)
{ 
int i;
PORTD.4=1;
PORTD.6=1;
PORTB=y;
PORTD.6=0;  
for(i=0;i<5000;i++);

}

  (440)

Leave a Reply

You must be logged in to post a comment.