打印

PIC12F1822的EEPROM问题求助

[复制链接]
582|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
a511484095|  楼主 | 2020-7-28 16:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 a511484095 于 2020-7-28 16:33 编辑

请问一下各位前辈,这个EEPROM我这样写AN2口可以正常输出。
但是为什么第二次烧录的时候,我注释掉了写代码,就不能正常读了捏。
不是说EEPROM是掉电后数据不会清除吗?
我也没有对EEPROM再进行写操作呀0.0


// PIC12F1822 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FOSC = INTOSC        // Oscillator Selection (HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF       // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
#pragma config STVREN = OFF     // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>



void EE_W(unsigned char data,unsigned char addr)//EEPROM写配置
{
    EEDAT=data;
    EEADR=addr;
    EECON2=0x55;
    EECON2=0xAA;
    EECON1bits.WR=1;
   
    EECON1=0x07;
    while(EECON1bits.WR==1);
   
}

unsigned char EE_R(unsigned char addr)//EEPROM读配置
{
    unsigned char rec;
    EEADR=addr;
    EECON1bits.RD=1;
    while(EECON1bits.RD==1);
    rec=EEDATA;
    return rec;
}
void main(void)
{
    OSCCON=0x6A;//内部时钟4MHZ
    TRISA=0x0;
//    ANSELA=0x0;
   
    int num,rec;
    for(;;)
    {
        for(num=10;num>0;num--)
        {
            EE_W(num,num+1);
        }
        if(EE_R(8)==7)PORTA=0x02;//判断第八字节是7否,是则AN2口输出1
        else PORTA=0;
    }
}


使用特权

评论回复

相关帖子

沙发
madboy21| | 2020-7-29 12:33 | 只看该作者
有可能你编程时选择了擦除EE。
我之前写过16F1786,这记得可以这样定义:eeprom  unsigned char i;  读出:x = i;  写入:i = x;

使用特权

评论回复
板凳
madboy21| | 2020-7-29 12:42 | 只看该作者
之前没看规格书,也不知道其实EEPROM操作是很复杂的,只是这个工作由编译器完了。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

126

帖子

0

粉丝