RC3, RC4 and RC5 on PIC16F870

Discussion in 'Embedded Systems and Microcontrollers' started by Peca, Jan 18, 2011.

  1. Peca

    Thread Starter New Member

    Jun 7, 2008
    4
    1
    Hi!
    Look at the code:
    Code ( (Unknown Language)):
    1.  
    2. #include <htc.h>
    3.  
    4. __CONFIG(HS & WDTDIS & PWRTEN & BORDIS & LVPDIS);
    5.  
    6. /* Function: Wait()
    7.  Well, PIC16F870 is working at 20MHz so it means that the controller will execute 5 million instructions in one second. If we made loop to count up to 5 million, we will have delay of 1 (one) second.
    8. My board is Mikroelektronika EasyPIC3 with the previosly mentioned controller running at 20MHz. */
    9.  
    10. void Wait()
    11. {
    12.  for(int i=0;i<1000;i++) // Start counting up to 1000...
    13.   _delay(5000); // ... with 5000 instructions delay.
    14. }
    15.  
    16. void main()
    17. {
    18.   TRISC=0x00; // Port C is output...
    19.    PORTC=0xff; // ... and turn the all LED`s on...
    20.   while(1)
    21.   {
    22.     PORTC^=0xff; //... than turn them off.
    23.    Wait(); // Wait about one second.
    24.   }
    25. }
    26.  
    When I put it in PIC LED`s RC3, RC4 and RC5 are not flashing!!! The same thing is happening when I replace 870 with 877A.

    Can anybody explain where is the mistake?

    Peca.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  3. Peca

    Thread Starter New Member

    Jun 7, 2008
    4
    1
    Well,
    in MPLAB simulator everything seems O.K. but on board it does not work! I`d like for someone to test it on the same board to be shure that my board is not broken or so.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your program structure look ok, like you have included the htc.h file. Have you tested a simple hello word program. That will say a program that just turn on some LEDs. A simple program. But a good diagnose setup. Have you created a project file in MPLAB?
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,870
    996
    Do you have a logic analyzer, logic probe, volt meter or scope? If not get one of them.

    If so, that is the output of each of those pins doing?
     
  6. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Try __delay_ms(1000) instead of cycles, the compiler will decode the number of cycles needed for the delay.

    If you set TRISB to 0x0, and PORTB to 0xFF at the top of main, do all the PORTB LEDs come on?

    I posted code similar to this for BoostC which worked fine, and was pretty much the same as your code, with a smaller delay (100mS). Works fine (Ports B and C) with 16F877A on QL200 board.

    Make sure your config settings are correct at burn time as well. Sometimes you need to re-specify the clock source and disable watchdog timer when programming. Rare, but I always double check.

    --ETA: RC3, RC4, RC5 have no extra functions assigned, so it isn't a peripheral getting in the way.
     
    Last edited: Jan 18, 2011
  7. Peca

    Thread Starter New Member

    Jun 7, 2008
    4
    1
    Dear friends,

    you are so patient and kind! Thank you all!

    Where is the problem?
    In jumpers on my EasyPIC3!!!
    Before pic16F87x there were pic18F4550 and for him I had set jumpers for USB connector which is connected to RC3-RC5. I saw it just few minutes ago, chaged jumpers and evrything is O.K.

    Thank You all for Your time - shame on me :mad: !!!
     
Loading...