--- a/matrix.inc Thu Jun 17 20:00:27 2010 +0300
+++ b/matrix.inc Thu Jun 17 21:54:24 2010 +0300
@@ -6,10 +6,12 @@
.set MATRIX_OE = PORTB1 ; Output Enable, active low, externally pulled high
.dseg
-.set MATRIX_COLS = 8 ; number of columns
+.set MATRIX_COLS = 8 ; number of physical columns (XXX: fixed to 8)
+.set MATRIX_BUF_COLS = 16 ; number of columns in frame buffer
-matrix_colbit: .byte 1 ; column bit
-matrix_rowbuf: .byte MATRIX_COLS ; row bitmask by column
+matrix_colbit: .byte 1 ; scan column bit
+matrix_colbuf: .byte MATRIX_BUF_COLS ; row bits by column
+matrix_colshift: .byte 1 ; left column offset
.cseg
@@ -35,10 +37,13 @@
ldi r16, 0b1
sts matrix_colbit, r16
+ ldi r16, 0
+ sts matrix_colshift, r16
+
ldi r16, 0
- ldi r17, MATRIX_COLS
- ldi YL, low(matrix_rowbuf)
- ldi YH, high(matrix_rowbuf)
+ ldi r17, MATRIX_BUF_COLS
+ ldi YL, low(matrix_colbuf)
+ ldi YH, high(matrix_colbuf)
m_init_mzero:
st Y+, r16
@@ -57,6 +62,10 @@
;; Scan the next column
;; Interrupt-driven
Matrix_ScanCol:
+ ; Save registers
+ push r16
+ push r17
+
; Column bit
; load
lds r16, matrix_colbit
@@ -82,16 +91,23 @@
rjmp m_sc_colidx
m_sc_row:
+ ; Column shift
+ ; load
+ lds r16, matrix_colshift
+
+ ; add to col index
+ add r17, r16
+
; Row mask
; base
- ldi XL, low(matrix_rowbuf)
- ldi XH, high(matrix_rowbuf)
+ ldi XL, low(matrix_colbuf)
+ ldi XH, high(matrix_colbuf)
; offset
- ldi r18, 0
+ ldi r16, 0
add XL, r17
- adc XH, r18
+ adc XH, r16
; load
ld r16, X
@@ -119,13 +135,16 @@
sbi SPI_PORT, SPI_SS
; Done
+ pop r17
+ pop r16
+
ret
;; Scan the matrix once in one go
Matrix_ScanFull:
; Row index
- ldi ZL, low(matrix_rowbuf)
- ldi ZH, high(matrix_rowbuf)
+ ldi ZL, low(matrix_colbuf)
+ ldi ZH, high(matrix_colbuf)
; Column bit
ldi r25, 0
@@ -156,3 +175,29 @@
; Done
ret
+;; Shift the matrix output one column to the right, looping around
+Matrix_ShiftRight:
+ ; Decrement-loop current value
+ ; current value
+ lds r16, matrix_colshift
+
+ ; shift window left
+ dec r16
+
+ ; test for underflow -> MSB/N set
+ brpl Matrix_ShiftSet
+
+ ; reset window to right edge
+ ldi r16, MATRIX_BUF_COLS - MATRIX_COLS
+
+ ;; Continue
+
+;; Set the matrix output left shift
+;; Input: r16
+Matrix_ShiftSet:
+ ; store new value
+ sts matrix_colshift, r16
+
+ ; done
+ ret
+
--- a/matrix.s Thu Jun 17 20:00:27 2010 +0300
+++ b/matrix.s Thu Jun 17 21:54:24 2010 +0300
@@ -18,7 +18,8 @@
.org SPIaddr
rjmp SPI_Interrupt
-.org 0x40
+
+cseg0: .org 0x40
;; Syntax
.include "macros.inc"
@@ -73,15 +74,15 @@
Main_ScanTest:
; Generate pattern
; end of buffer
- ldi r17, MATRIX_COLS
- ldi XL, low(matrix_rowbuf + MATRIX_COLS)
- ldi XH, high(matrix_rowbuf + MATRIX_COLS)
+ ldi r17, MATRIX_BUF_COLS
+ ldi XL, low(matrix_colbuf + MATRIX_BUF_COLS)
+ ldi XH, high(matrix_colbuf + MATRIX_BUF_COLS)
; bit pattern
ldi r16, 0b11
st_loop:
- ; put
+ ; put, pre-decrement
st -X, r16
; flip
@@ -91,10 +92,97 @@
dec r17
brne st_loop
-st_scan:
- ; Scan repeatedly
- ;rcall Matrix_ScanCol
- rjmp st_scan
+st_animate:
+ ; Animate
+ ; shift right
+ rcall Matrix_ShiftRight
+
+ ; wait for X/16th of a second
+ ldi XH, high(4 * 1024)
+ ldi XL, low(4 * 1024)
+
+ rcall Timer_Sleep
+
+ ; loop
+ rjmp st_animate
+
+
+;; Display device code memory
+Main_ScanCode:
+ ; Code start
+ ldi ZL, low(cseg0 * 2) ; word addr
+ ldi ZH, high(cseg0 * 2) ; word addr
+
+ ; Load initial frame
+ ; to first frame, starting from right edge
+ ldi r17, 8
+ ldi XL, low(matrix_colbuf + 16)
+ ldi XH, high(matrix_colbuf + 16)
+
+sc_load_initial:
+ ; one byte
+ lpm r16, Z+
+ st -X, r16
+
+ ; loop until zero
+ dec r17
+ brne sc_load_initial
+
+sc_next:
+ ; Show this frame
+ rcall Matrix_ShiftRight
+
+ ; Load next frame
+ ldi r17, 8
+ ldi XL, low(matrix_colbuf + 8)
+ ldi XH, high(matrix_colbuf + 8)
+
+sc_load_next:
+ ; one byte
+ lpm r16, Z+
+ st -X, r16
+
+ ; loop until zero
+ dec r17
+ brne sc_load_next
+
+ ; Animate from this -> next frame
+ ldi r17, 8 ; 8 columns
+
+sc_anim:
+ ; wait for X/16th of a second
+ ldi XH, high(2 * 1024)
+ ldi XL, low(2 * 1024)
+
+ rcall Timer_Sleep
+
+ ; shift
+ rcall Matrix_ShiftRight
+
+ ; loop until zero
+ dec r17
+ brne sc_anim
+
+ ; Move next -> this
+ ldi r17, 8
+ ldi XL, low(matrix_colbuf + 16)
+ ldi XH, high(matrix_colbuf + 16)
+ ldi YL, low(matrix_colbuf + 8)
+ ldi YH, high(matrix_colbuf + 8)
+
+sc_move_this:
+ ; one byte
+ ld r16, -Y
+ st -X, r16
+
+ ; loop until zero
+ dec r17
+ brne sc_move_this
+
+sbi PIND, PIND7
+
+ ; Load next frame, and animate
+ rjmp sc_next
Main:
init:
@@ -122,8 +210,9 @@
; Run
; rcall Main_ScanRaw
+ ; rcall Main_ScanTest
- rcall Main_ScanTest
+ rcall Main_ScanCode
end:
rjmp end