请教一下写用户ID的指令

[复制链接]
1270|17
 楼主| liuzaiy 发表于 2021-1-5 23:37 | 显示全部楼层 |阅读模式
用户ID地址是8000h~8003h,PIC8位单片机,请问写用户ID的指令是什么?
wangpe 发表于 2021-1-5 23:40 | 显示全部楼层
看看手册上有没有说
gongche 发表于 2021-1-5 23:44 | 显示全部楼层
static void eraseUserID(uint32_t addr)
{
    uint8_t GIEBitValue = INTCONbits.GIE;     // Save interrupt enable

    TBLPTRU = (uint8_t) ((addr >> 16) & 0xff);
    TBLPTRH = (uint8_t) ((addr >> 8) & 0xff);
    TBLPTRL = (uint8_t) (addr & 0xff);   
   
    EECON1bits.FREE = 1;
   
    EECON1bits.EEPGD = 1;
    EECON1bits.CFGS = 0;
    EECON1bits.WREN = 1;
   
    INTCONbits.GIE = 0; // Disable interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;  // Erase like the wind!
    INTCONbits.GIE = GIEBitValue;   // Restore interrupt enable
    EECON1bits.WREN = 0;    // Disable writes to memory   
}

static void writeUserID(uint8_t *flashWrBufPtr)
{
    int i;
    uint8_t GIEBitValue = INTCONbits.GIE;     // Save interrupt enable


    TBLPTRU = (uint8_t) 0x20;
    TBLPTRH = (uint8_t) 0;
    TBLPTRL = (uint8_t) 0;  
        
    // Write 3 bytes which uses 6 LOC cells (1 nibble each).

    TABLAT = (flashWrBufPtr[0] >> 4);
    asm("TBLWT*+");
    TABLAT = (flashWrBufPtr[0] & 0x0f);
    asm("TBLWT*+");
    TABLAT = (flashWrBufPtr[1] >> 4);
    asm("TBLWT*+");
    TABLAT = (flashWrBufPtr[1] & 0x0f);
    asm("TBLWT*+");
    TABLAT = (flashWrBufPtr[2] >> 4);
    asm("TBLWT*+");
    TABLAT = (flashWrBufPtr[2] & 0x0f);
    asm("TBLWT*");
   
    TBLPTRU = (uint8_t) 0x20;
    TBLPTRH = (uint8_t) 0;
    TBLPTRL = (uint8_t) 0;  
   
    EECON1bits.EEPGD = 1;
    EECON1bits.CFGS = 0;
    EECON1bits.WREN = 1;
   
    INTCONbits.GIE = 0; // Disable interrupts
    EECON2 = 0x55;
    EECON2 = 0xAA;
    EECON1bits.WR = 1;  // Write like the wind!
    INTCONbits.GIE = GIEBitValue;   // Restore interrupt enable
    EECON1bits.WREN = 0;    // Disable writes to memory   
}
wenfen 发表于 2021-1-5 23:48 | 显示全部楼层
用烧写器写
理论上也可以用写FLASH的函数来写
tian111 发表于 2021-1-5 23:51 | 显示全部楼层
但是,在程序运行过程中写这个地方,有什么意义呢?
xxrs 发表于 2021-1-5 23:55 | 显示全部楼层
你看datasheet上有相关userid的写入/读写说明的, 可以在代码中来操作..
 楼主| liuzaiy 发表于 2021-1-5 23:58 | 显示全部楼层
是想烧录的时候烧进去,找到部分答案了,可以用IDOCS来定义
 楼主| liuzaiy 发表于 2021-1-6 20:21 | 显示全部楼层
但是这只能写最后一位即000XH,前面三个数字不知道怎么写
renyaq 发表于 2021-1-6 20:25 | 显示全部楼层
你看IPE的user guide, 里面有关于这部分的说明的, 烧录的时候, 可以实现自动+1之类的操作...
 楼主| liuzaiy 发表于 2021-1-6 20:29 | 显示全部楼层
IPE是可以设置,看到了,谢谢。另外有一个问题,DEVICEID为什么不让改,改HEX烧了也一样没变,这样别人开盖不是很容易就**了吗?
chenjunt 发表于 2021-1-6 20:33 | 显示全部楼层
有没有方法可以擦写DEVICE ID的?
 楼主| liuzaiy 发表于 2021-1-6 20:36 | 显示全部楼层
或者破坏也行
yufe 发表于 2021-1-6 20:42 | 显示全部楼层
数据手册上应该有啊
zhanglli 发表于 2021-1-6 20:45 | 显示全部楼层
我还没有接触过这么深
 楼主| liuzaiy 发表于 2021-1-6 20:48 | 显示全部楼层

其实还是不大明白,我再琢磨琢磨吧,多谢了哈先
木木guainv 发表于 2021-2-4 12:37 | 显示全部楼层
是用的at指令吗
wakayi 发表于 2021-2-4 12:39 | 显示全部楼层
破坏的话还能恢复么
xiaoqizi 发表于 2021-2-4 12:40 | 显示全部楼层
设置完之后还能更改吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

735

主题

7546

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部