--- a/Makefile Sun May 09 23:27:12 2010 +0300
+++ b/Makefile Fri May 14 18:19:22 2010 +0300
@@ -9,7 +9,7 @@
AD = avrdude
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)
-PROG = led7seg
+PROG = matrix
all: $(PROG).hex
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/matrix.s Fri May 14 18:19:22 2010 +0300
@@ -0,0 +1,96 @@
+.nolist
+.include "m168def.inc" ; Same family as 328P
+.list
+
+
+;; Interrupt Vector
+.org 0x00
+ rjmp init
+
+;; Syntax
+.include "macros.inc"
+
+;; SPI
+.include "spi.inc"
+
+;; Utils
+.include "delay.inc"
+
+;; Initialize output buffers
+Main_Init:
+ ; Setup ENable port
+ sbi PORTB, PORTB1 ; high -> disabled
+ sbi DDRB, PORTB1 ; out
+
+ ; all low
+ ldi r16, 0
+
+ sts spi_outbuf + 0, r16
+ sts spi_outbuf + 1, r16
+
+ ; write out
+ rcall SPI_SendRecv
+
+ ; enable
+ cbi PORTB, PORTB1 ; low -> enabled
+
+ ; done
+ ret
+
+;; Scan through each pixel
+Main_Scan:
+ ; init
+ ldi r18, 1
+ ldi r19, 1
+
+scan_loop:
+ ; write out to SPI
+ sts spi_outbuf + 0, r18 ; rows
+ sts spi_outbuf + 1, r19 ; columns
+
+ rcall SPI_SendRecv
+
+ ; delay
+ ldi r20, 5 ; ~4M cycles
+ rcall VarDelay
+
+ ; rows
+ rol r18 ; next row
+ brcc scan_loop ; refresh if we didn't overflow
+
+ rol r18 ; shift back from C into r20.0
+
+ ; cols
+ rol r19 ; next col
+ brcc scan_loop ; refresh if we didn't overflow
+
+ rol r19 ; shift back from C into r21.0
+
+ ; one scan completed
+ ret
+
+Main:
+init:
+ ; Stack
+ ldi r16, high(RAMEND)
+ ldi r17, low(RAMEND)
+ out SPH, r16
+ out SPL, r17
+
+ ; Enable interrupts
+ sei
+
+ ; SPI
+ rcall SPI_Init
+
+
+ ; Run
+ rcall Main_Init
+
+loop:
+ rcall Main_Scan
+ rjmp loop
+
+end:
+ rjmp end
+
--- a/spi.inc Sun May 09 23:27:12 2010 +0300
+++ b/spi.inc Fri May 14 18:19:22 2010 +0300
@@ -47,8 +47,9 @@
out SPI_FLAGS, r0
; Start update timer
- ldi r16, 64 ; every 64k cycles
- rcall Timer0_Start
+ ; XXX: also used for ADC
+; ldi r16, 64 ; every 64k cycles
+; rcall Timer0_Start
; Done
ret