programming pic

Discussion in 'Embedded Systems and Microcontrollers' started by arashian1, Sep 9, 2016.

  1. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    PORTA.F0 = 0;
    delay_ms(650);
    PORTA.F0 =1;
    delay_ms(650);

    after excute program above the output pin is off

    PORTA.F0 = 1;
    delay_ms(650);
    PORTA.F0 =0;
    delay_ms(650);

    after excute program above the output is on but not blinking

    the program operated in proteus perfect and programmer show sucsess message after programming

    who knows what is wrong with this?

    programmer: PICKIT2
     
  2. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,889
    375
    Which PIC are you using?
    Which compiler are you using?
    Are you using MPLAB/MPLABX?
    Please show all the program before the snippet you give - config, includes, PIC setup, etc.
     
  3. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    compiler: mikro c pro
    programer and software: PICKIT3
    microcontroller: PIC16f877a & PIC16f84a
    oscilator: 16MHZ
     
    • PIC.pdf
      File size:
      125.7 KB
      Views:
      7
  4. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
     
    • PIC.pdf
      File size:
      272.5 KB
      Views:
      2
  5. Kjeldgaard

    Member

    Apr 7, 2016
    71
    16
    Is the used portbit set to digital I / O?
     
  6. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    with which register? but it operated correct in sofware simulation with proteus
     
  7. Kjeldgaard

    Member

    Apr 7, 2016
    71
    16
    ADCON1 in the datasheet "Analog-to-Digital (A/D) Converter module" section.
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    Is that the whole program? You need a loop to make it blink.
    Code (C):
    1.  while(1){
    2. PORTA.F0 = 1;
    3. delay_ms(650);
    4. PORTA.F0 =0;
    5. delay_ms(650);
    6. }
    As noted above by @Kjeldgaard (while I was typing) you have to set the port bits to DIGITAL from their default analog configuration. In the '877, that means writing 0x7 to ADCON1.
    FWIW, RA4 on both is open drain - it sinks only.
    From your description, it sounds like the LED is backwards.

    Show your complete code with configuration bit settings, IO initialization and what kind of oscillator you have connected to the chip.

    Good luck.
     
  9. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    what about pic1684a? it must set adcon1 too?
     
    • PIC.pdf
      File size:
      272.5 KB
      Views:
      1
  10. Kjeldgaard

    Member

    Apr 7, 2016
    71
    16
    By all PIC16 and PIC18 with ADC, you must initialize portbit to be used as digital I/O.
    But be aware that the registers do not have the same name across types.
     
  11. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    The 'F84 does not have an A/D converter so the pins are always digital. You still need to set up the IO (TRIS et. al.) to turn on output pins.
     
  12. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    but pic16f84a has no adc and i have same problem with it like pic16f877a
     
  13. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    i did
    TRISA = 0;
     
  14. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,889
    375
    Please give the whole source code.
    I don't fancy hand disassembling from the programming window.
     
  15. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    its whole source code
     
  16. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,889
    375
    You need to add this line immediately before the TRIS line:
    ADCON1 = 6;

    PS: This for the PIC16F877A
     
  17. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    but i used this source code for pic16f84a and this model has no ADC
     
  18. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    What oscillator are you using? Note that Proteus will simulate without an oscillator but the chip will not work without one. See section 6.1 'Configuration Bits' in the datasheet.

    You have no CONFIGURATION bits set - usually done with a #pragma in the C source. The default is an RC oscillator. If you use a crystal or external oscillator, you'll have to change the CONFIG bits.

    Don't forget proper power and to pull MCLR/ up as well.
     
  19. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,889
    375
    It does look, from your pictures from PICKIT2 (although you say you are using PICKIT3), that the config is set appropriately (for the '877A at least) though it is good practice to include those settings in the source file to ensure they are set correctly and to document them for the future.

    Do you have a pull-up resistor on /MCLR?
     
  20. arashian1

    Thread Starter Member

    Sep 9, 2016
    39
    0
    thanks
    i did not changed CONFIG bits but after connect MCLR to +5V it worked proper
    but for set clock source the register that must be change is CONFIG?
     
Loading...