X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=led_plex%2Fmain.asm;h=8d9145ba17c3708625568ce4cde6db690a7e4dee;hb=32e3f51bc0f4248019379fe784d38c7fb770f952;hp=23b33c37deec5bcf948d3b2eb1bc084bd8926050;hpb=204affb08caa9c97cdd1cc010f5a8fbaa0571992;p=my-code%2Fatmel.git diff --git a/led_plex/main.asm b/led_plex/main.asm index 23b33c3..8d9145b 100644 --- a/led_plex/main.asm +++ b/led_plex/main.asm @@ -9,11 +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 @@ -86,8 +90,17 @@ INIT: ; gio port init rcall PORT_INIT - ; timer init - ;rcall TIMER_INIT + ; timer0 init + rcall TIMER0_INIT + + ; timer0 interrupt enable + rcall TIMER0_INT_INIT + + ; timer1 init + rcall TIMER1_INIT + + ; timer1 interrupt enable + rcall TIMER1_INT_INIT ; uart init rcall UART_INIT @@ -95,23 +108,51 @@ 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,0x68 rcall UART_TX - ; testing ... DO NOT CONNECT LEDS BY NOW !!! - ldi hc595_sink,0xff - ldi hc595_source,0xff - rcall SET_HC595 - ldi uart_rxtx,0x61 - rcall UART_TX + ; global interrupt enable + sei MAIN: @@ -130,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_RECEIVE: reti +; include fonts +FONTS: +.include "fonts.asm" + +; +; sram +; + +.dseg + +; current framebuffer content +FB_C: .byte 8 + +