code working in simulation but not working in hardware - Page 1
Forum section: electronics / general

author: ect_09
author_rank: Contributor
timestamp: November 15, 2014, 09:03:22 am
content: 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:#include<htc.h>__CONFIG(1,OSCSDIS & HSPLL);__CONFIG(2,PWRTDIS & WDTDIS & BORDIS);__CONFIG(3,CCP2RC1);__CONFIG(4,LVPDIS & STVREN);__CONFIG(5, UNPROTECT);__CONFIG(6,WRTEN);__CONFIG(7,TRU);void main(){TRISB4=1;TRISD=0;while(1){if(!RB4){PORTD=0x55;}else{LATD=0xFF;}}}

author: hans
author_rank: Super Contributor
timestamp: November 15, 2014, 04:42:26 pm
content: Your post is a bit vague, so I can only ask lots of questions with a chance we're still missing the whole picture:Can you program the PIC? If not, what programmer do you use?How do you power the PIC?Have you got decoupling capacitors on VDD/GND pins?Have you got a pull-up resistor on MCLR?Do you have got a crystal oscillator , as is defined in your fuse settings? The PIC18F452 does not have an internal oscillator!Make sure you "program" the PIC and not "debug" it - debug HEX files usually don't start without a debugger starting up.

author: janengelbrecht
author_rank: Regular Contributor
timestamp: November 15, 2014, 04:53:32 pm
content: Decent simulators like Labcenter Proteus ISIS will pick up those kind of errors.....but less expensive ones..no...Depends on how much/how deep they simulate...do they simulate a lot of hardware too ? Thats important.But these days i think you are better off by emulating : running the software on the actual hardware with breakpoints and access to register contents and so on....Mostly because of the complex circuits used...a lot of simulator packages just give up....CPU load 120%

author: ect_09
author_rank: Contributor
timestamp: November 15, 2014, 05:32:26 pm
content: i attached the image.

author: mikerj
author_rank: Super Contributor
timestamp: November 15, 2014, 06:12:26 pm
content: Quote from: ect_09 on November 15, 2014, 09:03:22 amThat's not a very useful description of the problem. Describe the actual symptoms. Is the code running at all?Also why are you writing to the PORTD register for one part of the if condition, but writing to the LATD register for the other?

author: janengelbrecht
author_rank: Regular Contributor
timestamp: November 15, 2014, 06:32:04 pm
content: PickIt 2 & 3 and you can emulate, program and the hole lot....use proper toolshttp://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=PG164130&utm_source=&utm_medium=MicroSolutions&utm_term=&utm_content=&utm_campaign=PICkit+3

author: Unknown
author_rank: Unknown
timestamp: November 16, 2014, 08:23:34 am
content: Have you had code running successfully with that chip on your board before?I can't see any caps on your crystal - is it oscillating?What speed is your crystal?

author: bookaboo
author_rank: Frequent Contributor
timestamp: November 17, 2014, 09:54:49 am
content: Yep you need caps from the pins of the osc to ground, will depend on the frequency and osc spec but 22pf is a good guess.Also, I'd avoid simulation software, especially microchips. Much better to pick up something like a PICKIT3 or something along those lines.