AT89S52 Mini Development Board – EEPROM Interfacing
The AT89S52 Development Board (Mini) has an on board external 24C04 EEPROM (Electrically Erasable And Programmable Read-Only Memory) interfaced over I2C. The 24C04 provides 4096 bits of serial EEPROM organized as 512 words of 8 bits each. For interfacing make sure you had short the jumpers at J11 (SCL)and J10(SDA).SchematicSample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
/******************************************************************************** HEADER FILES *********************************************************************************/ #include <REGX52.H> #include <intrins.h> #define Lcd_Port P0 #define EN P1_0 #define RS P1_2 #define RW P1_1 #define LED1 P1_5 #define LED2 P1_4 #define SW1 P2_0 /******************************************************************************** FUNCTION DECLARATIONS *********************************************************************************/ void Eeprom_Save(void); void Eeprom_Read(void); void Lcd_Initial(void); void Lcd_Command(char); void Lcd_Data(char); unsigned char byte1,byte2; void Delay(unsigned int count); void Lcd_Display(unsigned char locn,const char *dat); /******************************************************************************** VARIABLE DECLARATIONS *********************************************************************************/ sbit sda=P3^4; sbit scl=P3^5; bit ack; unsigned char reead,write,write2; /******************************************************************************** MAIN FUNCTION *********************************************************************************/ void main() { Lcd_Initial(); while(1) { if(SW1==0) { Lcd_Display(0x80,"Sent :"); Lcd_Display(0xC0,"Read :"); Eeprom_Save(); Eeprom_Read(); Delay(250); } } } /******************************************************************************** * Function : Start * * * * Description : Function to give Start bit to EEPROM * * * * Parameters : None * *********************************************************************************/ void Start(void) { sda=1; scl=1; _nop_(); _nop_(); sda=0; scl=0; } /******************************************************************************** * Function : Stop * * * * Description : Function to give Stop bit to EEPROM * * * * Parameters : None * *********************************************************************************/ void Stop(void) { sda=0; scl=1; _nop_(); _nop_(); sda=1; scl=0; } /******************************************************************************** * Function : Aknowledge * * * * Description : Function to give acknowledge to EEPROM * * * * Parameters : None * *********************************************************************************/ void Aknowledge(void) { scl=1; _nop_(); _nop_(); scl=0; } /******************************************************************************** * Function : Send_Byte * * * * Description : Function to sent data to EEPROM * * * * Parameters : None * *********************************************************************************/ void Send_Byte(unsigned char value) { unsigned int i; unsigned char send; send=value; for(i=0;i<8;i++) { sda=send/128; send=send<<1; scl=1; _nop_(); _nop_(); scl=0; } ack=sda; sda=0; } /******************************************************************************** * Function : Read_Byte * * * * Description : Function to read data from EEPROM * * * * Parameters : None * *********************************************************************************/ unsigned char Read_Byte(void) { unsigned int i; sda=1; reead=0; for(i=0;i<8;i++) { reead=reead<<1; scl=1; _nop_(); _nop_(); if(sda==1) reead++; scl=0; } sda=0; return reead; } /******************************************************************************** * Function : Eeprom_Save * * * * Description : Function to store data in EEPROM * * * * Parameters : None * *********************************************************************************/ void Eeprom_Save(void) { Start(); Send_Byte(0xA0); Aknowledge(); Send_Byte(0x07); Aknowledge(); Send_Byte(5); Aknowledge(); Send_Byte(65); Aknowledge(); Stop(); if(ack==0) { LED1=0; Delay(100); LED1=1; Delay(100); Lcd_Display(0x86,"5A"); } else LED2=0; Aknowledge(); } /******************************************************************************** * Function : Eeprom_Read * * * * Description : Function to Read data from EEPROM * * * * Parameters : None * *********************************************************************************/ void Eeprom_Read(void) { Start(); Send_Byte(0xA0); Aknowledge(); Send_Byte(0x07); Aknowledge(); Start(); Send_Byte(0xA1); Aknowledge(); byte1=Read_Byte(); Aknowledge(); byte2=Read_Byte(); Aknowledge(); Stop(); if(byte1==5) { LED2=0; Delay(100); LED2=1; Delay(100); write=byte1+48; Lcd_Command(0xC6); Lcd_Data(write); } else LED1=1; if(byte2==65) { Lcd_Command(0xC7); Lcd_Data(byte2); } Aknowledge(); } /******************************************************************************** * Function : Lcd_Initial * * * * Description : Function to initialise LCD * * * * Parameters : None * *********************************************************************************/ void Lcd_Initial(void) { Lcd_Command(0x30); Lcd_Command(0x30); Lcd_Command(0x30); Lcd_Command(0x38); Lcd_Command(0x01); Lcd_Command(0x06); Lcd_Command(0x0c); Lcd_Command(0x80); } /******************************************************************************** * Function : Lcd_Command * * * * Description : Function to give command to LCD * * * * Parameters : value - command * *********************************************************************************/ void Lcd_Command(char value) { RW=0; RS=0; EN=1; Lcd_Port=value; Delay(1); EN=0; } /******************************************************************************** * Function : Lcd_Data * * * * Description : Function to give data for displayto LCD * * * * Parameters : value - data * *********************************************************************************/ void Lcd_Data(char value) { RW=0; RS=1; EN=1; Lcd_Port=value; Delay(1); EN=0; } /******************************************************************************** * Function : Lcd_Display * * * * Description : Function to display string on LCD * * * * Parameters : locn - address , dat - string * *********************************************************************************/ void Lcd_Display(unsigned char locn,const char *dat) { RS=0; RW=0; EN=1; Lcd_Port=locn; Delay(1); EN=0; while(*dat!='\0') { RS=1; RW=0; EN=1; Lcd_Port=*dat; Delay(1); EN=0; dat++; } } /******************************************************************************** * Function : Delay * * * * Description : Function for Delay * * * * Parameters : count - Delay time * *********************************************************************************/ void Delay(unsigned int count) { int x,y; for(x=0;x<count;x++) for(y=0;y<1275;y++); } |
Topics related to AT89S52 Mini Development Board
- AT89S52 Mini Development Board – Overview
- AT89S52 Mini Development Board – LED Interfacing
- AT89S52 Mini Development Board – LCD Interfacing
- AT89S52 Mini Development Board – Serial communication
- AT89S52 Mini Development Board – EEPROM Interfacing
- AT89S52 Mini Development Board – Buzzer Interfacing
- AT89S52 Mini Development Board – Servo Motor Interfacing
- AT89S52 Mini Development Board – Switch Interfacing
- AT89S52 Mini Development Board – RFID Interfacing
Resources
How to buy?
- Click here to buy the rhydoLABZ AT89S52 Mni Development Board (Mini) V1.01
- Click here to buy the rhydoLABZ AT89S52 Development Board
- Click here to buy the rhydoLABZ AT89S52-24PU Microcontroller
- Click here to buy the rhydoLABZ ATMEL 89SXX ISP Programmer (RS232)
SupportPlease share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.