This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

compare voltage

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?

Parents
  • 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.

Reply
  • 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.

Children