简体   繁体   English

如何将值保存到PIC18?

[英]How to save values to PIC18?

I would like to store some values to my PIC18 then retain those values even if the power is lost or the unit is reset. 我想将一些值存储到PIC18,然后保留这些值,即使断电或设备复位也是如此。 An example of the values I would like to save would some something like those 4 digits, 0100. 我想保存的值的一个例子就是那些4位数,0100。

Any help would be appreciated! 任何帮助,将不胜感激!

Update : Would this be the way to go? 更新 :这是要走的路吗?

    unsigned char value;
    unsigned char DEEdata = 0x25;
    unsigned int  DEEaddr = 0x04;

    DataEEInit();
    dataEEFlags.val = 0;

    DataEEWrite(DEEdata,DEEaddr);
    value = DataEERead(DEEaddr);
    Nop();

In mikroc_for_PIC IDE simply you can use : 在mikroc_for_PIC IDE中,您可以使用:

EEPROM_write(_Addres,char); EEPROM_write(_Addres炭); char = EEPROM_Read(_Addres); char = EEPROM_Read(_Addres);

note that: after write it is best if you have delay about 20 ms. 请注意:写入后最好是延迟大约20 ms。

EEPROM in PIC micro-controllers can save data for long period of time. PIC微控制器中的EEPROM可以长时间保存数据。 PIC16F84 can store 64 bytes. PIC16F84可以存储64个字节。 It is not that much, but it can serve your purpose. 它不是那么多,但它可以满足你的目的。 A good description to how to write to and read from EEPROM in PIC16 is given in this link. 有关如何在PIC​​16中写入和读取EEPROM的详细说明,请参见此链接。

http://www.romux.com/tutorials/pic-tutorial/eeprom-data-memory http://www.romux.com/tutorials/pic-tutorial/eeprom-data-memory

If you use HIGH-TECH as compiler you can simply write and read from EEPROM (which is the only way for keep a value after power lost except FARM ICs) with below function: 如果您使用HIGH-TECH作为编译器,您可以使用以下功能简单地写入和读取EEPROM (这是除掉FARM IC之后保持功率值的唯一方法):

Write_b_eep
Read_b_eep

you can find these function from below directory if you install HIGH-TECH : 如果你安装HIGH-TECH你可以从下面的目录中找到这些功能:

...\HI-TECH Software\PICC-18\9.80\sources\plib\EEP

It takes a few milli-seconds for the data to write into EE. 将数据写入EE需要几毫秒。 If you look at https://en.wikipedia.org/wiki/EEPROM it explains the electrical and physical process of both erasing and writing and gives a time between 0.1 and 5mS to achieve this. 如果你看看https://en.wikipedia.org/wiki/EEPROM,它会解释擦除和写入的电气和物理过程,并给出0.1到5mS之间的时间来实现这一目标。 Write or find a micro-second delay routine (hint the timers are good for this) Change your code to 写入或找到微秒延迟例程(提示定时器对此有利)将代码更改为

unsigned char value;
unsigned char DEEdata = 0x25;
unsigned int  DEEaddr = 0x04;

DataEEInit();
dataEEFlags.val = 0;

DataEEWrite(DEEdata,DEEaddr);
wait_us(5000); // Wait 5mS.... data takes a while to burn into EE
value = DataEERead(DEEaddr); // now its available to read

The EEPROM write function, is a bit `fire and forget'. EEPROM写入功能有点“火上浇油”。 You command it to write and it gets on with it in the background. 你命令它写,然后在后台继续它。 If you read too quickly after writing you are not guaranteed the value you might expect. 如果您在写作后读得太快,则无法保证您可能期望的价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM