;Program: ModSeven.ASM ;Update: 20 February 2003 ;By: Dr. Marcus O. Durham, PhD, PE ; Tulsa, OK, USA ; mod@superb.org ; www.ThewayCorp.com ;Copyright (c)1991, 2003. All rights reserved ;Purpose: ; Data is stored in GapA, GapB, GapC. ; Data is displayed on 3 7-segment displays. ; Display-out latch shows the data. ; The 3 displays are selected by port 3.2, 3.3, & ; 3.4 ; ;################################################# ; ASSIGNMENTS ;################################################# P35 EQU 0B5h ;switch input GapD EQU 37H ;general purpose variables GapC EQU 36H GapB EQU 35H GapA EQU 34H LoopC EQU 07H ;loop counter ;R0 EQU 00H ;destination indirect addr ;################################################# ; PROGRAM ;################################################# ORG 00h START: LJMP INITIAL ORG 0033h DB 25, 1,'Marcus O. Durham, PhD, PE' ;------------------------------------------------- ORG 0080H ;get past interrupt INITIAL: ;------------------------------------------------- MOV SP,#5Fh ;start stack @ 5f+1 SETB P35 ;make input LCALL HELLO ;start display LCALL SEVBCD ;BCD to 7 segment ;------------------------------------------------- MAIN: ;------------------------------------------------- LCALL SEVSEG ;output seven segmen MAN9: JNB P35,MAIN ;Repeat ;------------------------------------------------- HELLO: ;------------------------------------------------- ; Preload a value into the general purpose bytes. ;PRELOAD MOV GapA,#0Fh ;data byte MOV GapB,#0Ah MOV GapC,#0Bh RET ;------------------------------------------------- SEVBCD: ;------------------------------------------------- ; Convert the binary coded decimal to seven seg. ; Use a table look up. ;INITIAL MOV DPTR,#TabSeven ;seven seg table MOV R0,#GapA ;base of digits MOV LoopC,#3 ;number of digits ;CONVERT SBCD1: MOV A,@R0 ;get BCD MOVC A,@A+DPTR ;table offset to A MOV @R0,A ;replace w/ 7 seg ;NEXT DIGIT INC R0 ;next DJNZ LoopC,SBCD1 ;>=0, repeat process RET ;else, exit ;------------------------------------------------- SEVSEG: ;------------------------------------------------- ; Seven Seg is a routine that operates in 4 steps ; 1. Select the digit stored in GapS ; 2. Select the digit to turn on ; 3. Send the data ; 4. Wait briefly for persistence of the led. ; 5. Repeat ;INITIAL BYTE LOCATE MOV R0,#GapA ;least sig display ;SELECT LINES CLR 92h ;turnoff all selects CLR 93h CLR 94h ;DIGIT 1 SETB 92h ;Bit is hi, select A LCALL SEVOUT ;output & delay CLR 92h ;DIGIT 2 ;DIGIT 3 ;TERMINATE RET ;back to Hotlanta ;################################################# ; TABLES ;################################################# TabSeven: ;------------------------------------------------- ; Seven-segment display DB 3Fh ;0 DB 06h ;1 DB 5Bh ;2 ;complete the table ;************************************************* END ;Program end Alternative output can be on a port or via memory mapped io. ;------------------------------------------------- SEVOUT: ;------------------------------------------------- ;BYTE OUT MOV A,@R0 ;data byte INC R0 ;next info to show ;PERSISTENCE WAIT MOV R2,#200 ;Nested loop counter ZDEL1: MOV Pio,A ;display digit DJNZ R2,ZDEL1 ;Nested loop, 256 x RET ;------------------------------------------------- SEVOUT: ;------------------------------------------------- ;BYTE OUT MOV A,@R0 ;data byte INC R0 ;next info to show ;PERSISTENCE WAIT MOV DPTR,#8002h ;addr for disp latch MOV R2,#200 ;Nested loop counter ZDEL1: MOVX @DPTR,A ;display digit DJNZ R2,ZDEL1 ;Nested loop, 256 x RET