Pengguna:ArdWar/digiclock: Perbedaan antara revisi

Dari Wikipedia bahasa Indonesia, ensiklopedia bebas
Konten dihapus Konten ditambahkan
kTidak ada ringkasan suntingan
kTidak ada ringkasan suntingan
Baris 1: Baris 1:
<code lang="assembly">
<table cellspacing=0 cellpadding=0 style="clear:left;background:none"><tr style="background:{{{color|blue}}}">{{#ifexpr:{{{format|0}}}=12and{{#time:g|{{#expr:{{{offset|0}}}*60round0}}min}}<10|<td style="width:{{{size|40}}}px;background:#000">&nbsp;</td><td>|<td>[[Image:LED digit {{#expr:floor({{#time:{{#ifeq:{{{format}}}|12|g|G}}|{{#expr:{{{offset|0}}}*60round0}}min}}/10)}}.png|{{{size|40}}}px|link=]]}}[[Image:LED digit {{#expr:{{#time:{{#ifeq:{{{format}}}|12|g|G}}|{{#expr:{{{offset|0}}}*60round0}}min}}mod10}}.png|{{{size|40}}}px|link=]][[Image:LED colon.png|{{{size|40}}}px|link=]][[Image:LED digit {{#expr:floor({{#time:i|{{#expr:{{{offset|0}}}*60round0}}min}}/10)}}.png|{{{size|40}}}px|link=]][[Image:LED digit {{#expr:{{#time:i|{{#expr:{{{offset|0}}}*60round0}}min}}mod10}}.png|{{{size|40}}}px|link=]]{{#ifeq:{{{format}}}|12|[[Image:LED {{#time:a|{{#expr:{{{offset|0}}}*60round0}}min}}.png|{{{size|40}}}px|link=]]}}</td></tr></table>
code_seg segment
assume cs:code_seg,ds:code_seg,ss:code_seg
org 100h
;PA0 = Start/Reset timer
;PA1 = Delay set
;PC0 = Servo ctrl
;PB0-7 = Minute indicator

start:
mov al,98h ;A=IN B=OUT
out 03h,al ;
mov ax,02h
push ax
mov dx,02h
inp:
call debounce
in ax,00h ;pool port A 14
cmp ax,02h ;00000010
je hlds
cmp ax,01h
je hldr
jmp inp
hlds:
call debounce
in ax,00h ;pool port A
cmp ax,02h ;PA0 = start
je hlds ;repeat hold
add cx,60d
pop ax
shl ax,1
out 02h,ax
push ax
rlss:
call debounce
in ax,00h ;pool port A
cmp ax,00h ;release
jne rlss ;wait for PA0 release
jmp inp
hldr:
call debounce
in ax,00h ;pool port A
cmp ax,01h ;PA0 = start
je hldr ;repeat hold
add cx,60d
rlsr:
call debounce
in ax,00h ;pool port A
cmp ax,00h ;release
jne rlsr ;wait for PA0 release
timer:
push cx
mov cx,60d
onemin:
push cx ;store second timer 15
mov cx,50d ; 4
onesec: ;1s PC0 indicator
push cx ; 15
mov cx,1948d ;9,75u x 1948 = 18,993m 4
lowspace: ;19ms servo space 39 9,75u
in ax,00h ;pool port A 14
cmp ax,01h ;reset 4
je inp ;jump if reset 4
loop lowspace ;loop 1688x 17
mov al,01h ;toggle servo hi 4
out dx,al ;PC0 high 14
mov cx,102d ;mark timer 4
lowmark: ;1ms servo mark 39
in ax,00h ;pool port A
cmp ax,01h ;reset
je inp ;jump if reset
loop lowmark ;loop 1ms
mov al,00h ;toggle servo low
out dx,al ;PC0 low
pop cx ;return second timer
loop onesec
pop cx
mov al,cl
and al,0001b
out 01h,al
loop onemin
pop cx
pop ax
shr ax,1
out 01h,ax
push ax
loop timer ;loopback servo ctr
endtimer:
mov cx,1846d ;loop 18ms
highspace:
in ax,00h ;pool port A
cmp ax,01h ;reset
je rlss
loop highspace
mov al,01h ;toggle servo high
out dx,al ;port B high
mov cx,205d ;loop 2ms
highmark:
in ax,00h ;pool port A
cmp ax,01h ;reset
je rlss
loop highmark
mov al,00h ;toggle servo low
out dx,al ;port B low
jmp endtimer

debounce proc near
push cx
mov cx,0ffffh
del:
loop del
pop cx
ret
debounce endp
org 20f0h
db 0eah
dw 100h
dw 0fdf0h
code_seg ends
end start
</code>

Revisi per 9 November 2014 13.15

code_seg segment assume cs:code_seg,ds:code_seg,ss:code_seg org 100h

PA0 = Start/Reset timer
PA1 = Delay set
PC0 = Servo ctrl
PB0-7 = Minute indicator

start:

   mov al,98h                    ;A=IN B=OUT
   out 03h,al                    ;
   mov ax,02h
   push ax
   mov dx,02h

inp:

   call debounce
   in ax,00h                    ;pool port A                          14
   cmp ax,02h                    ;00000010
   je hlds
   cmp ax,01h
   je hldr
   jmp inp

hlds:

   call debounce
   in ax,00h                    ;pool port A
   cmp ax,02h                    ;PA0 = start
   je hlds                        ;repeat hold
   add cx,60d
   pop ax
   shl ax,1
   out 02h,ax
   push ax

rlss:

   call debounce
   in ax,00h                    ;pool port A
   cmp ax,00h                    ;release
   jne rlss                    ;wait for PA0 release
   jmp inp

hldr:

   call debounce
   in ax,00h                    ;pool port A
   cmp ax,01h                    ;PA0 = start
   je hldr                        ;repeat hold
   add cx,60d

rlsr:

   call debounce
   in ax,00h                    ;pool port A
   cmp ax,00h                    ;release
   jne rlsr                    ;wait for PA0 release

timer:

   push cx
   mov cx,60d
   onemin:
       push cx                    ;store second timer                             15
       mov cx,50d                    ;                                                4
       onesec:                        ;1s PC0 indicator
           push cx                ;                                                15
           mov cx,1948d            ;9,75u x 1948 =  18,993m                         4            
           lowspace:                ;19ms servo space                                39            9,75u
               in ax,00h            ;pool port A                                    14
               cmp ax,01h            ;reset                                             4
               je inp                ;jump if reset                                     4
               loop lowspace        ;loop 1688x                                        17
           mov al,01h                ;toggle servo hi                                 4
           out dx,al                ;PC0 high                                        14
           mov cx,102d              ;mark timer                                      4
           lowmark:                ;1ms servo mark                                 39
               in ax,00h            ;pool port A
               cmp ax,01h            ;reset
               je inp                ;jump if reset
               loop lowmark        ;loop 1ms
           mov al,00h                ;toggle servo low
           out dx,al                ;PC0 low
           pop cx                    ;return second timer
           loop onesec
       pop cx
       mov al,cl
       and al,0001b
       out 01h,al
       loop onemin
   pop cx
   pop ax
   shr ax,1
   out 01h,ax
   push ax
   loop timer                    ;loopback servo ctr

endtimer:

   mov cx,1846d                ;loop 18ms
   highspace:
       in ax,00h                ;pool port A
       cmp ax,01h                ;reset
       je rlss
   loop highspace
   mov al,01h                    ;toggle servo high
   out dx,al                    ;port B high
   mov cx,205d                ;loop 2ms
   highmark:
       in ax,00h                ;pool port A
       cmp ax,01h                ;reset
       je rlss
   loop highmark
   mov al,00h                    ;toggle servo low
   out dx,al                    ;port B low
   jmp endtimer

debounce proc near

   push cx
   mov cx,0ffffh
   del:
   loop del
   pop cx
   ret

debounce endp org 20f0h db 0eah dw 100h dw 0fdf0h code_seg ends end start