code working in simulation but not working in hardware

Discussion in 'Embedded Systems and Microcontrollers' started by ect_09, Nov 15, 2014.

  1. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    Hello,
    I am using PIC18F452 with MPLAB and HI-TECH compiler.
    i write this code that take input and show the corresponding output. simulation showing that its working OK,
    but when burn the hex file not taking the input.
    Code (Text):
    1. #include<htc.h>
    2.  
    3. __CONFIG(1,OSCSDIS & HSPLL);
    4. __CONFIG(2,PWRTDIS & WDTDIS & BORDIS);
    5. __CONFIG(3,CCP2RC1);
    6. __CONFIG(4,LVPDIS & STVREN);
    7. __CONFIG(5, UNPROTECT);
    8. __CONFIG(6,WRTEN);
    9. __CONFIG(7,TRU);
    10.  
    11.  
    12.  
    13. void main()
    14. {
    15. TRISB4=1;
    16. TRISD=0;
    17.  
    18. while(1)
    19. {
    20.    
    21. if(!RB4)
    22. {
    23. PORTD=0x45;
    24. }
    25. else
    26. {
    27. LATD=0xFF;
    28. }
    29. }
    30. }
    31.  
    32.  
    33.  
    34.  
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    That's a pretty good choice for a PIC to begin with. I keep seeing people trying to use near obsolete 16F devices, probably because 10 year old web sites still list them.

    Anyway, the only thing I wish for you was to have chosen a PIC with an internal oscillator. That is a good default to have in your back pocket as it works without any external parts. That's handy when getting the thing to work the first time.

    When you burned the hex file, what did you use? Did it report success?

    What hardware do you use? Got a schematic? Got a picture of the build to show?

    Any further information you can give will help with clues to fix this.
     
  3. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i used ICSP and its report successful

    the picture has been uploaded
    2.png

    IMG_20141115_212039.jpg IMG_20141115_212045.jpg
     
  4. nerdegutta

    Moderator

    Dec 15, 2009
    2,517
    785
    No caps at the crystal?

    I'd redo the section in the if brackets.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Ouch... clone programmers can't be used for in circuit debugging. Oh well....

    Do you have a schematic? That's my next step to inspect.
     
Loading...