Programs

Clockface

This is a program which my girlfriend suggested I write; I don’t see too well without glasses, so at night I find it difficult to read a clock. This program makes the tummy LED change colour depending upon what hour it it, and the lights around the outside change according to what segment the minute hand should be in at that time. I can tell the time to within 20 mins using it, which is enough to tell me to go back to sleep :)

The program needs a modified version of My proxy, but I’ll be posting that version here soon anyway.

# Assembler to make the lights go on according to what messages are being sent
# to the registers
 
# 0: black, 1: red, 2: green, 3: yellow, 4: blue, 5: purple, 6: cyan, 7: white
 
ID      0x7ffffffe
TRANSITION IMMEDIATE
 
# Set the LEDs to black
    LD R2,5
ledreset:
    DEC R2
    LD R0,0
    LD R1,0
    BSR @setanled
    TST R2
    BEQ @mainloop
    BRA @ledreset
 
mainloop:
    WAIT 20
    BSR @setleds
    BRA @mainloop
 
####################  Library #################
 
# Set all the LEDs to their respective colours
# from the SRC packet (eg LED 2 sets to the
# colour from position 2 in the packet)
setleds:
    PUSH R3,R2,R1,R0
    LD R2,5
setled1:
    DEC R2
    SRC R0,R2
    LD R3,5
    SRC R1,R3
    BSR @setanled
    TST R2
    BEQ @setled2
    BRA @setled1
setled2:
    PULL R3,R2,R1,R0
    RTS
 
# Call "BSR @setanled" with the palette colour
# in R0, the intensity in R1, and the LED number
# in R2
setanled:
    PUSH R7,R6,R5,R4,R3,R2,R1,R0
    LD R7,25
    LD R6,R2
    LD R5,R1
    LD R4,R0
    PALETTE R4,R5
    LED R6,R7
    PULL R7,R6,R5,R4,R3,R2,R1,R0
    RTS
 
# Call "BSR @setanlednow" with the palette colour
# in R0, the intensity in R1, and the LED number
# in R2
setanlednow:
    PUSH R7,R6,R5,R4,R3,R2,R1,R0
    LD R7,0
    LD R6,R2
    LD R5,R1
    LD R4,R0
    PALETTE R4,R5
    LED R6,R7
    PULL R7,R6,R5,R4,R3,R2,R1,R0
    RTS
 
 
 
clockface.txt · Last modified: 2007/04/21 18:37
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki