;code for accelerometer controlled vehicle ORG 000H LJMP MAIN ORG 0003H JB X0,RETURN JB Z0,RETURN JNB Y0,RETURN

JNB X1,RETURN JNB Y1,RETURN JNB Z1,RETURN CLR P2.2 CLR P2.3 SETB P2.4 SETB P2.5 MOV R0,#7H MOV R1,#1H THING: ACALL DELAY DJNZ R1,THING CPL P2.3 CPL P2.5 ACALL DELAY CPL P2.3 CPL P2.5 JB Z0,RETURN JB X0,RETURN INC R1 DJNZ R0,THING SJMP ANOTHER ANOTHER: SETB P2.3 CLR P2.5 THEE: JNB P3.2,THEE CLR P2.3 SETB P2.5 RETURN: RETI ORG 230H DELAY: MOV TMOD,#00010000B MOV TL1,#0FH MOV TH1,#0FFH SETB TR1 WHERE: JNB TF1,WHERE CLR TR1 CLR TF1 RET ORG 300H MAIN: X0 EQU P1.1 Y0 EQU P1.2 Z0 EQU P1.3 X1 EQU P1.4

Y1 EQU P1.5 Z1 EQU P1.6 MOV IE,#10000001B MOV P1,#0FFH START: JNB Z0,N SJMP ZEE_1 N:JNB X0,FWD_L_R_T JNB X1,R_50 JNB Y0,N4 JNB Y1,N5 SJMP START N4: LJMP L_TURN N5: LJMP R_TURN FWD_L_R_T: JNB Y0,N6 JNB Y1,N7 SJMP F_50 N6: LJMP L_MOVE N7: LJMP R_MOVE ZEE_1: JB Z1,START JNB Z1,N2 N2:JB X0,N3 LJMP F_FURTHER N3:JNB X1,R_FURTHER SJMP START F_50: CLR C MOV P2.2,C MOV P2.3,C SETB P2.4 SETB P2.5 THIS: ACALL DELAY CPL P2.3 CPL P2.5 ACALL DELAY JB Z0,WAY JB X0,WAY JNB Y0,WAY JNB Y1,WAY SJMP THIS WAY: CLR P2.3 SETB P2.5 LJMP FINISH F_FURTHER: CLR P2.2 CLR P2.3

SETB P2.4 SETB P2.5 THIS1: ACALL DELAY SETB P2.3 CLR P2.5 ACALL DELAY ACALL DELAY ACALL DELAY CPL P2.3 CPL P2.5 JB X0,WAY JB Z1,WAY SJMP THIS1 R_50: SETB P2.2 SETB P2.3 CLR P2.4 CLR P2.5 THISR: ACALL DELAY CPL P2.3 CPL P2.5 ACALL DELAY JB X1,WAYR JB Z0,WAYR SJMP THISR WAYR: SETB P2.3 CLR P2.5 lJMP FINISH R_FURTHER: SETB P2.2 SETB P2.3 CLR P2.4 CLR P2.5 THISR2: ACALL DELAY CPL P2.3 CPL P2.5 ACALL DELAY ACALL DELAY ACALL DELAY CPL P2.3 CPL P2.5 JB X1,WAYR JB Z1,WAYR SJMP THISR2 L_TURN: SETB P2.2 CLR P2.3 SETB P2.4 CLR P2.5 THISL: ACALL DELAY JB Z0,WAYL JB Y0,WAYL

JNB X0,WAYL SJMP THISL WAYL: CPL P2.3 CPL P2.5 SJMP FINISH L_MOVE: SETB P2.2 CLR P2.3 SETB P2.4 CLR P2.5 THISL_M: ACALL DELAY ACALL DELAY CPL P2.3 ACALL DELAY CPL P2.3 JB Y0,WAYL JB X0,WAYL JB Z0,WAYL SJMP THISL_M R_TURN: CLR P2.2 SETB P2.3 CLR P2.4 SETB P2.5 THIS_R: ACALL DELAY JB Y1,WAY_R JB Z0,WAY_R JNB X0,WAY_R SJMP THIS_R R_MOVE: CLR P2.2 SETB P2.3 CLR P2.4 SETB P2.5 THISR_M: ACALL DELAY ACALL DELAY CPL P2.3 ACALL DELAY CPL P2.3 JB Y1,WAY_R JB Z0,WAY_R JB X0,WAY_R SJMP THISR_M WAY_R: CLR P2.3 CLR P2.5 SJMP FINISH

FINISH: LJMP MAIN END

Sign up to vote on this title
UsefulNot useful