My code does not work. Any help?
Submitted By: Jan Waclawek FAQ Last Modified: 07/16/06
- (with many of the following originally by Andy Neil)
- Have a good sleep
- Tell it to the teddy bear
- If your hypothesis is correct, you have identified the problem, and can then work on fixing it;
- If your hypothesis is not correct, you need to form another - maybe re-check your Observations
- state what is your hardware (including the exact type of the microcontroller)
- present only the shortest version of program which exhibits the problem (leave out irrelevant parts); but give complete program, so that other participants can verify it by compliling/assembling
- present a thoroughtly commented program (see the FAQ for proper commenting)
- state, what is the expected behaviour, and what is the reality
- consider attaching the resulting hex/binary file
- make sure your hardware works
- check the power - check directly on the appropriate pins, if you have actually connected both GND and VCC
- check the clock (using oscilloscope or counter)
- check the reset - especially RC resets are known to produce "funny" and unpredictible results, so use a proper reset IC
- check the power - check directly on the appropriate pins, if you have actually connected both GND and VCC
- check the "executable" is in the code memory: read it back or verify
- check you really assembled/compiled those source files you intended; and you "burned" really the file which resulted from that assembling/compilation
- try some rudimentary "known good" code snippet
First, a couple of surprising hints:
More scientific approach to debugging:
1. Observe
Observe precisely what the system does - just saying, "it doesn't work" helps nobody!
2. Form a Hypothesis
ie, construct a theory to explain the observed behaviour
3. Test your Hypothesis
Devise an "experiment" that will verify whether your hypothesis is correct or not:
If you are desperate and want to ask for help - for example in the 8052.com Forum - don't forget to:
There is a FAQ for the newbies by Jon Ledbetter, with some guidelines on how to post questions to 8052.com Forum so that you get prompt and relevant answers.
A few more hints, for case when "it does nothing":
snippet: blinky
Submitted By: Jan Waclawek FAQ Last Modified: 07/16/06
;Name: Blinkey ; ;What does it do: Blinks with a LED ; ;What if it does not blink: See "Basic troubleshooting FAQ" ; ;Required hardware: ;- any '51 with reset, clock (crystal), power supply connected ;- if code in internal memory (FLASH), don't forget to connect ; /EA to VCC ;- one LED, cathode to port pin (see HW dependent code), ; anode via a series resistor (300 Ohm - 1kOhm) connected to VCC ; ;Reference assembler: asm51 from metalink webpage ;for other assemblers remove the following line ; (causes a "duplicate definition" or similar error) P3 EQU 0B0h ; ; ;HW dependent code Pin EQU P3.0 ;pin, where LED is connected Timing EQU 4 ;using this value, it flashes approx. 1/sec on 12-clock '51 @ 12MHz ;on slightly faster hardware (e.g. 6-clocker at 20MHz) ; should work, but blinks faster ;on significantly faster hardware, increase this value ; appropriately, as too fast blinking might seem ; as if LED is continouosly ON ;code main ;ORG 0 and/or CSEG omitted for simplicity - most asms have these as default ; X0: cpl Pin ;toggle LED state mov r2,#Timing ;load timing value X1: djnz r0,X1 ;timing done by simple nested loops djnz r1,X1 ; - not precise, but good for blinkey djnz r2,X1 sjmp X0 end
The resulting "reference" hex:
:0C000000B2B07A04D8FED9FCDAFA80F421 :00000001FF
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.