;----------------------------------------------------------------------------------------; ;THIS CODE IS A SIMPLE EVENT COUNTING CODE.THE DISPLAY IS ON TWO SEVEN SEGMENTS WHICH ARE; ;ATTACHED TO P1 AND P2; ; ;----------------------------------------------------------------------------------------; ;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 ; ;----------------------------------------------------------------------------------------; ORG 0000H LJMP MAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; TMR0_INIT: ;;;;;;;;;;;;;;;;; CLR TF0 CLR TR0 MOV TH0,#0H MOV TL0,#0H SETB TR0 RET ;;;;;;;;;;;;;;;;; LOOK_UP: ;;;;;;;;;;;;;;;;; INC A MOVC A,@A+PC RET TABLE: DB 0xC0,0xFC,0x92,0x98,0xAC,0x89,0x81,0xDC,0x80,0x88 ;COMMON ANODE DISPLAY ;;;;;;;;;;;;;;;;; MAIN: ;;;;;;;;;;;;;;;;; MOV TMOD,#05H ;TMR0 16-BIT MODE,EVENT COUNTING LCALL TMR0_INIT MOV R2,#0H AGAIN: MOV R1,TL0 LCALL ADJUST MOV A,R3 LCALL LOOK_UP MOV P1,A NOP NOP CJNE R3,#9,NEXT CJNE R4,#9,NEXT LCALL TMR0_INIT NEXT: MOV A,R4 LCALL LOOK_UP MOV P2,A LJMP AGAIN END