• AVR Freaks

Hot!Read & Write HEF of PIC10F322

Author
K.Sakai
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2020/09/29 03:38:28
  • Location: 0
  • Status: offline
2020/09/29 17:49:47 (permalink)
0

Read & Write HEF of PIC10F322

Hi,
 
I am going to Read & Write HEF of PIC10F322.
Is there any library or tutorial for PIC10F ?
 
I try to use PIC16 library of AN1673,
Chnging resistor address as attached but it does not work as following.
 
Could I get any advise ?
 
Error Description
//////////////////////////////////////////////////////////////////////////////////////////////////////////
 
(908) exit status = 1
2 warnings generated.
nbproject/Makefile-default.mk:219: recipe for target 'build/default/production/Flash.p1' failed
make[2]: *** [build/default/production/Flash.p1] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory 'C:/Users/kisk-ski/MPLABXProjects/LED.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/kisk-ski/MPLABXProjects/LED.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
K.Sakai

Attached Image(s)

#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28691
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read & Write HEF of PIC10F322 2020/09/30 21:31:44 (permalink)
    +2 (2)
    You seem to have had a compilation error, but you only showed the end of the build log, so we can't see the error message.
     
    I have no idea how to do it with MCC. It shouldn't be too hard to just access it directly following the procedure documented in the PIC10F322 datasheet.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Howard Long
    Super Member
    • Total Posts : 837
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: online
    Re: Read & Write HEF of PIC10F322 2020/10/02 09:13:32 (permalink)
    +2 (2)
    Here's some example code that toggles the duty cycle of and LED on RA2 each time it's reset (any reset, POR, MCLR etc).
     
    As ric suggests, I wouldn't touch MCC with a barge pole for something like this, it just adds complexity unnecessarily.
     
    Another thing you may find beneficial is a debug header (AC244045 in this case) as production PIC10s have no hardware debug.
     

     

    // PIC10F322 Configuration Bit Settings
     
    // 'C' source line config statements
     
    // CONFIG
    #pragma config FOSC = INTOSC // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled)
    #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
    #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
    #pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
    #pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
    #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
    #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
    #pragma config LPBOR = OFF // Brown-out Reset Selection bits (BOR disabled)
    #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
    #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
     
    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.
     
    #include <xc.h>
    #include <stdint.h>
    #include <stdbool.h>
    #define _XTAL_FREQ 31000
    #define FLASH_ROW_SIZE 16
    #define FLASH_BASE_ADDRESS 0x180
    #define FLASH_SIZE 128
     
    // Reserve HEF area, don't access HEF data with this identifier!
    const uint8_t _au8FlashReserve[FLASH_SIZE] __at(FLASH_BASE_ADDRESS);
     
    // RAM buffer for flash row read & write
    uint16_t _au16FlashBuffer[FLASH_ROW_SIZE];
     
    void FlashReadRow(uint16_t u16Addr)
    {
    uint16_t *pu16=_au16FlashBuffer;
    int i;

    PMADR=u16Addr;

    for (i=FLASH_ROW_SIZE;i>0;i--)
    {
    PMCON1bits.CFGS=0;
    PMCON1bits.RD=1;
    NOP();
    NOP();

    *pu16++=PMDAT;
    PMADR++;
    }
    }
     
    void FlashEraseRow(uint16_t u16Addr)
    {
    bool bGIESave=INTCONbits.GIE;

    INTCONbits.GIE=0;
    PMADR=u16Addr;
    PMCON1bits.CFGS=0;
    PMCON1bits.FREE=1;
    PMCON1bits.WREN=1;
     
    PMCON2=0x55; // Unlock sequence
    PMCON2=0xAA;
    PMCON1bits.WR=1;
    NOP();
    NOP();
     
    PMCON1bits.WREN=0;
    if (bGIESave)
    {
    INTCONbits.GIE=1;
    }
    }
     
    static void FlashWriteRow(uint16_t u16Addr)
    {
    uint16_t *pu16=_au16FlashBuffer;
    bool bGIESave=INTCONbits.GIE;
    int i;
     
    INTCONbits.GIE=0;
    PMCON1bits.CFGS=0;
    PMADR=u16Addr;
    PMCON1bits.FREE=0;
    PMCON1bits.LWLO=1;
    PMCON1bits.WREN=1;
     
    for (i=FLASH_ROW_SIZE;i>0;i--)
    {
    PMDAT=*pu16++;
    if (i==1)
    {
    PMCON1bits.LWLO=0; // Last byte of row
    }
    PMCON2=0x55; // Unlock sequence
    PMCON2=0xAA;
    PMCON1bits.WR=1;
    NOP();
    NOP();
    if (i!=1)
    {
    PMADR++; // Not last byte of row
    }
    }
     
    PMCON1bits.WREN=0;
    if (bGIESave)
    {
    INTCONbits.GIE=1;
    }
    }
     
    int main(void)
    {
    OSCCONbits.IRCF=0b0000; // 0b000 => Fosc=31kHz
    LATAbits.LATA2=0;
    TRISAbits.TRISA2=0;

    // Toggle state after each reset
    FlashReadRow(FLASH_BASE_ADDRESS);
    if (_au16FlashBuffer[0]!=0)
    {
    _au16FlashBuffer[0]=0;
    }
    else
    {
    _au16FlashBuffer[0]=1;
    }
    FlashEraseRow(FLASH_BASE_ADDRESS); // Erase & write back new state
    FlashWriteRow(FLASH_BASE_ADDRESS);

    // Flash LED on RA2 with duty cycle depending on state stored in flash
    while (1)
    {
    LATAbits.LATA2=1;
    if (_au16FlashBuffer[0]!=0)
    {
    __delay_ms(250);
    }
    else
    {
    __delay_ms(50);
    }
    LATAbits.LATA2=0;
    if (_au16FlashBuffer[0]!=0)
    {
    __delay_ms(50);
    }
    else
    {
    __delay_ms(250);
    }
    }
    return 0;
    }
     

    post edited by Howard Long - 2020/10/02 12:39:36
    #3
    Jim Nickerson
    User 452
    • Total Posts : 6755
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Read & Write HEF of PIC10F322 2020/10/02 10:41:21 (permalink)
    +1 (1)
    I see MCC supports PIC10F322
    I also see a "MEMORY" Peripheral, which adds "FLASH_ReadWord" and "FLASH_WriteWord"
    Examples of usage is in Header Files, MCC Generated Files, memory.h
    To read/write HEF memory set the "flashAddr" paramater to an address in the range specified 
     
     

    Attached Image(s)

    #4
    K.Sakai
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2020/09/29 03:38:28
    • Location: 0
    • Status: offline
    Re: Read & Write HEF of PIC10F322 2020/10/04 18:52:35 (permalink)
    0
    Thank you Everyone,
    I will try to use example code you sent and check memory library code on MCC.
     
    K.Sakai
     
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5