• AVR Freaks

Hot!PIC 12F1571 reprogram

Page: 1234 > Showing page 1 of 4
Author
Moondust
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/03/16 13:58:38
  • Location: 0
  • Status: offline
2020/03/17 14:36:05 (permalink)
0

PIC 12F1571 reprogram

Hello
 
i'm trying to make some changes in the firmware of a PIC 12F1571. But i've got some problems.
So now i'm first trying to build a working .hex file starting from the original .c file.
 
This is what i have:
Original .c file
Original .hex file (read out from a working controller)
Original configuration file
 
i've used the original .c file in Mplab ide and build a .hex file from it.
Then i flashed this .hex file in my pic controller with a Snap programmer.
 
Result: my controller does nothing and is dead.
So i flashed the original .hex file in the controller and everything is working fine again.
 
So i think that the configuration bits aren't right???
 
I've also been comparing the configuration files and there are some difference between the original and mine (created using the original .c file)
 
The greatest difference is that the original is whith a pickit 3 and i use a Snap tool to flash the controller.
 
#1

69 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27697
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/18 12:25:57 (permalink)
    +1 (1)
    Moondust
     
    So i think that the configuration bits aren't right???

    Maybe you are right, but we can only guess, as you have shown zero code.
    Post your code and we would have a chance of commenting.
    Also, which C compiler was the original compiled with, and which are you using?
    There are BIG differences between XC8 v1.xx and XC8 v2.xx
     

    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
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/18 13:29:44 (permalink)
    0
    Hello
     
    thanks for the reply.
    I had some issues with posting yesterdat so my first post wasn't complete.
    This is the rest.
     
    Other difference are:
     
    Original                                                                               Mine
    <configurationDescriptor version="62">                                                                             <configurationDescriptor version="65">
    <itemPath>main.c</itemPath>                                                                                         <itemPath>../../pixie-master/software/main.c</itemPath>
          <itemPath>read.asm</itemPath>
     <itemPath>Makefile</itemPath>
    <platformTool>PICkit3PlatformTool</platformTool>                                                           <platformTool>snap</platformTool>
    <languageToolchainVersion>1.31</languageToolchainVersion>                                           <languageToolchainVersion>2.05</languageToolchain
    parseOnProdLoad>true</parseOnProdLoad>                                                                      <parseOnProdLoad>false</parseOnProdLoad>
                                                                                                     <property key="additional-warnings" value="true"/>
                                                                                                                                           <property key="default-bitfield-type" value="true"/>
                                                                                                                                           <property key="default-char-type" value="true"/>
                                                                                                                                           <property key="disable-optimizations" value="true"/>
                                                                                                                                           <property key="favor-optimization-for" value="-speed,+space"/>
                                                                                                                                           <property key="garbage-collect-data" value="true"/>
                                                                                                                                           <property key="garbage-collect-functions" value="true"/>
                                                                                                                                           <property key="local-generation" value="false"/>
    <property key="optimization-global" value="true"/>
    <property key="optimization-level" value="9"/>                                                                 <property key="optimization-level" value="-O0"/>
    <property key="optimization-set" value="default"/>
                                                                                                                                          <property key="optimization-stable-enable" value="false"/>
                                                                                                                                          <property key="pack-struct" value="true"/>
                                                                                                                                          <property key="short-enums" value="true"/>
    <property key="warning-level" value="0"/>                                                                      <property key="warning-level" value="-3"/>
    <property key="calibrate-oscillator" value="true"/>                                                           <property key="calibrate-oscillator" value="false"/>
    <property key="calibrate-oscillator-value" value=""/>                                                        <property key="calibrate-oscillator-value" value="0x3400"/>
    <property key="data-model-size-of-double" value="24"/>                                                   <property key="data-model-size-of-double" value="32"/>
    <property key="data-model-size-of-float" value="24"/>                                                     <property key="data-model-size-of-double-gcc" value="no- short-double"/>
                                                                                                                                          <property key="data-model-size-of-float" value="32"/>
     
                                                                                                    <property key="data-model-size-of-float-gcc" value="no-short-                                                                                                                                       float"/>
    <property key="link-in-peripheral-library" value="true"/>                                                   <property key="link-in-c-library-gcc" value="-mc90lib"/>
                                                                                                                                          <property key="link-in-peripheral-library" value="false"/>
     
    <PICkit3PlatformTool>                                                                                                     <XC8-CO>
                                                                                                                                          <property key="coverage-enable" value=""/>
                                                                                                                                           </XC8-CO>
                                                                                                                                           <XC8-config-global>
                                                                                                                                          <property key="advanced-elf" value="true"/>
                                                                                                                                          <property key="gcc-opt-driver-new" value="true"/>
                                                                                                                                          <property key="gcc-opt-std" value="-std=c99"/>
                                                                                                                                          <property key="gcc-output-file-format" value="dwarf-3"/>
                                                                                                                                          <property key="omit-pack-options" value="false"/>
                                                                                                                                          <property key="output-file-format" value="-mcof,+elf"/>
                                                                                                                                          <property key="stack-size-high" value="auto"/>
                                                                                                                                          <property key="stack-size-low" value="auto"/>
                                                                                                                                          <property key="stack-size-main" value="auto"/>
                                                                                                                                           <property key="stack-type" value="compiled"/>
                                                                                                      <property key="user-pack-device-support" value=""/>
                                                                                                                                           </XC8-config-global>
                                                                                                                                           <snap>
    <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
    <property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>                              <property key="ToolFirmwareOption.UpdateOptions"
    <property key="hwtoolclock.frcindebug" value="false"/>                                                                                                   value="ToolFirmwareOption.UseLatest"/>
                                                                                                                                            <property key="communication.interface"
                                                                                                                                                                                      value="${communication.interface.default}"/>
                                                                                                                                            <property key="communication.interface.jtag" value="2wire"/>
                                                                                                                                            <property key="communication.speed" value="${communication.speed.default}"/>
                                                                                                                                            <property key="debugoptions.useswbreakpoints" value="false"/>
    <property key="memories.bootflash" value="false"/>                                                         <property key="memories.bootflash" value="true"/>
    <property key="memories.configurationmemory" value="false"/>                                        <property key="memories.configurationmemory" value="true"/>
    <property key="memories.eeprom" value="false"/>                                                            <property key="memories.configurationmemory2" value="true"/>
                                                                                                                                           <property key="memories.dataflash" value="true"/>
                                                                                                                                           <property key="memories.eeprom" value="true"/>
                                                                                                                                           <property key="memories.exclude.configurationmemory" value="true"/>
    <property key="memories.programmemory.end" value="0x3ff"/>                                         <property key="memories.programmemory.ranges" value="0-3ff"/> 
    <property key="memories.programmemory.start" value="0x0"/>
     <property key="poweroptions.powerenable" value="false"/>
    <property key="programmertogo.imagename" value=""/>
    <property key="programoptions.pgmspeed" value="2"/>                                                        <property key="programoptions.pgmentry.voltage" value="low"/>
                                                                                                                                               <property key="programoptions.pgmspeed" value="Min"/>
                                                                                                                                                <property key="programoptions.preservedataflash"value="false"/>
                                                                                                                                                <property key="programoptions.preservedataflash.ranges"
                                                                                                                                                                                value="${memories.dataflash.default}"/>
                                                                                                                                                <property key="programoptions.preserveeeprom.ranges" 
                                                                                                                                            value=""/>
                                                                                                                                                  <property key="programoptions.preserveprogram.ranges"
                                                                                                                                                                                             value=""/>
    <property key="programoptions.preserveprogramrange.end" value="0x3ff"/>                           <property key="programoptions.programcalmem"
                                                                                                                                                                                                 value="false"/>
    <property key="programoptions.preserveprogramrange.start" value="0x0"/>                           <property key="programoptions.programuserotp" 
                                                                                                                                          value="false"/>
    <property key="programoptions.preserveuserid" value="false"/>                                             <property key="programoptions.testmodeentrymethod" 
                                                                                                               value="VDDFirst"/>
      <property key="programoptions.testmodeentrymethod" value="VPPFirst"/>                            </snap>
    <property key="programoptions.usehighvoltageonmclr" value="false"/>
     <property key="programoptions.uselvpprogramming" value="true"/>
    <property key="voltagevalue" value="5.0"/>
     </PICkit3PlatformTool>
     <XC8-config-global>
     <property key="advanced-elf" value="true"/>
      <property key="output-file-format" value="-mcof,+elf"/>
     <property key="stack-size-high" value="auto"/>
     <property key="stack-size-low" value="auto"/>
      <property key="stack-size-main" value="auto"/>
      <property key="stack-type" value="compiled"/>
     </XC8-config-global>
     
    This are the difference between the 2 files. Open places means not in the file.
     
    Is there somebody who can point me in the right direction so i can built a working hex file from the original .c file?? Then i can start making my own program.
     
    So i hope this will help.
    Best regards
    #3
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/18 13:32:57 (permalink)
    0
    Oh a last remark
    The Original file was compiled in 2016.
     
    Best regards
    #4
    ric
    Super Member
    • Total Posts : 27697
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/18 14:38:07 (permalink)
    +2 (2)
    You still have not posted any of your C code.
    All you have posted is a configuration XML file for MPLABX.
    We need to see the C code containing your main() function and your PIC configuration bit settings.
     
     

    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!
    #5
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/18 15:03:49 (permalink)
    0
    // PIC12F1571 Configuration Bit Settings

    // 'C' source line config statements

    // CONFIG1
    #pragma config FOSC = ECH // (ECH, External Clock, High Power Mode (4-32 MHz); device clock supplied to CLKIN pin)
    #pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled)
    #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
    #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
    #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
    #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
    #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)

    // CONFIG2
    #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
    #pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
    #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
    #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
    #pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled)
    #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)

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

    #include <xc.h>

     
    C-code
    #include <stdbool.h>
    #include <stdint.h>

    #include <xc.h>

    #pragma config FOSC = INTOSC, WDTE = ON, CP = OFF, PLLEN = ON, BOREN = OFF, MCLRE = ON, CLKOUTEN = OFF, PWRTE = OFF, LPBOREN = ON,

    #define DIN_PIN_MASK (1 << 5)
    #define DOUT_PIN_MASK (1 << 4)
    #define RED_PIN_MASK (1 << 0)
    #define GREEN_PIN_MASK (1 << 1)
    #define BLUE_PIN_MASK (1 << 2)
    #define RGB_PIN_MASK (RED_PIN_MASK | GREEN_PIN_MASK | BLUE_PIN_MASK)

    // How long of a silence on the line is considered a latch event.
    // Units are 32[us] per count.
    #define LATCH_TIME 30

    // To convert this value to real temperature (in Celcius):
    // T = K -temperature * 1.5151515, where K is some calibration constant,
    // typically around 320.
    static uint8_t temperature;
    static uint8_t max_temp;

    static uint8_t r, g, b;
    uint8_t color_array[24];
    volatile uint8_t bit_count;

    static void InitializePwm() {
      // Fosc, no prescaler = 32MHz. Full cycle will be: 32MHz / 2^16 = 488Hz
      PWM1CLKCON = 0;
      PWM2CLKCON = 0;
      PWM3CLKCON = 0;

      // Set the period to 2^16
      PWM1PRH = PWM1PRL = 0xFF;
      PWM2PRH = PWM2PRL = 0xFF;
      PWM3PRH = PWM3PRL = 0xFF;

      // Set the phase to 0.
      PWM1PHH = PWM1PHL = 0;
      PWM2PHH = PWM2PHL = 0;
      PWM3PHH = PWM3PHL = 0;

      // Set the offset to 0.
      PWM1OFH = PWM1OFL = 0;
      PWM2OFH = PWM2OFL = 0;
      PWM3OFH = PWM3OFL = 0;

      // Set the duty cycle to 0.
      PWM1DC = 0;
      PWM2DC = 0;
      PWM3DC = 0;

      // Latch the values on next trigger.
      PWMLD = 0x07;

      // Enable the output pins.
      PWM1CON = 0x40;
      PWM2CON = 0x40;
      PWM3CON = 0x40;

      // Enable all PWM modules.
      PWMEN = 0x07;
    }

    static void InitializePins() {
      // Disable analog inputs.
      ANSELA = 0;
      // All outputs but Dout are low.
      LATA = DOUT_PIN_MASK;
      // Weak pull-up on Din.
      WPUA = DIN_PIN_MASK;
      // Schmidt-trigger input on Din.
      INLVLA = DIN_PIN_MASK;
      // Set the output pins as output.
      TRISA = ~(RGB_PIN_MASK | DOUT_PIN_MASK);
    }

    static void InitializeTimers() {
      // Timer 0 : Instruction clock / 256 = 31.25kHz (32us).
      OPTION_REG = 0x07;

      // Timer 1: Instruction clock / 8 = 1MHz (1us).
      T1CON = 0x31;

      // Timer 2: Instruction clock / 16 = 500kHz (2us).
      T2CON = 0x06;
    }

    static void InitializeTemperature() {
      // Enable temperature indicator at high range and FVR.
      FVRCON = 0xB0;

      // Configure ADC.
      ADCON2 = 0x00;
      // Left-aligned, Tad = 1us.
      ADCON1 = 0x20;

      // Wait for FVR to settle.
      while (!FVRRDY);
    }

    static inline void Timer1Delay(uint16_t count) {
      TMR1 = 0;
      while (TMR1 < count);
    }

    static inline uint16_t AcquireTemperature() {
      // Configure the ADC to acquire the temperature indicator.
      ADCON0 = 0x75;

      // Wait for acquisition (200us).
      Timer1Delay(200);

      // Sample.
      GO = 1; // Start.
      while (GO); // Wait completion.

      return ADRES;
    }

    static inline uint16_t AcquireVref() {
        // Enable the FVR amplifier (2x)
      FVRCON = 0xB2;

      // Configure the ADC to acquire the FVR.
      ADCON0 = 0x7D;

      // Wait for acquisition (50us).
      Timer1Delay(50);

      // Sample.
      GO = 1; // Start.
      while (GO); // Wait completion.

      // Disable the FVR amplifier.
      FVRCON = 0xB0;

      return ADRES;
    }

    static void ReadTemperature() {
      uint16_t v1 = AcquireVref();
      uint16_t t = AcquireTemperature();
      uint16_t v2 = AcquireVref();

      // Turn ADC off.
      ADCON0 = 0;

      uint8_t vavg = ((v1 >> 1) + (v2 >> 1) + 128) >> 8;
      temperature = (0xFFC0 - t) / vavg - 200;
    }

    static void ConvertColor() {
      r = g = b = 0;

      // Note the the temperature units used are reversed: bigger number == lower
      // temperature. So the condition below actually means temp <= max_temp.
      if (temperature >= max_temp && bit_count == 1) {
        uint8_t i;
        uint8_t const * p = color_array;

        // Read Red bits.
        for (i = 0; i < 8; ++i) {
          r |= ((*p++ >> 5) & 1) << i;
        }

        // Read Green bits.
        for (i = 0; i < 8; ++i) {
          g |= ((*p++ >> 5) & 1) << i;
        }

        // Read Blue bits.
        for (i = 0; i < 8; ++i) {
          b |= ((*p++ >> 5) & 1) << i;
        }
      }
    }

    static void LatchColor() {
      // Prepare the new values in the PWM periods.
      PWM1DC = (uint16_t) g * g;
      PWM2DC = (uint16_t) r * r;
      PWM3DC = (uint16_t) b * b;

      // Latch all at once.
      PWMLD = 0x07;
    }

    static inline void SerialSend(uint8_t b) {
      // Start bit.
      LATA &= ~DOUT_PIN_MASK;
      Timer1Delay(99);
      for (unsigned i = 0; i < 8; ++i) {
        if (b & 1) {
          LATA |= DOUT_PIN_MASK;
        } else {
          LATA &= ~DOUT_PIN_MASK;
        }
        b >>= 1;
        Timer1Delay(99);
      }
      // Stop bit.
      LATA |= DOUT_PIN_MASK;
      Timer1Delay(99);
    }

    static uint8_t ReadMaxTemperature() {
      PMADR = 0x8000;
      CFGS = 1;
      RD = 1;
      asm("nop\nnop\n");
      return PMDATL;
    }

    void main() {
      // High speed.
      OSCCONbits.IRCF = 0xe;

      InitializePwm();
      InitializePins();
      InitializeTimers();
      InitializeTemperature();

      max_temp = ReadMaxTemperature();
      if (max_temp == 0xFF) {
        for (;;) {
          ReadTemperature();
          SerialSend(temperature);

          CLRWDT();
          Timer1Delay(1000);
        }
      }

      // Enable interrupts on any edge of DIN.
      IOCAP5 = 1;
      IOCAN5 = 1;
      IOCIE = 1;

      // Wait for silence. Do not take interrupts and do not set the output.
      TMR0 = 0;
      while (TMR0 < LATCH_TIME) {
        if (IOCAF5) {
          TMR0 = 0;
          IOCAF5 = 0;
        }
      }

      // Main loop.
      while (true) {
        // FSR0 needs to point to the beginning of the color array.
        FSR0 = (uint16_t) color_array;

        // And we have 24 bits left to read (+1, as 1 means done).
        bit_count = 25;

        // Ready to handle interrupts. Clear first.
        IOCAF5 = 0;
        GIE = 1;

        // Wait for read to start. The interrupt handler will decrement bit_count.
        while (bit_count == 25);

        // Then, wait for silence of LATCH_TIME. The interrupt handler will clear
        // timer 0 on every edge, so we'll get out of this loop only after
        // LATCH_TIME with no edges.
        TMR0 = 0;
        while (TMR0 < LATCH_TIME);

        // Disable interrupts while processing.
        GIE = 0;

        // Read the temperature. This should take ~400us.
        ReadTemperature();
      
        // Convert the color read by the interrupt handler.
        ConvertColor();

        // The color array not contains the 24 bits we've read. Latch.
        LatchColor();

        // Clear the watchdog.
        CLRWDT();
      }
    }

     
    Best regards
    #6
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 12:59:23 (permalink)
    0
    The C code is for controlling a led.
    But the problem is that i need to send every second data to the pic so that the led keeps lightning and the color the i want.
     
    So i was trying to remove the watchdog so that i can send 1 time the color and the brightness to the led and then i can do some other things but the led stays on.
     
    To control the pic i send data to it with a Arduino. This works fine.
     
    But now when i build a new hex file for the pic and flash it into the pic it doesn't react anymore on the Arduino.
    So i've build a hex file from the Original c file , but the result is the same.
    Now i try a recovered hex file from an other original pic and the test pic reacts back to the Arduino.
     
    So what goes wrong when i build the hex file??
     
    Best regards
    #7
    NorthGuy
    Super Member
    • Total Posts : 6179
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/19 13:17:56 (permalink)
    0
    I'm not sure how you compile it. The config that you have posted would normally be pasted into the C file instead of "#pragma config". Of course you need to keep only one "#inclide <xc.h>" while doing this.
     
    Your config post requires external clock ECH, while #pragma uses internal oscillator.
    #8
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11894
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 13:19:53 (permalink)
    +1 (1)
    Do you really have an external clock?  That's an unusual configuration.
    #9
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 13:39:40 (permalink)
    0

    I don't have an external clock signal
    #10
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11894
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 13:47:35 (permalink)
    +1 (1)
    So your generated configuration is incorrect, but the one in your code is correct.
    #11
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 13:51:25 (permalink)
    0
    NorthGuy
    I'm not sure how you compile it. The config that you have posted would normally be pasted into the C file instead of "#pragma config". Of course you need to keep only one "#inclide <xc.h>" while doing this.
     
    Your config post requires external clock ECH, while #pragma uses internal oscillator.


    The .c file i have posted is the Original file that i have found.
    I've pasted this .c file in MPlab X ide in the source file map and than build the hex file.
    #12
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/19 13:52:55 (permalink)
    0
    jtemples
    So your generated configuration is incorrect, but the one in your code is correct.


    Can you please give me some tips how i can make the right file?
    #13
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/20 11:05:40 (permalink)
    0
    NorthGuy
    I'm not sure how you compile it. The config that you have posted would normally be pasted into the C file instead of "#pragma config". Of course you need to keep only one "#inclide <xc.h>" while doing this.
     
    Your config post requires external clock ECH, while #pragma uses internal oscillator.


    Can you please give mo some more information about the "#pragma config" and the "#inclide <xc.h>".
    PIC controllers is a very long time ago that i used those. At the moment i use Arduino.
    #14
    NorthGuy
    Super Member
    • Total Posts : 6179
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/20 13:36:08 (permalink)
    0
    If the code you have was used to generate HEX in the past, then you don't need to modify it and you don't need to add any external configs. Just create a project, add the .c file and compile.
    #15
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/20 14:47:09 (permalink)
    0
    NorthGuy
    If the code you have was used to generate HEX in the past, then you don't need to modify it and you don't need to add any external configs. Just create a project, add the .c file and compile.


    That is what i've done, but then the controller doesn't react anymore to th Arduino and the led won't light up.
     
    I've created a new stand alone project, added the .c file to the Source file and compiled it.
    Then i took the hex file loaded inti mplab x ipe and flashed it into the pic using a Snap programmer.
     
    But the result wasn't great.
    #16
    ric
    Super Member
    • Total Posts : 27697
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/20 14:54:37 (permalink)
    0
    This line in your C file enables the MCLR pin

    #pragma config FOSC = INTOSC, WDTE = ON, CP = OFF, PLLEN = ON, BOREN = OFF, MCLRE = ON, CLKOUTEN = OFF, PWRTE = OFF, LPBOREN = ON,
     
    but I cannot see any pullup on the MCLR signal on your schematic.
    maybe change that to
    MCLRE = OFF
     

    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!
    #17
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/20 14:58:47 (permalink)
    0
    @Ric
     
    I have a pullup between the MCLR and the power pin on the Snap programmer.
    Otherwise i can't connect to the pic controller.
    #18
    ric
    Super Member
    • Total Posts : 27697
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC 12F1571 reprogram 2020/03/20 15:01:07 (permalink)
    0
    Does the programmer stay connected when your code should run?
     

    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!
    #19
    Moondust
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2020/03/16 13:58:38
    • Location: 0
    • Status: offline
    Re: PIC 12F1571 reprogram 2020/03/20 15:06:03 (permalink)
    -1 (1)
    No
     
    i make connection to the pic then program the pic, disconnect the programmer.
    Connect the pic to the Arduino and see what the result is.
     
    This way works fine when i use the readout hex file. But with the own compiled hex file it won't succeed.
    #20
    Page: 1234 > Showing page 1 of 4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5