;----------------------------------------------------------------------------------------; ;THIS CODE DISPLAYS SECONDS ON TWO SEVEN SEGMENTS ATTACHED TO P0 & P1 ; ;IT CAN BE USED AS A STOP WATCH ; ;----------------------------------------------------------------------------------------; ;This code is written by Mubashar Yasin(Islamabad,Pakistan).It is freely distributable ; ;however please distribute it with my name and if you add this code to your website or ; ;some other publication then mention about me along with this code.I have tested this ; ;code to work properly even then there is no guarantee or warranty and i cannot be held ; ;responsible for any damage or loss due to this code.If you have any querries about this ; ;code please contact me at: ; ; ; ; kool_projects@yahoo.com ; ; mubasharpk09@hotmail.com ; ; ; ;or visit my website: ; ; ; ; http://www.geocities.com/kool_projects ; ;----------------------------------------------------------------------------------------; COUNT EQU -10000 ORG 0000H LJMP MAIN ;;;;;;;;;;;;;;;;;; UPDATE_DISP: ;;;;;;;;;;;;;;;;;; LCALL ADJUST MOV A,R3 LCALL LOOK_UP MOV P0,A MOV A,R4 LCALL LOOK_UP MOV P1,A RET ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADJUST: ; 149 cycles for 2 bytes, 77 cycles for 1 byte ;MOV r1,#0AFH ; 175d ;MOV r2,#91H ; 91AFH = 37295d ; Result: R7=3, R6=7, ..., R3=5 ; All 8 registers are used, and also A and B MOV R5,#0 MOV R6,#0 MOV R7,#0 MOV A,R1 MOV B,#10 DIV AB MOV R3,B ; Lower byte, in R1, is transformed into 2 decade digits, MOV R4,A ; it's OK that the higher one can be greater than 9 MOV A,R2 ; Higher byte is in R2 JZ SPRING ; Spring over if 0 MOV B,#10 DIV AB MOV R5,B ; Same as for lower byte MOV R6,A ; Value in R5 is 256 times higher than value standing in R3, R4. Mply R5 with 6, ; add to R3, mply R5 with 5, add to R4, mply R5 with 2 and replace itself in R5 MOV R0,#05 ; Point to R5 ACALL TRANSF ; Transform R5 to 3 lower positions INC R0 ; Repeat from R6, now all registers are 1 higher ACALL TRANSF ; Transform R6 to 3 higher positions SPRING: MOV R0,#03 ; Point to lowest digit ; Adjust to decimal, everything higher than 9 should be, as 1 tenth, added to higher. ; Starting from the lowest digit, divide with 10, keep the rest, and add the 1/10th to ; first higher place (eg. 145, leave 5 and add 14 to the next higher) ACALL DECADJ RET TRANSF: MOV A,@R0 MOV B,#6 MUL AB DEC R0 DEC R0 ADD A,@R0 MOV @R0,A INC R0 INC R0 MOV A,@R0 MOV B,#5 MUL AB DEC R0 ADD A,@R0 MOV @R0,A INC R0 MOV A,@R0 RL A ; Mply with 2 MOV @R0,A RET DECADJ: MOV A,@R0 DECLOP: MOV B,#10 DIV AB MOV @R0,B INC R0 ADD A,@R0 MOV @R0,A CJNE R0,#7,DECLOP RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; LOOK_UP: ;;;;;;;;;;;;;;;;;; INC A MOVC A,@A+PC RET TABLE: DB 0x40,0x7C,0x12,0x18,0x2C,0x09,0x01,0x5C,0x00,0x08 ;COMMON ANODE DISPLAY ;;;;;;;;;;;;;;;;;; ONE_SECOND: ;;;;;;;;;;;;;;;;;; MOV R0,#100 REPEAT: MOV TMOD,#01H MOV TH0,#HIGH COUNT MOV TL0,#LOW COUNT SETB TR0 JNB TF0,$ CLR TF0 CLR TR0 DJNZ R0,REPEAT LCALL UPDATE_DISP RET ;;;;;;;;;;;;;;;;;; MAIN: ;;;;;;;;;;;;;;;;;; MOV R1,#0H MOV R2,#0H AGAIN: LCALL ONE_SECOND INC R1 CJNE R1,#60,AGAIN MOV R1,#0H LJMP AGAIN END