Hi,
my program:
EP: MOV A,ADC0H CJNZ A,#175D,EP
i have problem jumping to the next subrountine
when i detect 1.75V from power supply it will start to display if not it will display 0V
any advice?
My guess is that this is a school project.
Are you required to use assembler?
It is quite obvious that you are not comfortable with assembler and I feel that it will take a significant time for you to learn it. Assembler isn't the easiest to learn.
I have pointed out the problem with infinite loops in earlier posts. If you do a compare while waiting for something, the loop must also contain the sampling of new values, or the software will always lock up.
Comparing for higher or lower can be implemented by comparing the retrieved value with a constant. Then you can use a conditional jump depending on the affected flags - and the processor (all processors) have more flags than just the Z (zero) flag. Look for borrow/carry/sign flags.
Also, whatever language you use, you should try to create submodules/functions to help you out. You have a routine called 'DISPLAY'. Maybe it should be called 'DISPLAY_CHAR' since it only emits a single character. I would recommend you to also create a 'DISPLAY_STR' routine, to avoid the long MOV A,#xx/DISPLAY sequences.
Why do your code have a line:
POLL2: CJNE A,00H,ZERO
Compare the retrieved ADC value, and jump to a routine ZERO if the ADC value was NOT zero. Does that make sense? And what use is it to compare with the value 0 if your code is expected to treat all values below 1.75V as zero?
Why do you have several places in the code that reads the ADC value? Shouldn't you just do it at a single place, and then decide what display code to jump to. After displaying anything, returning back to the ADC read code again to get a new sample?
What do you think the following line does (already mentioned in a previous post):
EP: CJNE A,#4BH,EP
Depending on the value in A, the processor can take the jump, or it can continue to the next instruction. If it does take the jump, where will it jump? How many times will it continue to take this jump? Will it ever break this loop?
Hint: If you really, really, really have to turn in this assignment using assembler, do yourself a big favor. Write the code in C. Let the compiler generate the code. Look at the generated code, and try to understand how - and why - the compiler handles the different if/while situations. However, do not try to copy/paste the assembler output from the C compiler into your project - any decent teacher should spot the difference between hand-written and compiler-generated assembler code.
If you really, really, really have to turn in this assignment using assembler, do yourself a big favor. Write the code in C ... even better, and also needxed if you follow Pers suggestion, read "the bible" chapter 2. It is clear from your posts that just reading CJNE in this paper would have eliminated this whole thread
Erik
here are the links to "the bible" Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer’s Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf