Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Digital Clock Using Emu8086 and Dosbox: Team Members: George Kuncheria (18BCE2339) Ajayjith (18BCE2332)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 50

DIGITAL CLOCK USING EMU8086 AND DOSBOX

TEAM MEMBERS:
George Kuncheria(18BCE2339)
Ajayjith (18BCE2332)

Report submitted for the


Final Project Review of: DIGITAL CLOCK

Course Code: CSE2006 – MICROPROCESSOR AND INTERFACING


Slot: A1and A2
Professor: Antony X.G.X

1
ACKNOWLEDGEMENTS

We would like to express our deep gratitude to Professor Antony Xavier Gittas X,
our project guide, for his idea of topic, patient guidance, enthusiastic
encouragement and useful critiques of this project work. We would also like to
thank SCOPE department of VIT University for providing us this course which
help us fulfil our Degree of Bachelor of technology in Computer and Science
Engineering.

2
TABLE OF CONENT:

[1] AIM 04
[2] OBJECTIVE 04
[3] ABSTRACT 04
[4] INTRODUCTION 04
[5] LITERATURE REVIEW 05
[6] EXISTING AND PROPOSED MODEL 06
[7] METHODOLGY 07
[8] CODE 08
[9] OUTPUT 46
[10] RESULT 48
[11] CONCLUSION 48
[12] REFERENCES 48

3
AIM:
To understand the assembler development process under the 8086 platform, master
the use of emu8086 and DOSBox tools and to have better understanding of how
the digital clock works on emu8086.

OBJECTIVE:
Our proposed system will be using an emulation tool like DOSBox to make the
synchronous counter that counts the hour, minute and second and also uses three
push buttons(left shit-split, right shift-lap, R- reset time) to set those output

ABSTRACT:
The system that is anticipated to be built consists of a digit clock including hour,
minute and second hand using an emulation to view the clock that covers a very
favorable place. The design consists of all the features that a digital clock should
consist and as the design is synchronous the overall delay is negligible. It also
includes a stop watch which consist of split and lap time

INTRODUCTION:
As of now most people groups in the entire world utilize a automated digital clock
in their ordinary use. Beginning from the hand watch we were to those immense
road timekeepers all of us are reliant on the showcase the make. In 21st century
time being more than cash, with respect to this change our diversions of checking
our time each moment is significantly expanding. About 99% of the present digital
clock are made utilizing microcontrollers which make them more hand capable
from the rest, those we can set an opportunity to begin any moment or second we
need and furthermore set a caution for update so the framework will store the
incentive in a memory and afterward when the time arrives at the alert will be on.
As the microcontroller comprises practically all the sensible gadgets outer rationale
entryways does not exist.

4
So as to be utilized appropriately and for a long life use digital clock must cover a
little spot as much as could reasonably be expected however the size of the vast
majority of the computerized tickers produced this time is suddenly expanding as
the utilization the give increments. This are the rundown of issues that exists in the
present automated digital clock

LITERATURE REVIEW:

Literature review
In all walks of life, digitals system
are making sophisticated approach
to the mankind. Of course
the machines cannot be replaced
by human beings in exact accuracy
in some fields. For a long
time humans were using analog
devices in our case analog clocks
in their daily life.

5
The first digital pocket watch was
the invention of Austrian engineer
Josef Pallweber who
created his "jump-hour"
mechanism in 1883. Instead of a
conventional dial, the jump-hour
featured two windows in an
enamel dial, through which the
hours and minutes are visible on
rotating discs. The second hand
remained conventional. By 1885
Pallweber mechanism was
already on the market in pocket
watches by Cortébert and IWC;
arguably contributing to the

6
subsequent rise and commercial
success of IWC. The principles of
Pallweber jump-hour
movement had appeared in
wristwatches by the 1920s
(Cortébert) and are still used today
(Chronoswiss Digiteur). While the
original inventor didn't have a
watch brand at the time, his
name has since been resurrected by
a newly established watch
manufacturer
In all walks of life, digitals system are making sophisticated approach to the
mankind. Of course the machines cannot be replaced by human beings in exact
accuracy in some fields. For a long time humans were using analog devices in our
case analog clocks in their daily life. The first digital pocket watch was the
invention of Austrian engineer Josef Pallweber who created his "jump-hour"
mechanism in 1883. Instead of a conventional dial, the jump-hour featured two
windows in an enamel dial, through which the hours and minutes are visible on
rotating discs.

7
The second hand remained conventional. By 1885 Pallweber mechanism was
already on the market in pocket watches by Cortébert and IWC; arguably
contributing to the subsequent rise and commercial success of IWC. The principles
of Pallweber jump-hour movement had appeared in wristwatches by the 1920s
(Cortébert) and are still used today (Chronoswiss Digiteur). While the original
inventor didn't have a watch brand at the time, his name has since been resurrected
by a newly established watch manufacturer.

EXISTING AND PROPOSED MODEL:

Through the top-down design method, the program can be divided into three
modules: acquisition time, printing time, interrupt deal with. After the modules are
divided, the implementation and testing of each module can be implemented.
Experimental steps
From the above analysis, the experiment can be divided into three parts, so the
experimental steps can be roughly divided into three parts.
1. Get the time
2. Printing time
3. Interrupt handling
In the get time module, we use the 2Ch instruction of int 21h to read the system
time.
The hour, minute, and second are stored in the CH, CL, and DH registers.

8
In the print time module, we need to split the ones and tens of the value to achieve
the printing of numeric characters.
Therefore, we use the div instruction to find the quotient and remainder of the
value and 10. After getting the ones and tens values, I
We achieved the display of hours, minutes, and seconds by printing the numeric
character data in the data segment line by line at a fixed point.
In the interrupt processing module, we use the 01h instruction of int 16h to get the
status of the keyboard buffer, and
And judge whether to interrupt the program according to whether there is data in
the buffer.

Experimental results
After many experiments, the experimental code can display the system time (hour,
minute, second), and can correctly respond to the keyboard
Interrupt the signal, and the experimental results meet the experimental
requirements. One of the test results is given below.

METHODOLGY
The prime algorithm that is working in the backend of this project is:

9
CODE:

BACKEND FOR DIGITAL CLOCK:


bits 16
org 100h

10
start:
call start_graphic_mode
finit
call draw_background
.main_loop:
call update_time
call update_angles

mov cx, 15
call draw_pointers

mov ah, 1
int 16h
jnz exit_process

call sleep_half_s

mov cx, 0
call draw_pointers

jmp .main_loop

sleep_half_s:
mov cx, 07h
mov dx, 0a120h
mov ah, 86h
int 15h
ret

11
update_pointer:
fld qword [di]
fcos
fld qword [si]
fmul st1
fistp word [data.x]
ffree st0

fld qword [di]


fsin
fld qword [si]
fmul st1
fistp word [data.y]
ffree st0

ret

update_angles:
mov bx, data.v720
mov si, data.hours
mov di, data.angle_h
call update_angle

mov bx, data.v60


mov si, data.minutes
mov di, data.angle_m

12
call update_angle

mov bx, data.v60


mov si, data.seconds
mov di, data.angle_s
call update_angle

ret;

update_angle:
fld qword [data.v90deg]
fld qword [data.pi2]
fld qword [bx]
fild word [si]
fdiv st1
fmul st2
fsub st3
fstp qword [di]
ffree st0
ffree st1
ffree st2
ret

update_time:

mov ah, 02h


int 1ah

13
mov al, dh
call convert_byte_bcd_to_bin
mov ah, 0
mov word [data.seconds], ax

mov al, cl
call convert_byte_bcd_to_bin
mov ah, 0
mov word [data.minutes], ax

mov al, ch
call convert_byte_bcd_to_bin
mov ah, 0
mov bx, 60
xor dx, dx
mul bx
add ax, [data.minutes]
mov word [data.hours], ax

ret

draw_pointers:
mov di, data.angle_h
mov si, data.size50
call update_pointer
mov di, cx

14
call draw_pointer

mov di, data.angle_m


mov si, data.size80
call update_pointer
mov di, cx
call draw_pointer

mov di, data.angle_s


mov si, data.size80
call update_pointer
mov di, cx
call draw_pointer

ret

draw_pointer:
pusha
mov ax, 160
mov bx, 100
mov cx, 160
mov dx, 100
add cx, word [data.x]
add dx, word [data.y]
call draw_line
popa
ret

15
draw_circle:
.next:
fld qword [bx]
fld qword [di]
fadd st1
fstp qword [di]
ffree st0

mov di, data.angle_s

call update_pointer

pusha
mov al, 15
mov cx, 160
add cx, [data.x]
mov bx, 100
add bx, [data.y]
call pset
popa

loop .next
ret

draw_hours_indications:
mov cx, 12

16
.next:
push cx

fld qword [data.v30deg]


fld qword [data.angle_h]
fadd st1
fstp qword [data.angle_h]
ffree st0

mov di, data.angle_h


mov si, data.size85
call update_pointer

.draw_square:
mov ax, 159
mov dx, 99
.next_dot:
call .draw_square_dot
inc ax
cmp ax, 162
jb .next_dot
.dot_next_y:
mov ax, 159
inc dx
cmp dx, 102
jb .next_dot

pop cx

17
loop .next

ret

.draw_square_dot:
pusha
mov cx, ax
add cx, [data.x]
mov bx, dx
add bx, [data.y]
mov al, 15
call pset
popa
ret

draw_background:

mov cx, 720


mov bx, data.vhalf_deg
mov si, data.size90
mov di, data.angle_s
call draw_circle

mov cx, 60
mov bx, data.v6deg
mov si, data.size85
mov di, data.angle_m
call draw_circle

18
call draw_hours_indications
ret

exit_process:
mov ah, 4ch
int 21h

convert_byte_bcd_to_bin:
push bx
push cx
push dx
mov bh, 0
mov bl, al
and bl, 0fh
mov ch, 0
mov cl, al
shr cx, 4
xor dx, dx
mov ax, 10
mul cx
add ax, bx
pop dx
pop cx
pop bx
ret

19
%include "graphic.inc"

data:
.angle_s dq 0
.angle_m dq 0
.angle_h dq 0

.hours dw 0 ; in number of minutes


.minutes dw 0
.seconds dw 0

.size90 dq 90.0
.size85 dq 85.0
.size80 dq 80.0
.size50 dq 50.0

.pi2 dq 6.28318

.vhalf_deg dq 0.00872665
.v6deg dq 0.10472
.v90deg dq 1.5708
.v30deg dq 0.523599

.v60 dq 60.0
.v720 dq 720.0

.x dw 0
.y dw 0

20
.tmp dw 0

FRONTEND FOR DIGITAL CLOCK:

start_graphic_mode:
mov ax, 0a000h
mov es, ax
mov ah, 0
mov al, 13h
int 10h
ret

; ax = x1
; bx = y1
; cx = x2
; dx = y2
; di = color index
draw_line:
mov word [.x1], ax
mov word [.y1], bx
mov word [.x2], cx
mov word [.y2], dx
sub cx, ax ; CX -> dx = x2 - x1
sub dx, bx ; DX -> dy = y2 - y1
mov word [.dx], cx

21
mov word [.dy], dx
cmp cx, 0
jl .dx_less

.dx_greater:
cmp dx, 0
jge .dx_greater_dy_greater
jl .dx_greater_dy_less
.dx_less:
cmp dx, 0
jge .dx_less_dy_greater
jl .dx_less_dy_less

.dx_greater_dy_greater:
mov ax, [.dx]
mov bx, [.dy]
mov [draw_line_quadrant.dx], ax
mov [draw_line_quadrant.dy], bx
mov ax, [.x1]
mov bx, [.y1]
mov cx, [.x2]
mov dx, [.y2]
mov si, 0 ; quadrant 0
jmp .continue
.dx_greater_dy_less:
mov ax, [.dy]
neg ax
mov bx, [.dx]

22
mov [draw_line_quadrant.dx], ax
mov [draw_line_quadrant.dy], bx
mov ax, [.y1]
neg ax
mov bx, [.x1]
mov cx, [.y2]
neg cx
mov dx, [.x2]
mov si, 3 ; quadrant 3
jmp .continue
.dx_less_dy_greater:
mov ax, [.dy]
mov bx, [.dx]
neg bx
mov [draw_line_quadrant.dx], ax
mov [draw_line_quadrant.dy], bx
mov ax, [.y1]
mov bx, [.x1]
neg bx
mov cx, [.y2]
mov dx, [.x2]
neg dx
mov si, 1 ; quadrant 1
jmp .continue
.dx_less_dy_less:
mov ax, [.dx]
neg ax
mov bx, [.dy]

23
neg bx
mov [draw_line_quadrant.dx], ax
mov [draw_line_quadrant.dy], bx
mov ax, [.x1]
neg ax
mov bx, [.y1]
neg bx
mov cx, [.x2]
neg cx
mov dx, [.y2]
neg dx
mov si, 2 ; quadrant 2

.continue:
call draw_line_quadrant
ret
.x1 dw 0
.y1 dw 0
.x2 dw 0
.y2 dw 0
.dx dw 0
.dy dw 0

; ax = x1
; bx = y1
; cx = x2
; dx = y2
; di = color index

24
; si = quadrant
draw_line_quadrant:
add si, si
push cx
push dx
mov cx, word [.dx] ; CX = dx
mov dx, word [.dy] ; DX = dy
cmp cx, dx
jge .not_swap
.swap:
pop dx
pop cx
xchg ax, bx
xchg cx, dx
inc si
jmp .continue
.not_swap:
pop dx
pop cx
.continue:
call draw_line_octant
ret
.dx dw 0
.dy dw 0

; ax = x1
; bx = y1
; cx = x2

25
; dx = y2
; di = color index
; si = octant
draw_line_octant:
mov word [.x2], cx
sub cx, ax
sub dx, bx
add dx, dx
mov word [.2dy], dx
sub dx, cx ; dx = d = 2 * dy - dx
add cx, cx
mov word [.2dx], cx
; bx = y = y1
mov cx, ax ; cx = x
mov ax, di
.next_point:
call pset_octant
cmp dx, 0
jle .d_less_or_equal
.d_greater:
add dx, word [.2dy]
sub dx, word [.2dx]
inc bx
jmp .continue
.d_less_or_equal:
add dx, word [.2dy]
.continue:
inc cx

26
cmp cx, word [.x2]
jbe .next_point
ret
.x2 dw 0
.2dx dw 0
.2dy dw 0

; al = color index
; bx = row
; cx = col
; si = octant
pset_octant:
push bx
push cx
cmp si, 0
jz .octant_0
cmp si, 1
jz .octant_1
cmp si, 2
jz .octant_2
cmp si, 3
jz .octant_3
cmp si, 4
jz .octant_4
cmp si, 5
jz .octant_5
cmp si, 6
jz .octant_6

27
cmp si, 7
jz .octant_7
.octant_0:
; do nothing
jmp .continue
.octant_1:
xchg bx, cx
jmp .continue
.octant_2:
neg bx
xchg bx, cx
jmp .continue
.octant_3:
neg cx
jmp .continue
.octant_4:
neg cx
neg bx
jmp .continue
.octant_5:
neg cx
neg bx
xchg bx, cx
jmp .continue
.octant_6:
neg cx
xchg bx, cx
jmp .continue

28
.octant_7:
neg bx
.continue:
call pset
pop cx
pop bx
ret

; al = color index
; bx = row
; cx = col
pset:
pusha
xor dx, dx
push ax
mov ax, 320
mul bx
add ax, cx
mov bx, ax
pop ax
mov byte [es:bx], al
popa
ret

STOPWATCH:

org 100h

29
jmp start

;Orignal Time
hrs: dw 0
min: dw 0
s: dw 0
ms: dw 0

;Lap Time
lhrs: dw 0
lmin: dw 0
ls: dw 0
lms: dw 0

oldkb: dd 0

sMode: db 0
lMode: db 0

startTimer: db 0
snapshot: db 0
lapTime: db 0

30
location: db 6

;------------------------------------------------------------------------------------------------------------------

clrscr: pusha
push es

mov ax, 0xb800


mov es, ax
xor di, di
mov ax, 0x720
mov cx, 2000

cld
rep stosw

pop es
popa
ret

;-------------------------------------------------------------------------------------------------------------------

printLayout: pusha
push es

31
mov ax, 0xB800
mov es, ax

mov di, 160

mov byte[es:di+0], 'H'


mov byte[es:di+2], 'R'
mov byte[es:di+4], 'S'

mov byte[es:di+8], ':'

mov byte[es:di+12], 'M'


mov byte[es:di+14], 'I'
mov byte[es:di+16], 'N'

mov byte[es:di+20], ':'

mov byte[es:di+24], 'S'

mov byte[es:di+28], ':'

mov byte[es:di+34], 'M'


mov byte[es:di+36], 'S'

pop es
popa
ret

32
;-------------------------------------------------------------------------------------------------------------------

;-------------------------------------------------------------------------------------------------------------------

kbisr: push ax

in al, 0x60

cmp al, 147


jz reset
jnz modChanger

reset:

mov word [cs:hrs], 0


mov word [cs:min], 0
mov word [cs:s], 0
mov word [cs:ms], 0

33
mov word [cs:lhrs], 0
mov word [cs:lmin], 0
mov word [cs:ls], 0
mov word [cs:lms], 0

call clrscr

mov byte [cs:location], 6

jmp EOI1

modChanger: cmp al, 170


jnz checkLMode1

mov byte [cs:lMode], 0

cmp byte [cs:sMode], 1


jz EOI1

mov byte [cs:sMode], 1 sMode


jmp EOI1

checkLMode1: cmp al, 182


jnz startTime

34
mov byte [cs:sMode], 0

cmp byte [cs:lMode], 1


jz EOI1

mov byte [cs:lMode], 1


jmp EOI1

startTime: cmp al, 185


jnz oldKbHandler

cmp byte [cs:startTimer], 1 then do nothing


jz check0

mov byte [cs:startTimer], 1

check0: cmp byte [cs:sMode], 1


jnz check1

mov byte [cs:snapshot], 1


jmp EOI1

check1: cmp byte [cs:lMode], 1

35
jnz EOI1

mov byte [cs:lapTime], 1


jmp EOI1

EOI1: mov al, 0x20


out 0x20,al

pop ax
iret

oldKbHandler: pop ax
jmp far [cs:oldkb]

;-------------------------------------------------------------------------------------------------------------------

;-------------------------------------------------------------------------------------------------------------------

printstr: push bp
mov bp, sp
pusha

36
push es

mov ax, 0xb800


mov es, ax

mov di, [bp+4]


mov ax, [bp+6]

mov bx, 10
mov cx, 0

nextdigit: mov dx, 0


div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit

cmp cx, 1
jnz nextpos
mov byte [es:di], '0'
add di, 2

nextpos: pop dx
mov dh, 0x07

37
mov [es:di], dx
add di, 2
loop nextpos

pop es
popa
pop bp
ret 4

;-------------------------------------------------------------------------------------------------------------------

printTime: push bp
mov bp,sp
pusha

push es

mov ax, 0xB800


mov es, ax

mov di, [bp+4]

;Printing hours
push word [bp+6]
add di, 2

38
push di
call printstr

;Printing Colon
add di, 6
mov byte [es:di], ':'

;Printing minutes
push word [bp+8]
add di, 6
push di
call printstr

;Printing Colon
add di, 6
mov byte [es:di], ':'

;Printing seconds
push word [bp+10]
add di, 2
push di
call printstr

39
;Printing Colon
add di, 6
mov byte [es:di], ':'

;Printing milli seconds


push word [bp+12]
add di, 2
push di
call printstr

pop es

popa
pop bp
ret 10

;-------------------------------------------------------------------------------------------------------------------

stopWatch: pusha
push es

40
call printLayout

push word [cs:ms]


push word [cs:s]
push word [cs:min]
push word [cs:hrs]

push 480
call printTime

cmp byte [cs:startTimer], 1


jnz dEOI

changeTime: add word [cs:ms], 55


cmp word[cs:ms], 1000
jle modCheck

mov word [cs:ms], 0


inc word[cs:s]
cmp word [cs:s], 60
jnz modCheck

mov word [cs:s], 0


inc word[cs:min]

41
cmp word [cs:min], 60
jnz modCheck

mov word [cs:min], 0


inc word[cs:hrs]

jmp modCheck

modCheck: cmp byte [cs:sMode], 1


jz splitMode

cmp byte [cs:lMode], 1


jz lapMode

jmp EOI

dEOI: jmp EOI

splitMode: cmp byte [cs:snapshot], 1


jnz eEOI

42
mov byte [cs:snapshot], 0

push word [cs:ms]


push word [cs:s]
push word [cs:min]
push word [cs:hrs]

;Position Calculation
mov al, 80
mul byte [cs:location]
shl ax, 1

add byte [cs:location], 2

push ax
call printTime

jmp EOI

eEOI: jmp EOI

lapMode: cmp byte [cs:lapTime], 1


jnz xEOI

43
mov byte [cs:lapTime], 0

mov ax, [cs:ms]


mov bx, [cs:s]
mov cx, [cs:min]
mov dx, [cs:hrs]

l1: sub ax, [cs:lms]


cmp ax, 0
jge l2

add ax, 1000


dec bx

l2: mov [cs:lms],ax

sub bx, [cs:ls]


cmp bx, 0
jge l3

44
add bx, 60
dec cx

l3: mov [cs:ls],bx

jmp l4

xEOI: jmp

l4: sub cx, [cs:lmin]


cmp cx, 0
jge l5

add cx, 60
dec dx

l5: mov [cs:lmin],cx

sub dx, [cs:lhrs]


mov [cs:lhrs],dx

45
push word [cs:lms]
push word [cs:ls]
push word [cs:lmin]
push word [cs:lhrs]

mov al, 80
mul byte [cs:location]
shl ax, 1

add byte [cs:location], 2

push ax
call printTime

jmp EOI

EOI: mov al, 0x20


out 0x20, al

return: pop es
popa
iret

46
;-------------------------------------------------------------------------------------------------------------------

start: mov ax, 0


mov es, ax

mov ax, [es:9*4]


mov [oldkb],ax
mov ax, [es:9*4+2]
mov [oldkb+2], ax

call clrscr

cli

mov word [es:9*4], kbisr


mov [es:9*4+2], cs

mov word [es:8*4], stopWatch


mov [es:8*4+2], cs

47
sti

mov dx, start


add dx, 15
mov cl, 4
shr dx, cl

mov ax, 0x3100


int 21h

;-------------------------------------------------------------------------------------------------------------------

OUTPUT:

48
RESULT:

The laptop screen displays the digital clock and the stopwatch.
The project was done entirely on virtually on DOSBox.

CONCLUSION:
Thus, this is how our main system has been built up.
 More and more knowledge involving the whole system has been

49
gained with time and through more research.
 We have completed this project successfully and have successfully
made a 12-hour digital clock.
 We have also implemented a stopwatch that consists of split time and lap
time.

REFRENCES:
[1] Thomas L. Floyd, "Digital Fundamentals", Seventh Edition,
Prentice-Hall International, Inc., 2000.
[2] Donald D. Givone, "Digital Principles and Designs", McGraw- Hill
2003.
[3] Victor P. Nelson, H. Try Nagle, Bill D. Carroll, and J. David Irwin,
"Digital Logic Circuit Analysis & Design", Prentice-Hall Englewood
Cliffs.NJ, 1995.

50

You might also like