<> Necessary knowledge of Blue Bridge Cup MCU -----(11)EEPROM

<>EEPROM

because EPROM Inconvenience in operation , Later came out of the motherboard BIOS ROM Most of the chips are made of silicon EEPROM(Electrically Erasable Programmable
ROM, Electrically erasable programmable ROM).EEPROM No other device is needed to erase , It uses electronic signals to modify its content , And it's based on Byte Is the minimum modification unit , You don't have to wash all the data out to write it , I'm completely out of it EPROM
Eraser And programmer .EEPROM When writing data , A certain programming voltage should still be used , here , Just need the special refresh program provided by the manufacturer to rewrite the content easily , therefore , It belongs to dual voltage chip . With the help of EEPROM Dual voltage characteristics of chip , Can make BIOS It has good anti-virus function , When upgrading , Turn the jumper switch to “on” The location of , That is to add the corresponding programming voltage to the chip , It's easy to upgrade ; In normal use , Set the jumper switch to “off” The location of , prevent CIH Class of viruses BIOS Illegal modification of chip . therefore , There are still a lot of motherboards EEPROM As BIOS Chip and as a major feature of their motherboard .
IIC.H add to
void write_eeprom(unsigned char add,unsigned char val); unsigned char
read_eeprom(unsigned char add);
<>IIC.C Add in
// write in void write_eeprom(unsigned char add,unsigned char val) { IIC_Start();
IIC_SendByte(0xa0); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck();
IIC_SendByte(val); IIC_WaitAck(); IIC_Stop(); } unsigned char read_eeprom(
unsigned char add) { unsigned char da; IIC_Start(); IIC_SendByte(0xa0);
IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Start(); IIC_SendByte(0xa1)
; IIC_WaitAck(); da = IIC_RecByte(); IIC_SendAck(1); IIC_Stop(); return da; }
<>MAIN.C Call in
void delay() //10ms @11.0592MHz { unsigned char i, j; i = 108; j = 145; do {
while (--j); } while (--i); } // Read and write operation of data // write_eeprom(0x00,0x00);
//EEPROM The data stored in needs to be initialized reset_cnt = read_eeprom(0x00); // from AT24C02 address 0x00 Read data from delay
(); // delayed 10ms write_eeprom(0x00,reset_cnt); // towards AT24C02 address 0x00 Write data in delay();
<> test result :

Implementation function : Record startup times .

<> Paste the whole code

<>IIC.H
#ifndef _IIC_H #define _IIC_H void IIC_Start(void); void IIC_Stop(void); bit
IIC_WaitAck(void); void IIC_SendAck(bit ackbit); void IIC_SendByte(unsigned char
byt); unsigned char IIC_RecByte(void); void write_eeprom(unsigned char add,
unsigned char val); unsigned char read_eeprom(unsigned char add); #endif
<>IIC.C
#include "reg52.h" #include "intrins.h" #define DELAY_TIME 5 #define
SlaveAddrW 0xA0 #define SlaveAddrR 0xA1 // Bus pin definition sbit SDA = P2^1; /* data line */
sbit SCL= P2^0; /* Clock line */ void IIC_Delay(unsigned char i) { do{_nop_();} while(i
--); } // Bus start condition void IIC_Start(void) { SDA = 1; SCL = 1; IIC_Delay(DELAY_TIME);
SDA= 0; IIC_Delay(DELAY_TIME); SCL = 0; } // Bus stop condition void IIC_Stop(void) { SDA = 0
; SCL = 1; IIC_Delay(DELAY_TIME); SDA = 1; IIC_Delay(DELAY_TIME); } // Send response void
IIC_SendAck(bit ackbit) { SCL = 0; SDA = ackbit; // 0: answer ,1: Nonresponse IIC_Delay(
DELAY_TIME); SCL = 1; IIC_Delay(DELAY_TIME); SCL = 0; SDA = 1; IIC_Delay(
DELAY_TIME); } // Waiting for response bit IIC_WaitAck(void) { bit ackbit; SCL = 1; IIC_Delay(
DELAY_TIME); ackbit = SDA; SCL = 0; IIC_Delay(DELAY_TIME); return ackbit; }
// adopt I2C Bus send data void IIC_SendByte(unsigned char byt) { unsigned char i; for(i=0; i
<8; i++) { SCL = 0; IIC_Delay(DELAY_TIME); if(byt & 0x80) SDA = 1; else SDA = 0;
IIC_Delay(DELAY_TIME); SCL = 1; byt <<= 1; IIC_Delay(DELAY_TIME); } SCL = 0; }
// from I2C Receiving data on the bus unsigned char IIC_RecByte(void) { unsigned char i, da; for(i=0; i<
8; i++) { SCL = 1; IIC_Delay(DELAY_TIME); da <<= 1; if(SDA) da |= 1; SCL = 0;
IIC_Delay(DELAY_TIME); } return da; } // write in void write_eeprom(unsigned char add,
unsigned char val) { IIC_Start(); IIC_SendByte(0xa0); IIC_WaitAck();
IIC_SendByte(add); IIC_WaitAck(); IIC_SendByte(val); IIC_WaitAck(); IIC_Stop();
} unsigned char read_eeprom(unsigned char add) { unsigned char da; IIC_Start();
IIC_SendByte(0xa0); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Start()
; IIC_SendByte(0xa1); IIC_WaitAck(); da = IIC_RecByte(); IIC_SendAck(1);
IIC_Stop(); return da; }
<>MAIN.C
#include <stc15f2k60s2.h> #include "iic.h" #define uchar unsigned char #define
uint unsigned char uchar tab[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8
, 0x80, 0x90, 0xff}; uchar dspbuf[8] = {10,10,10,10,10,10,10,10}; uchar a1 = 10,
b1= 20,c1 = 0,a2,b2,c2; //uchar s4 = 0,s5 = 0,s8 = 0,s9 = 0; uchar s4 = 0,s5 = 0
,s6 = 0,s7 = 0,s8 = 0,s9 = 0,s10 = 0; uchar s11 = 0,s12 = 0,s13 = 0,s14 = 0,s15
= 0,s16 = 0,s17 = 0,s18 = 0,s19 = 0; void load(); void display(); void read_key(
); void delay() //10ms @11.0592MHz { unsigned char i, j; i = 108; j = 145; do {
while (--j); } while (--i); } void cls() { P2 = (P2 & 0x1f) | 0x80; P0 = 0xff;
P2= 0x1f; P2 = (P2 & 0x1f) | 0xa0; P0 = 0x00; P2 = 0x1f; } void main() { cls();
AUXR= 0xc0; TMOD = 0x00; TL0 = 0xcd; TH0 = 0xd4; TR0 = 1; ET0 = 1; EA = 1; c2 =
read_eeprom(0x04); delay(); c1 = c2 + 1; write_eeprom(0x04,c1); delay(); dspbuf[
4] = c2 / 10; dspbuf[5] = c2 % 10; while(1){} } void time0() interrupt 1 {
display(); } void display() { static unsigned char dspcom = 0; P2 = (P2 & 0x1f)
| 0xe0; P0 = 0xff; P2 = 0x1f; P2 = (P2 & 0x1f) | 0xc0; P0 = 1 << dspcom; P2 =
0x1f; P2 = (P2 & 0x1f) | 0xe0; P0 = tab[dspbuf[dspcom]]; P2 = 0x1f; if(++dspcom
== 8) dspcom = 0; }

Technology