IIC memory microcontroller power-on times

Publisher:恬淡岁月Latest update time:2015-06-29 Source: 51heiKeywords:IIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
IIC has a memory function. Actually, I didn't understand why it can remember before, because the program I wrote was to make the light flash, so I didn't understand the so-called memory principle. Today, I let it remember the number of times the microcontroller was turned on through the digital tube. Finally, I learned its true principle tomorrow. In fact, when the microcontroller controls it, the program keeps running, and the data obtained by the program is constantly written into the IIC register. The register will not lose data after power failure, so when we turn off the program, that is, the data is saved after power failure. The next time you turn it on, the program starts from the beginning, but the address starts from the address stored in our register last time, so the memory function is achieved. This application is very large in data storage and protection, such as traffic lights memorizing illegal vehicles, account storage, data accumulation, etc. can be stored by it.

The following is the program for IIC to memorize the number of times the microcontroller is powered on:

The program is as follows:
//Copyright: Single Chip Computer Network http://www.51hei.com 
#include
#include
#define uchar unsigned char//macro definition
#define uint unsigned int
sbit scl=P2^0; //These two bits are defined to control the pins of IIC      
sbit sda=P2^1;
uchar number[10]={ //Digital tube array definition
0x3f,
0x06,
0x5b,
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f
};
void delayt(void)//Delay of digital tube
{
 uint x,y;
 for(x=0;x<5;x++)
 for(y=0;y<120;y++);
}
void delay(void)//Adaptive delay of IIC
{
 _nop_();_nop_();_nop_();_nop_();
 _nop_();_nop_();_nop_();_nop_();
}
void start()//Start
{
 sda=1;
 delay();
 scl=1;
 delay();
 sda=0;
 delay(); 
}
void stop()//Stop
{
 sda=0;
 delay();
 scl=1 ;
 delay();
 sda=1;
 delay();
}
void init()//Initialization settings
{
 sda=1;
 scl=1;
}
void answer()//Response
{
 uchar i;
 scl=1;
 while((sda==1)&&(i<250))i++;
 scl=0;
 delay();
}
void noanser()//Non-response
{
 scl=1;
 delay();
 sda=1;
 delay( );
 scl=0; 
 delay();
}
void writebyte(uchar dat)//Write byte
{
 uchar i;
 scl=0;
 delay();
 for(i=0;i<8;i++)
 {
  if(dat&0x80)
  {
  sda=1;
  }
  else
  {
  sda=0;
  }
  dat=dat<<1;
  delay();
  scl=1;
  delay();
  scl=0;
  delay();
 }
 sda=1;
 
}

uchar readbyte()//Read byte
{
 uchar i,dat;
 scl=0;
 delay();
 sda=1;
 delay();
 for(i=0;i<8;i++)
 {
 scl=1;
 delay( );
 dat=dat<<1;
 if(sda)
 {
 dat++;
 }
 scl=0;
 delay();
 }
 return dat;
}


void write_byte(uchar add,uchar dat)//Write byte encapsulation
{
 init();
 start();
 writebyte(0xae);
 answer();
 writebyte(add);
 answer();
 writebyte(dat);
 answer( );
 stop();
}
uchar read_byte(uchar add)//Read byte encapsulation
{
 uchar value;
 init();
 start();
 writebyte(0xae);
 answer();
 writebyte(add);
 answer();
 start();
 writebyte(0xaf);
 answer();
 value=readbyte();
 noanser();
 stop();
 return value;
}
void main()
{
 
 
 uchar temp,k,j;

 temp=read_byte(0x10);//digital tube units and tens operation
 k=temp/10;
 j=temp%10;
 temp++;
  write_byte(0x10,temp);
 delay();
 while(1) //digital tube display
 {
 P1=number[k];
 P0=0;
 delayt();
 P1=number[j];
 P0=1;
 delayt();
 }
}

Keywords:IIC Reference address:IIC memory microcontroller power-on times

Previous article:Research and design of automatic observation control platform for solar radio telescope
Next article:Single chip microcomputer and stepper motor control

Recommended ReadingLatest update time:2024-11-17 02:40

STM32-IIC configuration explanation
STM32-IIC Configuration Explanation (Original) STM32 - I2C Introduction: The I2C bus interface connects the microcontroller and the serial I2C bus. It provides multi-host functionality and controls all I2C bus-specific timing, protocols, arbitration and timing. It supports both standard and fast modes. In addition, th
[Microcontroller]
IIC read and write AT24Cxx (S3C2440)
IIC (Inter-Integrated Circuit, I2C) bus is a two-wire serial bus developed by PHILIPS, used to connect microprocessors and their peripherals. Its main advantages are simplicity and effectiveness. It only needs a data line SDA and a clock line SCL to achieve bidirectional transmission between the CPU and the controlled
[Microcontroller]
IIC read and write AT24Cxx (S3C2440)
Initialization and simple use of stm8 hardware IIC
STM8 is a mainstream control chip commonly used by electronic engineers. IIC is a commonly used serial port protocol. However, people who have worked with 51 know that to perform IIC communication, pin simulation IIC is required. Although many engineers know that STM8 has hardware IIC, many engineers are still accusto
[Microcontroller]
STM32 - Read EEPROM based on analog IIC method
Preface: Recently, I was debugging the program of using the IIC interface to read EEPROM on the STM32L152 chip. Here is a summary of how to use the IIC interface of STM32 to read EEPROM. PS: Due to some problems with the hardware IIC of STM32, this article temporarily uses simulated IIC to read EEPROM. The usage of
[Microcontroller]
Exynos4412 Bare Metal Development——IIC Bus
Preface: I2C (Inter-Integrated Circuit) bus (also called IIC or I2C) is a two-wire serial bus developed by PHILIPS, used to connect microcontrollers and peripheral devices, and is a bus standard widely used in the field of microelectronic communication control. It is a special form of synchronous communication, with t
[Microcontroller]
Exynos4412 Bare Metal Development——IIC Bus
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号