basic implementation done ...
[my-code/atmel.git] / led_plex / main.asm
index 3130055..8d9145b 100644 (file)
@@ -1,5 +1,7 @@
 ; main file of led_plex project
 ;
+; schematics: http://hackdaworld.org/download/led_plex/led_plex.png
+;
 ; author: hackbard@hackdaworld.org
 ;
 
@@ -7,9 +9,15 @@
 .include "../include/tn2313def.inc"
 
 ; defines
+.def   zero            = r1
+.def   one             = r2
 .def   tmp1            = r16
 .def   tmp2            = r17
 .def   uart_rxtx       = r18
+.def   hc595_sink      = r19
+.def   hc595_source    = r20
+.def   column          = r21
+.def   count           = r22
 
 ;
 ; interrupts
@@ -37,7 +45,7 @@ rjmp T1_OVF
 rjmp T0_OVF
 
 ; UART RX
-rjmp UART_RX
+rjmp UART_RECEIVE
 
 ; UART UDRE
 reti
@@ -72,18 +80,27 @@ reti
 ; WDT OVF
 reti
 
-
-; include control defines
-.include "ctrl.def"
+;
+; init and main code
+;
 
 RESET:
 INIT:
 
        ; gio port init
-       rcall GIO_PORT_INIT
+       rcall PORT_INIT
+
+       ; timer0 init
+       rcall TIMER0_INIT
+
+       ; timer0 interrupt enable
+       rcall TIMER0_INT_INIT
+
+       ; timer1 init
+       rcall TIMER1_INIT
 
-       ; timer init
-       rcall TIMER_INIT
+       ; timer1 interrupt enable
+       rcall TIMER1_INT_INIT
 
        ; uart init
        rcall UART_INIT
@@ -91,17 +108,52 @@ INIT:
        ; uart interrupt enable
        rcall UART_INT_RX_INIT
 
+       ; zero and one initialization
+       ldi tmp1,0
+       mov zero,tmp1
+       ldi tmp1,1
+       mov one,tmp1
+
        ; set stackpointer
        ldi tmp1,low(RAMEND)
        out SPL,tmp1
 
-       ; global interrupt enable
-       ;sei 
+       ; framebuffer init: Z :)
+       ldi ZL,low(FB_C)
+       ldi ZH,high(FB_C)
+       ldi tmp1,0xff
+       st Z+,tmp1
+       ldi tmp1,0xc3
+       st Z+,tmp1
+       ldi tmp1,0xa5
+       st Z+,tmp1
+       ldi tmp1,0x99
+       st Z+,tmp1
+       ldi tmp1,0x99
+       st Z+,tmp1
+       ldi tmp1,0xa5
+       st Z+,tmp1
+       ldi tmp1,0xc3
+       st Z+,tmp1
+       ldi tmp1,0xff
+       st Z,tmp1
+
+       ; led init
+       ldi hc595_sink,0x00
+       ldi hc595_source,0x01
+       ldi column,0
+       rcall SET_HC595
+
+       ; more init
+       ldi count,0x21
 
        ; signal ready output
-       ldi uart_rxtx,0x23
+       ldi uart_rxtx,0x68
        rcall UART_TX
 
+       ; global interrupt enable
+       sei 
+
 MAIN:
 
        ; loop forever
@@ -119,11 +171,169 @@ MAIN:
 ;
 
 T1_OVF:
+
+       ;
+       ; write font into framebuffer sram
+       ;
+
+.ifdef DEBUG_PORTS
+       ldi uart_rxtx,0x21
+       rcall UART_TX
+.endif
+       ; calculate address
+
+       ; font base address
+       ldi ZL,low(FONTS*2)
+       ldi ZH,high(FONTS*2)
+.ifdef DEBUG_PORTS
+       mov uart_rxtx,ZH
+       rcall UART_TX
+       mov uart_rxtx,ZL
+       rcall UART_TX
+       ldi uart_rxtx,0x2d
+       rcall UART_TX
+.endif
+
+       ; framebuffer base address
+       ldi YL,low(FB_C)
+       ldi YH,high(FB_C)
+.ifdef DEBUG_PORTS
+       mov uart_rxtx,YH
+       rcall UART_TX
+       mov uart_rxtx,YL
+       rcall UART_TX
+       ldi uart_rxtx,0x2d
+       rcall UART_TX
+.endif
+
+       ; font offset
+       mov XL,count
+       ldi XH,0
+       ; times 8 == 3 left shifts 
+       rol XL
+       rol XH
+       rol XL
+       rol XH
+       rol XL
+       rol XH
+.ifdef DEBUG_PORTS
+       mov uart_rxtx,XH
+       rcall UART_TX
+       mov uart_rxtx,XL
+       rcall UART_TX
+       ldi uart_rxtx,0x2d
+       rcall UART_TX
+.endif
+
+       ; final font address
+       add ZL,XL
+       adc ZH,zero
+       add ZH,XH
+.ifdef DEBUG_PORTS
+       mov uart_rxtx,ZH
+       rcall UART_TX
+       mov uart_rxtx,ZL
+       rcall UART_TX
+       ldi uart_rxtx,0x2d
+       rcall UART_TX
+       mov uart_rxtx,count
+       rcall UART_TX
+.endif
+
+       ; move font data into framebuffer
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z+
+       st Y+,tmp1
+       lpm tmp1,Z
+       st Y,tmp1
+
+       ; TESTING
+       ; increment test counter
+       inc count
+       cpi count,0x80
+       brne EXIT_T1_OVF
+       ldi count,0x21
+
+EXIT_T1_OVF:
+       
        reti
 
 T0_OVF:
+
+       ; debug output
+       cbi PORTD,3
+
+       ; shift source
+       rol hc595_source
+       inc column
+       cpi column,8
+       brne SINK_UPDATE
+       ldi column,0
+       ldi hc595_source,1
+
+       ; update sink
+SINK_UPDATE:
+
+       ldi ZL,low(FB_C)
+       ldi ZH,high(FB_C)
+       add ZL,column
+       adc ZH,zero
+       ld hc595_sink,Z
+
+.ifdef DEBUG_PORTS
+       ldi uart_rxtx,0x2d
+       rcall UART_TX
+       ldi uart_rxtx,0x3e
+       rcall UART_TX
+       ldi uart_rxtx,0x30
+       add uart_rxtx,column
+       rcall UART_TX
+       ldi uart_rxtx,0x3a
+       rcall UART_TX
+       ldi uart_rxtx,0x20
+       rcall UART_TX
+.endif
+
+       ; set hc595
+       rcall SET_HC595
+
+.ifdef DEBUG_PORTS
+       ldi uart_rxtx,0x0a
+       rcall UART_TX
+       ldi uart_rxtx,0x0d
+       rcall UART_TX
+.endif
+
+       ; debug output
+       sbi PORTD,3
+       
        reti
 
-UART_RX:
+UART_RECEIVE:
        reti
 
+; include fonts 
+FONTS:
+.include "fonts.asm"
+
+;
+; sram
+;
+
+.dseg
+
+; current framebuffer content
+FB_C: .byte 8
+
+