NAME CLOCK ;** ;** 97.461 LAB 1, Part D. ;** ;** Runs an hour, minute, second clock on the SDK board display. ;** CONTROL_REG EQU 0FFEAH ;Set the address value of the DATA_REG EQU 0FFE8H ; control and data port. LED_ADDR EQU 090H ;Set the starting of LED addr. MAX_SECONDS EQU 60H MAX_MINUTES EQU 60H MAX_HOURS EQU 24H ZERO EQU 00H ;********* S T A R T O F C O D E S E G M E N T ********* CODE_SEG SEGMENT ASSUME CS:CODE_SEG, DS:DATA_SEG ORG 100H ;** WAIT ** (Please write code below in space provided). ;** ;** Contains loops which run for approximately one second (within 25%). ;** Does not take into account the run time of the other procedures ;** in the CLOCK program (they are negligible with respect to the ;** processor speed variance). ;** WAIT PROC NEAR RET WAIT ENDP ;** UPDATE ** ;** ;** Increments the SECOND location modulo 60, then increments the MINUTE ;** location modulo 60 and the HOUR location modulo 24 if necessary. ;** Works in decimal arithmetic (note the decimal adjust operations that ;** are necessary). ;** UPDATE PROC NEAR MOV AL,SECOND INC AL DAA CMP AL,MAX_SECONDS JE INC_MINUTES MOV SECOND,AL RET INC_MINUTES: MOV SECOND,ZERO MOV AL,MINUTE INC AL DAA CMP AL,MAX_MINUTES JE INC_HOURS MOV MINUTE,AL RET INC_HOURS: MOV MINUTE,ZERO MOV AL,HOUR INC AL DAA CMP AL,MAX_HOURS JE FINISHED MOV HOUR,AL RET FINISHED: MOV HOUR,ZERO RET UPDATE ENDP ;** WRITE ** ;** ;** This subroutine writes the contents of the SECOND, MINUTE, and HOUR ;** locations to the SDK board display. The 90H is written to the control ;** register to initialize the display. Data is written by consecutively ;** writing the digits to the data register of the display, starting from ;** the low digit of SECOND. Each write increments the display address ;** automatically which was initialized to the rightmost digit. ;** ;** Before the output, the BCD digits are translated into 7-segment code ;** using the LED_TABLE. The two digits of each field (SECOND, MINUTE, ;** HOUR) are separated before the translation. ;** WRITE PROC NEAR MOV AL,90H MOV DX,CONTROL_REG OUT DX,AL MOV DX,DATA_REG LDS BX,LED_TAB_PTR MOV AL,SECOND AND AL,0FH XLAT LED_TABLE OUT DX,AL MOV AL,SECOND MOV CL,4 SHR AL,CL XLAT LED_TABLE OUT DX,AL MOV AL,MINUTE AND AL,0FH XLAT LED_TABLE OUT DX,AL MOV AL,MINUTE SHR AL,CL XLAT LED_TABLE OUT DX,AL MOV AL,HOUR AND AL,0FH XLAT LED_TABLE OUT DX,AL MOV AL,HOUR SHR AL,CL XLAT LED_TABLE OUT DX,AL RET WRITE ENDP ;********* S T A R T O F M A I N P R O G R A M ********* BEG: MOV AX,DATA_SEG ;Set up the DS register MOV DS,AX ;as ASSUMEd. CONT: CALL WAIT ;Wait one second. CALL UPDATE ;Update the time. CALL WRITE ;Load to LED display. JMP CONT ;Loop forever. CODE_SEG ENDS ;********* S T A R T O F D A T A S E G M E N T ********* DATA_SEG SEGMENT ORG 200H SECOND DB 22H ;Storage for second MINUTE DB 59H ;Storage for minute HOUR DB 23H ;Storage for hour LED_TAB_PTR DD LED_TABLE ;Translation table for 7-segment codes. LED_TABLE DB 3FH ; 0 DB 06H ; 1 DB 5BH ; 2 DB 4FH ; 3 DB 66H ; 4 DB 6DH ; 5 DB 7DH ; 6 DB 07H ; 7 DB 7FH ; 8 DB 6FH ; 9 DATA_SEG ENDS END BEG