;ildclock - program to display the time on a 6x6 led board by lighting ;the amount of red, green, blue leds in the hours, minutes and seconds. ;See ;http://sprite.student.utwente.nl/~jeroen/projects/ildclock/ ;and ;http://gathering.tweakers.net/forum/list_messages/1144387/ ;for more info ;This software is licensed under the GNU GPL. ;(c) 2006 Jeroen Domburg ;We're using a tiny2313 here. .device ATTiny2313 ;You might want to include the ATTiny2313-definitions included with ;your assembler. I use gavrasm, which doesn't need them. ;.include "tn2313def.inc" ;The fuses should be configured as follows: ;FUSE_L=0xff ;FUSE_H=0xdf .def dat = r0 ;Data from an lpm instruction ends up here .def temp = R16 ;The temp register .def temp2 = R17 ;Second temp register .def temp3 = R18 .def row = r19 .def framebaddr = r20 ;address of data to be displayed .def framebaddr2= r21 ;address of data to be faded to .def fadeamt = r23 .def fadectr = r24 .def random = r25 .def random2 = r26 .def ylo = r28 .def yhi = r29 .def zlo = r30 .def zhi = r31 rjmp start ; reset vector reti ; External Int 0 not enabled reti ; External Int 1 not enabled reti ; Timer 1 Capture Int not enabled reti ; Timer 1 Compare match A Int not enabled reti ; Timer 1 Overflow Int not enabled rjmp handledisp ; Timer 0 Overflow Int not enabled reti ; UART ReceiveInt reti ; UART Date Reg Empty Int not enabled reti ; UART tx'ed Int Not enabled reti ; Anacomp interrupt Not enabled start: ldi temp,RAMEND ; top of memory out SPL,temp ; init stack pointer ldi temp,$ff ; Port B direction options ldi temp,0 out tccr0a,temp ldi temp,2 out tccr0b,temp ldi temp,2 out timsk,temp ;random seed ldi random,$aa ldi random2,$55 ldi framebaddr,RAMEND-127 ldi framebaddr2,RAMEND-127+6 mov yl,framebaddr vast: sei ;Wait a few secs ldi temp,100 waitloop: rcall wachtff dec temp brne waitloop ;fill backbuffer with (for now, random) data ldi temp2,6 mov yl,framebaddr2 fill: rcall getrandom st y+,random dec temp2 brne fill ;fade from front- to backbuffer ldi fadeamt,0 fadeloop: rcall wachtff inc fadeamt andi fadeamt,15 cpi fadeamt,0 brne fadeloop ;exchange front- and backbuffer mov temp,framebaddr mov framebaddr,framebaddr2 mov framebaddr2,temp rjmp vast ; Routine: wachtff ;Waits a certain amount of time wachtff: push temp push temp2 ldi temp,0 loop1: ldi temp2,0 loop2: nop nop nop nop nop nop nop nop dec temp2 brne loop2 dec temp brne loop1 pop temp2 pop temp ret ; Routine: getrandom ;Random number generator - polynomial = x15 + x + 1 ;Returns a new random number in random getrandom: push temp push temp2 ldi temp,8 rngnextbit: ldi temp2,1 lsl random rol random2 brcc rngnobit15 inc temp2 rngnobit15: sbrc random,1 inc temp2 andi temp2,1 eor random,temp2 dec temp brne rngnextbit pop temp2 pop temp ret ;------------------------------ ;Interrupt routine: handles the display handledisp: push temp in temp,sreg push temp push temp2 push ylo ;Display row-th data from the display buffer mov temp,row inc temp ldi temp2,0 sec dispcalcradloop: rol temp2 dec temp brne dispcalcradloop ;get row data subi fadectr,-15 andi fadectr,15 mov ylo,framebaddr cp fadectr,fadeamt brge nouse2ndbuff mov ylo,framebaddr2 nouse2ndbuff: add ylo,row ld temp,y ;All the bits in content should be set in both ddrb and portb ;The pos'th bit should only be set in ddrb or temp,temp2 com temp2 out ddrb,temp and temp,temp2 out portb,temp ;Increase row addr and check and reset if row=6 inc row cpi row,6 brne dispnorstrow ldi row,0 inc fadectr ;to get proper interlacing etc dispnorstrow: ;Display code end pop ylo pop temp2 pop temp out sreg,temp pop temp reti