we have taken up the project automatic room light controller with visitor counter using at89s52..we have rigged up the circuit and have written the code too..but when it is dumped into the controller and executed the kit does not produce the expected result..we are getting random numbers like 17,99,etc and there is no decrementation happening at all..could you please go thro' the below code and point out what might be the mistake..the code is as follows:
LIGHT EQU P2.5 DIS1 EQU P2.7 DIS2 EQU P2.6 SEN1 EQU P1.0 SEN2 EQU P1.1 ORG 00H ;************************************************************************************ ;MAIN MOV R4,#00H MOV R5,#00H MOV P0,#0FFH ;make P0 output MOV P1,#0FFH ;make P1 input MOV P2,#0FFH ;make P2 output JNB SEN1,UPPC JNB SEN2,DOWNC AJMP DISPLAY UPPC: JB SEN2,DISPLAY INC R4 CJNE R4,#01H,UPP1 SETB LIGHT SETB DIS1 SETB DIS2 CALL CONV AJMP DISPLAY UPP1: CALL CONV AJMP DISPLAY DOWNC: JB SEN1,DISPLAY DEC R4 CJNE R4,#00H,DOWN1 CLR LIGHT AJMP DISPLAY DOWN1: CALL CONV AJMP DISPLAY ;******************************************************************************* ;CONVERSION CONV: MOV A,R4 MOV B,#10d DIV AB RR A RR A RR A RR A ADD A,B ;to get both the bcd digits in one register MOV R5,A RET ;********************************************************************************** ;DISPLAY DISPLAY: MOV P2, #80H MOV A, R5 ANL A, #0F0H CALL TRANS MOV P0,A CALL DELAY MOV P2,#40H MOV A,R5 ANL A,#0FH RR A RR A RR A RR A CALL TRANS MOV P0,A CALL DELAY JNB SEN1,UPPC JNB SEN2,DOWNC AJMP DISPLAY ;********************************************************************************* ;TO DECIDE THE NUMBER TO BE DISPLAYED TRANS: CJNE A,#00H,ONE MOV A,#0C0H RET ONE: CJNE A,#10H,TWO MOV A,#0F9H RET TWO: CJNE A,#20H,THREE MOV A,#0A4H RET THREE: CJNE A,#30H,FOUR MOV A,#0B0H RET FOUR: CJNE A,#40H,FIVE MOV A,#99H RET FIVE: CJNE A,#50H,SIX MOV A,#92H RET SIX: CJNE A,#60H,SEVEN MOV A,#82H RET SEVEN: CJNE A,#70H,EIGHT MOV A,#0F8H RET EIGHT: CJNE A,#80H,NINE MOV A,#80H RET NINE: MOV A,#98H RET ;************************************************************************************ ;DELAY OF 1ms DELAY: MOV R6,#2 MOV R7,#230 D1: DJNZ R7,D1 DJNZ R6,D1 RET END
thanks
I stated :"A quick look at yor code seens to show that if a person stand still in the lightpath the counter will count and count snd count" your problem right now the increment is happening in huge leaps like it goes from 71 to 82 or decrements from 61 to 54 etc...hope this makes it a bit clear as to what my problem is.. is the time "a person stand still in the lightpath"
but right now we r jus planning a prototype for our academic curriculum so you "jus(t) r (resist) planning", that is VERY obvious. There is ZERO thought behind your code.
Erik