MIPS - Segundos


MIPS - Seconds


org 0h ;power-on reset

JMP Main

org 0bh ;timer 0 interrupt

JMP TC0int


org 100h ;mainline code

main:


SETB P3.0

MOV R1, #00h

MOV R3, #00h
MOV DPTR, #TABLE

LOOP: MOV A,R1
MOVC A, @A+DPTR
MOV R3,A
CJNE R3, #0 ,NEXT
JMP final
NEXT:
MOV P1,A
INC R1

CALL Init ;initialize RTC
CALL TC0int
CJNE R1, #8, LOOP
jmp final



org 0020h
TABLE: DB 11111110b
DB 11111101b
DB 11111011b
DB 11110111b
DB 11101111b
DB 11011111b
DB 10111111b
DB 01111111b
DB 00000000b

;;;;;;;




;R0 acts as a decrementing variable counter
;TH0 and TL0 are the counter generating an interrupt when it
;reaches 0000h

Init: MOV R0, #20h ;this gives R0 * 33ms delay = 1sec

MOV R2, #00h

MOV TH0, #80h

MOV TL0, #00h ;timer 0 gives 33msecs between
; interrupts

MOV TMOD, #01 ;C/T=0, mode 1 (16bit counter)

MOV TCON, #10h ;start timer 0 running

MOV IE, #82h ;enable all interrupt control bit

;enable interrupt for timer 0
RET

;Timer Counter Zero Interrupt Service Routine

TC0int:
DEC R0 ;decrement counter variable

MOV B, R0 ;move into accumulator

JNZ TC0Exit ;if not zero then return from interrupt

MOV R0, #20h ;re-load initial values in R0

INC R2 ;seconds = seconds + 1

MOV B, R2 ;get seconds variable

;SUBB B, #60 ;if seconds >= 60

;JNZ TC0Exit
ret


TC0Exit:
MOV TH0, #80h

MOV TL0, #00h

CLR TF0

RET

final:
End



0 comentários:

Enviar um comentário