Declan, here's an 18X working version. I didn't have any lighthouse patterns handy, so I built the program to flash the Morse digits 0 through 7 on outputs 0 through 7.
I've ordered a couple of 28X1s, but they haven't arrived yet, so I couldn't try this program on a physical 28X1.
Hope this helps, and that you'll really enjoy looking at your finished work of art.
Best,
Tom
<code><pre><font size=2 face='Courier'>
;
; Lighthouse simulator: tests algorithm for Declan's animated lighthouse artwork
;
; This program just flashes the outputs in Morse code
;
; Morse 0 on out0 through Morse 7 on out7
;
; 152 bytes
;
; Picaxe 18X, PE 5.1.3, Enhanced compiler options turned on
;
; Morse patterns in eeprom
; Record format: sequence length, then three bytes of data which represents
; the state of each output line during each baud interval.
;
; The sequences are stored back-to-front, with the LSB of the
; last byte sent first, working toward the MSB of the first
; sequence byte.
;
symbol TblBase = 0
symbol DSize = 4
data 0,(23,%00000111,%01110111,%01110111) ; 0
data 4,(21,%00000001,%11011101,%11011101) ; 1
data 8,(19,%00000000,%01110111,%01110101) ; 2
data 12,(17,%00000000,%00011101,%11010101) ; 3
data 16,(15,%00000000,%00000111,%01010101) ; 4
data 20,(13,%00000000,%00000001,%01010101) ; 5
data 24,(15,%00000000,%00000101,%01010111) ; 6
data 28,(17,%00000000,%00010101,%01110111) ; 7
symbol Cptr = 32 ; Character position regs in eeprom addr 32 - 39
symbol Baud = 50 ; Sets flash speed
symbol LEDLine = b1
symbol DataAddr = b2
symbol Size = b3
symbol Position = b4
symbol PosAddr = b5
Main:
; Initialize position registers
for LEDLine = 0 to 7
PosAddr = Cptr + LEDLine
write PosAddr,0
next
do
pause Baud
for LEDLine = 0 to 7
DataAddr = LEDLine * DSize + TblBase
read DataAddr,Size
PosAddr = LEDLine + Cptr
read PosAddr,Position
gosub GetBit ; get state of sequence bit in bit0
if bit0 = 1 then
gosub LED_on
else
gosub LED_off
endif
read PosAddr,Position ; inc position register
inc Position
if Position > Size then
Position = 0
endif
write PosAddr,Position
next
loop
end
GetBit:
;
; Input:
;
; b2: DataAddr - sequence base address
; b4: Position - sequence position
;
; Action:
;
; returns state of sequence bit in bit0
;
; Modifies:
;
; bit0 in b0 modified
; b1 through b7 unchanged
; b8-b10 modified
;
if Position < 8 then ; calculate the byte to retrieve from the table
b8 = 3
elseif Position < 16 then
b8 = 2
else
b8 = 1
endif
b9 = DataAddr + b8 ; put sequence byte into b8
read b9,b8
b9 = Position % 8 ; b9 = bit position within the seq byte
b10 = 1 ; generate the mask in b10
do while b9 > 0
b10 = b10 * 2
dec b9
loop
b9 = b8 & b10 ; bit0 = sequence bit
if b9 > 0 then
bit0 = 1
else
bit0 = 0
endif
return
LED_on:
low LEDLine
return
LED_off:
high LEDLine
return
</font></pre></code>
Edited by - Tom2000 on 25/06/2007 22:28:08
Edited by - Tom2000 on 25/06/2007 22:38:19