{"id":2547,"date":"2011-05-04T17:22:19","date_gmt":"2011-05-04T21:22:19","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=2547"},"modified":"2012-07-30T09:29:19","modified_gmt":"2012-07-30T13:29:19","slug":"lab-13-read-and-write-to-internal-eeprom","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/lab-13-read-and-write-to-internal-eeprom\/","title":{"rendered":"Lab 13: Read and Write to internal EEPROM"},"content":{"rendered":"<p>EEPROM (<em><strong>E<\/strong>lectrically <strong>E<\/strong>rasable <strong>P<\/strong>rogrammable <strong>R<\/strong>ead-<strong>O<\/strong>nly <strong>M<\/strong>emory<\/em>) is a type of non-volatile memory which can be programmed, erased, and re-programmed electrically while it is on the circuit board. A majority of PIC microcontrollers come with some built-in\u00a0EEPROM which is a great place to store data that should not be lost when the system is powered down. A good example is a digital lock system where the access code can be stored in the EEPROM of microcontroller so that the contents remain intact even after the power supply has been removed. In my &#8216;<strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=2236\" target=\"_blank\">Beginner&#8217;s data logger<\/a><\/strong>&#8216; project, I used the internal EEPROM of PIC12F683 to store the measured temperature values. In today&#8217;s experiment, we will learn how to perform the basic Read and Write operations to the internal EEPROM of PIC16F628A.<\/p>\n<div id=\"attachment_2555\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_Title.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2555\" class=\"size-full wp-image-2555\" title=\"InternalEEPROM_Title\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_Title.jpg\" alt=\"\" width=\"560\" height=\"353\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_Title.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_Title-550x346.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2555\" class=\"wp-caption-text\">Read\/Write operation with PIC&#39;s internal EEPROM<\/p><\/div>\n<p><!--more--><strong>Theory<\/strong><\/p>\n<p>PIC16F628A microcontroller has got 128 bytes of data EEPROM with an address range from 00h to 7Fh. There are four Special Function Registers used to read and write this memory, which are EECON1, EECON2, EEDATA, and EEADR. EEADR holds the address in the EEPROM which you wish to read or write to, while EEDATA holds the 8-bit data that you have just read, or which you wish to write to the EEPROM. EECON1 and EECON2 are control registers that are used to enable the EEPROM read\/write operations. We will ignore the details of these registers here because we will be using mikroC compiler for programming, where the built-in library routines for EEPROM operations takes care of configuring these registers. However, you can find the details of these registers in the <a href=\"http:\/\/ww1.microchip.com\/downloads\/en\/devicedoc\/40044f.pdf\" target=\"_blank\">datasheet of PIC16F628A<\/a>.<\/p>\n<p><strong>Circuit setup<\/strong><\/p>\n<p>This experiment requires a 16&#215;2 character LCD for display and three tactile switches for user inputs. The circuit diagram below shows the connections of the LCD and the switches with the PIC16F628A microcontroller.<\/p>\n<div id=\"attachment_4078\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/Lab13EEPROMCkt.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4078\" class=\"size-medium wp-image-4078\" title=\"Lab13EEPROMCkt\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/Lab13EEPROMCkt-550x433.png\" alt=\"\" width=\"550\" height=\"433\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/Lab13EEPROMCkt-550x433.png 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/Lab13EEPROMCkt.png 669w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4078\" class=\"wp-caption-text\">Circuit diagram for Lab 13<\/p><\/div>\n<p>The three tact switches are connected to RB0, RB1, and RB3 pins. The LCD is operating in 4-bit mode and the data pins are driven by RB4 through RB7 pins of PIC16F628A. The LCD RS and E control pins are connected to RA0 and RA1 pins. The functions of the three tact switches are discussed in software section.<\/p>\n<div id=\"attachment_2554\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_setup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2554\" class=\"size-full wp-image-2554\" title=\"InternalEEPROM_setup\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_setup.jpg\" alt=\"\" width=\"560\" height=\"349\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_setup.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_setup-550x342.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2554\" class=\"wp-caption-text\">Experimental circuit setup on breadboard<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>We will write a small application software for PIC16F628A that will do Read, Write and Delete operations to the selected internal EEPROM locations (00h through 0Fh) of PIC16F628A. When the Read button is pressed, the 16 bytes of information stored at 00h-0Fh locations will be read and displayed on the LCD screen. Pressing the Write button will write a character string &#8216;Embedded-Lab.com&#8217; to these locations, whereas if the Zero button is pressed, the values in these locations will be replaced by all 0s.<\/p>\n<p>The mikroC Pro for PIC compiler provides the following functions for EEPROM read and write operations:<\/p>\n<p><strong>unsigned short<\/strong> EEPROM_Read(<strong>unsigned short<\/strong> address) :- returns a byte from the specified address<\/p>\n<p><strong>void<\/strong> EEPROM_Write(<strong>unsigned short<\/strong> address, <strong>unsigned short<\/strong> data) :- writes the data at the specified address<\/p>\n<p>You can download the complete source code and hex files from the link below.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC16F628A\/InternalEEPROM.zip\">Download mikroC project files<\/a><\/p>\n<p><strong>Output<\/strong><\/p>\n<p>The default values in an erased EEPROM locations are all FFh (255). All 5&#215;10 dots are active on the screen when this value (FFh) is displayed on LCD. So when you first read the EEPROM, which is in an erased state, you will read all FFh (see pictures below). Once the Write operation is completed, turn off the power for a few seconds, then turn it back again, and press the Read button. You will see the character string (Embedded-Lab.com) is still retained inside the EEPROM.<\/p>\n<div id=\"attachment_2548\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2548\" class=\"size-full wp-image-2548\" title=\"InternalEEPROM_1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_1.jpg\" alt=\"\" width=\"560\" height=\"336\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_1.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_1-550x330.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2548\" class=\"wp-caption-text\">Main menu<\/p><\/div>\n<div id=\"attachment_2549\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2549\" class=\"size-full wp-image-2549\" title=\"InternalEEPROM_2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_2.jpg\" alt=\"\" width=\"560\" height=\"328\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_2.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_2-550x322.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2549\" class=\"wp-caption-text\">Reading all FF&#39;s at the beginning<\/p><\/div>\n<div id=\"attachment_2550\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_3.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2550\" class=\"size-full wp-image-2550\" title=\"InternalEEPROM_3\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_3.jpg\" alt=\"\" width=\"560\" height=\"292\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_3.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_3-550x286.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2550\" class=\"wp-caption-text\">Write operation<\/p><\/div>\n<div id=\"attachment_2551\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_4.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2551\" class=\"size-full wp-image-2551\" title=\"InternalEEPROM_4\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_4.jpg\" alt=\"\" width=\"560\" height=\"311\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_4.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_4-550x305.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2551\" class=\"wp-caption-text\">Reading again the newly stored valuesa<\/p><\/div>\n<div id=\"attachment_2552\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_5.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2552\" class=\"size-full wp-image-2552\" title=\"InternalEEPROM_5\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_5.jpg\" alt=\"\" width=\"560\" height=\"320\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_5.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_5-550x314.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2552\" class=\"wp-caption-text\">Zeroing the locations<\/p><\/div>\n<div id=\"attachment_2553\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_6.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2553\" class=\"size-full wp-image-2553\" title=\"InternalEEPROM_6\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_6.jpg\" alt=\"\" width=\"560\" height=\"315\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_6.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/05\/InternalEEPROM_6-550x309.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-2553\" class=\"wp-caption-text\">Reading all Zeros<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>EEPROM (Electrically Erasable Programmable Read-Only Memory) is a type of non-volatile memory which can be programmed, erased, and re-programmed electrically while it is on the circuit board. A majority of PIC microcontrollers come with some built-in\u00a0EEPROM which is a great place to store data that should not be lost when the system is powered down. A good example is a digital lock system where the access code can be stored in the EEPROM of microcontroller so that the contents remain intact even after the power supply has been removed. In my &#8216;Beginner&#8217;s data logger&#8216; project, I used the internal EEPROM<\/p>\n","protected":false},"author":1,"featured_media":2548,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,38],"tags":[264,265,96],"class_list":["post-2547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-lessons","category-pic-tutorials","tag-eeprom","tag-internal-eeprom","tag-pic16f628a"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=2547"}],"version-history":[{"count":24,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2547\/revisions"}],"predecessor-version":[{"id":5756,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2547\/revisions\/5756"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/2548"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=2547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=2547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=2547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}