I am facing problem when programming 89c51 using assembly language.According to following code controller counts only 4.please help me to correct the code when both the pins (P1.0 and P1.1)are high then pin (P1.7)should be high to count.
ORG 0 IA EQU P2.0 IB EQU P2.1 IC EQU P2.2 ID EQU P2.3 IN_1 EQU P1.0 IN_2 EQU P1.1 OUT EQU P1.7 MOV R0,#0 MOV P0,R0 MOV P1,R0 MOV P2,R0 MOV P3,R0 CLR A AGAIN:JNB IN_1,AGAIN JNB IN_2,AGAIN SETB OUT INC A CJNE A,#1,N1 MOV P2,#00000001B ;1 CLR OUT SJMP AGAIN N1:CJNE A,#2,N2 MOV P2,#00000010B ;2 CLR OUT SJMP AGAIN N2:CJNE A,#3,N3 MOV P2,#00000010B ;3 CLR OUT SJMP AGAIN N3:CJNE A,#4,AGAIN MOV P2,#00000100B ;4 CLR OUT SJMP AGAIN N4:CJNE A,#4,N5 MOV P2,#00000101B ;5 CLR OUT SJMP AGAIN N5:CJNE A,#5,N6 MOV P2,#00000110B ;6 CLR OUT SJMP AGAIN N6:CJNE A,#6,N7 MOV P2,#00000111B ;7 CLR OUT SJMP AGAIN N7:CJNE A,#7,N8 MOV P2,#00001000B ;8 CLR OUT SJMP AGAIN N8:CJNE A,#8,N9 MOV P2,#00001001B ;9 CLR OUT SJMP AGAIN N9:CJNE A,#9,AGAIN MOV P2,#00000000B ;0 CLR OUT SJMP AGAIN END
I think you forgot one thing - you are supposed to read through your own code and try to understand it. Every line of it.
Interesting here: Your comparisons:
#1 #2 #3 #4 #4 <= again??? #5 #6 #7 #8 #9
Another interesting thing - your output patterns:
#00000001B ;1 #00000010B ;2 #00000010B ;3 <= wanna bet??? #00000100B ;4 #00000101B ;5 #00000110B ;6 #00000111B ;7 #00001000B ;8 #00001001B ;9 #00000000B ;0
How fast is this counter expected to tick? As fast as it can?
And what is the actual intention with the output pin?
If you think the assembler understands numbers both as decimal and binary constants - why are you using binary constants that you need to "explain" with a decimal value directly after?
Do you think compilers and assemblers got support for software comments just so that a developer could add information about the intentions and meanings of variables, I/O pins etc? Or is software comments just so that we can add a copyright message just before we hand in our assignments? Your only use of comments is to insert (sometimes incorrect) translations from binary to decimal.
Next thing - before your loop you clear A. Then your code only increments A. And your code assumes that if A isn't 1, 2, 3, 4, 5, 6, 7, 8, 9 then your display should continue to display the previous value. Extra interesting since A=1 should display1. While A=9 should not display 9 but 0... But further - is A really limited to the numeric range 0..9? What is the expected display output if you have let A increment to 47? Or 59? Or 243? Or 255? Did you really intend that A should continut to tick 253 -> 254 -> 255 -> 0 just to return back to the 10 numeric values your counter most probably was intended to understands?
Wouldn't you think it's a good idea if you actually debug your code - stepping through the full intended range of your variables, and stepping through all specific values that are expected to match explicit tests - before you post? Code coverage is how to test code so you attempt to test true/false for every single comparison. Off-by-one errors are expected to be hunted by testing the actual end ranges to make sure that the first and last value really will be the first and last values - and will produce the expected result.
A forum can't remove the need for you to invest own time.
you are supposed to read through your own code and try to understand it. which would be easier with labels less cryptic and a few comments would not hurt