Circuit Diagram:
For those who want to build it on their own breadboard or other platform, here is the electronic scheme built in Eagle Cad, free version:
Software:
Here is the C program written for MikroC PRO for PIC 2010 (version v4.15).
/*
'*******************************************************************************
' Lesson nr.19:
' Using Internal EEPROM Memory.
' Done by:
' Aureliu Raducu Macovei, 2010.
' Description:
' In this experiment we will work with internal EEPROM Memory
' and I'll show how to write and read information on it helped by a little
' menu displayed on the LCD.
' Communication with LCD will be performed through 4-bits and connections
' is made as follows: D4 with RB0, D5 with RB1, D6 with RB2, D7 with RB3;
' RS with RB4 and EN with RB5.
' The Push buttons are connected to PORT RA4 (for read), RA6(for write) and RA7
' (for delete). Of course we need pull-up resistors (4k7 is required).
' Test configuration:
' MCU: PIC16F628A
' Test.Board: WB-106 Breadboard 2420 dots
' SW: MikroC PRO for PIC 2010 (version v4.15)
' Configuration Word
' Oscillator: INTOSC:I/O on RA.6, I/O on RA.7
' Watchdog Timer: OFF
' Power up Timer: Disabled
' Master Clear Enable: Enabled
' Browun Out Detect: Enabled
' Low Voltage Program: Disabled
' Data EE Read Protect: Disabled
' Code Protect: OFF
'*******************************************************************************
*/
// LCD module connections
sbit LCD_RS at RB4_bit; // LCD_RS assigned to PORT RB4;
sbit LCD_EN at RB5_bit; // LCD_EN assigned to PORT RB5;
sbit LCD_D4 at RB0_bit; // LCD_D4 assigned to PORT RB0;
sbit LCD_D5 at RB1_bit; // LCD_D5 assigned to PORT RB1;
sbit LCD_D6 at RB2_bit; // LCD_D6 assigned to PORT RB2;
sbit LCD_D7 at RB3_bit; // LCD_D7 assigned to PORT RB3;
sbit LCD_RS_Direction at TRISB4_bit; // LCD_RS assigned to TRIS B4;
sbit LCD_EN_Direction at TRISB5_bit; // LCD_EN assigned to TRIS B5;
sbit LCD_D4_Direction at TRISB0_bit; // LCD_D4 assigned to TRIS B0;
sbit LCD_D5_Direction at TRISB1_bit; // LCD_D5 assigned to TRIS B1;
sbit LCD_D6_Direction at TRISB2_bit; // LCD_D6 assigned to TRIS B2;
sbit LCD_D7_Direction at TRISB3_bit; // LCD_D7 assigned to TRIS B3;
// End LCD module connections
// Define Messages
char message1[] = "Switch1: Read";
char message2[] = "Switch2: Write";
char message3[] = "Switch3: Erase";
char message4[] = "EEPROM_Write";
char message5[] = "EEPROM_Read ";
char message6[] = "EEPROM ERASED";
char message7[] = "Internal";
char message8[] = "EEPROM";
char message9[] = "*";
char message10[] = "**";
char message11[] = "***";
char digit[] = "00000000000000";
unsigned short ii, All ;
void read_eeprom()
{
if (Button(&PORTA, 4, 1, 0)) // Detect logical one to zero;
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,message5);
Lcd_Out(2,7,message9);
delay_ms(1000); // Delay 1s
Lcd_Out(2,7,message10);
delay_ms(1000); // Delay 1s
Lcd_Out(2,7,message11);
delay_ms(1000); // Delay 1s
for (ii=0; ii<=13; ii++)
{
All = EEPROM_Read(0x00+ii); // Start EEPROM Location,
digit[ii] = All+65; // Look at ascii table
}
Lcd_Out(2,2,digit);
delay_ms(5000); // Delay 5s
}
}
void write_eeprom()
{
if (Button(&PORTA, 6, 1, 0)) // Detect logical one to zero
{
for (ii=0; ii<14; ii++)
EEPROM_Write(0x00+ii,ii);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,message4);
Lcd_Out(2,7,message9);
delay_ms(1000);
Lcd_Out(2,7,message10);
delay_ms(1000);
Lcd_Out(2,7,message11);
delay_ms(1000);
}
}
void delete_eeprom()
{
if (Button(&PORTA, 7, 1, 0)) // Detect logical one to zero
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,message6);
Lcd_Out(2,7,message9);
delay_ms(1000);
Lcd_Out(2,7,message10);
delay_ms(1000);
Lcd_Out(2,7,message11);
delay_ms(1000);
for (ii=0; ii<=13; ii++)
EEPROM_Write(0x00+ii,0x0e);
}
}
void main() {
CMCON |= 7; // Disable Comparators
TRISA4_bit = 1;
TRISA6_bit = 1;
TRISA7_bit = 1;
TRISB = 0;
PORTB = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,5,message7);
Lcd_Out(2,6,message8);
delay_ms(3000); // Delay 3s
do {
Lcd_cmd(_LCD_Clear);
Lcd_Out(1,2,message1); // Write message1 in 1st row
delay_ms(1000);
read_eeprom();
write_eeprom();
delete_eeprom();
Lcd_cmd(_LCD_Clear);
Lcd_Out(1,2,message2);
delay_ms(1000);
read_eeprom();
write_eeprom();
delete_eeprom();
Lcd_cmd(_LCD_Clear);
Lcd_Out(1,2,message3);
delay_ms(1000);
read_eeprom();
write_eeprom();
delete_eeprom();
} while(1);
}