$include (C8051F410.INC) LED EQU P0.2 CSEG at 0000h jmp Main Main: anl PCA0MD, #0BFh mov PCA0MD, #000h mov XBR1, #040h Main1: mov R7,#0 Main2: mov a,R7 call BCD7S mov a,#50 call Wait inc R7 cjne R7,#10,Main2 jmp Main1 ; a*10ms Wait: push acc Wait1: push acc mov a,#127 djnz acc,$ ; 127*5 cycles djnz acc,$ pop acc djnz acc,Wait1 pop acc ret BCD7S: push acc ; save the accumulator mov dptr,#Table ; load the conversion table address movc a,@a+dptr ; load the proper value from the table cpl a ; use negative logic mov P2,a ; switch on the 7 segment LEDs pop acc ; restore the accumulator ret Table: ; this table holds the binary 7 segment conversion codes db 03Fh, 006h, 05Bh, 04Fh, 066h, 06Dh, 07Dh, 007h, 07Fh, 06Fh END