--- a/Makefile Sun May 09 23:17:14 2010 +0300
+++ b/Makefile Sun May 09 23:27:12 2010 +0300
@@ -9,7 +9,7 @@
AD = avrdude
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)
-PROG = timer
+PROG = led7seg
all: $(PROG).hex
--- a/dip.inc Sun May 09 23:17:14 2010 +0300
+++ b/dip.inc Sun May 09 23:27:12 2010 +0300
@@ -8,7 +8,7 @@
;; Output: r16
DIP_Read8:
; update
- rcall SPI_SendRecv
+; rcall SPI_SendRecv
; get bits
lds r16, DIP_BUFFER
--- a/led7seg.inc Sun May 09 23:17:14 2010 +0300
+++ b/led7seg.inc Sun May 09 23:27:12 2010 +0300
@@ -49,7 +49,7 @@
sbi LED7_DDR, LED7_OE ; Out
; Initialize buffer
- ldi r16, 0b11111111
+ ldi r16, 0b01000000
sts led7_buffer + 0, r16
sts led7_buffer + 1, r16
@@ -148,6 +148,5 @@
sts led7_buffer + 1, r17
; Update display
- rjmp SPI_SendRecv
+ rjmp SPI_Update
-
--- a/led7seg.s Sun May 09 23:17:14 2010 +0300
+++ b/led7seg.s Sun May 09 23:27:12 2010 +0300
@@ -7,9 +7,13 @@
rjmp init
.org OC1Aaddr
- ; Timer/Counter1 Overflow
+ ; Timer/Counter1 Compare Output A
rjmp Timer_OC1A
+.org OC0Aaddr
+ ; Timer/Counter0 Compare Output A
+ rjmp Timer_OC0A
+
.org SPIaddr
rjmp SPI_Interrupt
@@ -34,6 +38,8 @@
.include "adc.inc"
;; Timer
+.set TIMER0_CB_A = SPI_Update
+
.include "timer.inc"
;; Utils
@@ -42,7 +48,8 @@
Sleep_ADC:
; delay
- rcall ADC_Read8
+ ; rcall ADC_Read8
+ rcall DIP_Read8
; Sleep for 64 * var timer cycles
ldi r17, 64
@@ -54,17 +61,27 @@
;; Show value
Main_ShowValue:
+ ; DEBUG
+ sbi PIND, PORTD7
+
; load value to r16
- rcall DIP_Read8
+ ; rcall DIP_Read8
; rcall ADC_Read8
+ rcall Timer0_Read8
; display from r16
rcall LED7_ShowHex
- ; *g*
- ldi XL, 0
- ldi XH, 16
- rcall Timer_Sleep
+ ; wait
+ rcall Sleep_ADC
+
+ ; ldi XL, 0
+ ; ldi XH, 16
+ ; rcall Timer_Sleep
+
+ ; rcall ADC_Read8
+ ; mov r20, r16
+ ; rcall VarDelay
; continue
rjmp Main_ShowValue
@@ -175,10 +192,6 @@
Main:
init:
- ; DEBUG
- sbi DDRD, PORTD7
- sbi PORTD, PORTD7
-
; Stack
ldi r16, high(RAMEND)
ldi r17, low(RAMEND)
@@ -200,9 +213,13 @@
; LCD (requires interrupts, blocks)
rcall LED7_Init
+ ; DEBUG
+ sbi DDRD, PORTD7
+ cbi PORTD, PORTD7
+
; Run
- rcall Main_ShowValue
- ; rcall Main_Spin
+ ; rcall Main_ShowValue
+ rcall Main_Spin
; rcall Main_Countup
; rcall Main_Countdown
; rcall Main_Blink
--- a/spi.inc Sun May 09 23:17:14 2010 +0300
+++ b/spi.inc Sun May 09 23:27:12 2010 +0300
@@ -45,10 +45,24 @@
; Flags
clr r0
out SPI_FLAGS, r0
+
+ ; Start update timer
+ ldi r16, 64 ; every 64k cycles
+ rcall Timer0_Start
; Done
ret
+;; Triggered by Timer0, updates the spi_bufs
+;; Run from timer interrupt context
+SPI_Update:
+ ; skip if updating
+ sbic SPI_FLAGS, SPI_BUSY
+ ret
+
+ ;; Continue
+ ; XXX: blocks too much?
+
;; Send/Recv from/to SPI buffers
SPI_SendRecv:
; Flag
@@ -89,6 +103,8 @@
; End of packet
sbi SPI_PORT, SPI_SS
+
+ cbi SPI_FLAGS, SPI_BUSY
; Done
ret