Full Version : Winslow Rotating Message Machine (AVR ASM)
avr >>LIGHT & VISION PROJECTS >>Winslow Rotating Message Machine (AVR ASM)


Admin3- 04-18-2006
Project description:
For my final design project I decided to design and build a digital dot matrix message device. I’ve seen devices similar to this before and I wanted to find out if I could build one myself. The display consists of 7 LEDs in a vertical row. By moving them fast enough back and forth over each other, I can display a message which appears to be generated by a 7*n matrix of LEDs and not a single column of LEDs.

Link: http://instruct1.cit.cornell.edu/courses/e...nslow/index.htm

CODE

;***** Simple time-based scheduler ********
;LED display code for spinning disc
;
;********************************
;You will need to CHANGE this path
;,nolist
.include "c:\users\jkw10\8515def.inc"
.list
;********************************
;define registers
.def save  =r1
.def Letter  =r3;Letter Value
.def clock0  =r4;time between hit and display
.def complow  =r5;compare values for position
.def comphigh =r6
.def spacelow =r9;used to computer the spacing
.def spacehigh =r10;between flashes on wand
.def temp  =r16;temporary register
.def LED  =r17;the actual LED value to display
.def reload  =r18;holds timer reload value
.def Cin  =r19;Input from PortC
.def checksensor =r20;check sensor flag
.def letterpos =r21;Which of the 7 letter portion outputs
.def state  =r22;state of state machine
.def spacecounter =r23;counter for value of spacing
.def Letnum  =r24;Which of the 14 letters are we now displaying
.def perlow  =r28;Holds ticks for wheel period low
.def perhigh  =r29;Holds ticks for wheel period high

.equ messagelength=16
;************************************************************************
; Initialization
.cseg
.org $0000
rjmp RESET;reset entry vector
reti  
reti
reti
reti
reti
reti
rjmp TIMER
reti
reti  
reti
reti
reti
;*************************************************************************
;The following include file contains the db table containing
;all the rastorization information for the LED display segments
;
;The table after that contains references to sections of the
;rastorization table
;15 references the 15th line in the rastorization table
;which references the segment information for the letter E

.include "c:\users\jkw10\rastor2.inc"
Message: .db  63,63,63,63,63,63,63,15,15,4,7,6,63,63,63,63
;.db  19,63,22,51,58,41,63,14,45,50,51,65,55,63;I Love Dino's
;*************************************************************************

RESET:
ldi Temp, LOW(RAMEND) ;setup stack pointer
out  SPL, Temp
ldi Temp, HIGH(RAMEND)
out SPH, Temp

;set up the PORTs
ser Temp ;set PORTB to be
out DDRB,Temp;all outputs
ldi Temp, 0xff;turn off LEDs
out PortB, Temp
clr Temp ;set PORTC to be
out DDRC,Temp;all inputs

;set up timer 0 for 10 uSec ticks
ldi Temp,exp2(TOIE0);enable timer interrupt
out TIMSK, Temp
ldi  Temp, 3 ;prescale timer by 64
out  TCCR0, Temp
ldi Reload,256-1;preload timer since
out  TCNT0, Reload;1 x (64x.125) microSec = 8 uSec.

;initialize variables
ldi LED, 0xff;initialize all variables
ldi letnum,0
ldi state,0
ldi temp,0
mov Letnum,temp

;Start the clock ticking
sei  ;enable all interrupts
;**************************************************************

SPIN: cpi checksensor,0;this ensures that the phototransistor
brne done ;makes a revolution before another hit
in Cin,PinC;check phototransistor
sbrc Cin, 0
rjmp done
rcall SensorHit;call subroutine if a hit
done: rjmp SPIN ;now all work is done by intr routine

GetLetter:
ldi temp,messagelength
cp letnum,temp
breq lettermax
ldi temp,0
ldi ZL, low(message*2);table pointer in FLASH
ldi ZH, high(message*2);so convert from word to byte addr
add ZL, Letnum ;double precision add for specific letter
adc ZH, temp  
inc letnum
lpm
rjmp getletter2
lettermax:
ldi temp,63
mov r0,temp
getletter2:
ldi temp,0
mov letter,r0
ldi ZL, low(rastor*2)
ldi ZH, high(rastor*2)
lsl letter ;rastorization.db is 8*65
add Zl,letter;so letter is between 0 and 65
adc ZH,temp ;but we need to point to proper byte addres so
add Zl,letter;the following lines add letter*8 to the pointer
adc ZH,temp ;I shift once and add 4 times to maintain letter
add Zl,letter;as only 1 byte
adc ZH,temp ;2 shifts might result in overflow
add Zl,letter;overflow=bad
adc ZH,temp ;bad=no worky
ret

SensorHit:
ldi letnum,0;reset all variables
ldi state,0
ldi checksensor,1
mov complow,perlow
mov comphigh,perhigh
ldi LED,0xff;turn all LEDs off
out PortB,LED
lsr comphigh;computer cycle/2
ror complow ;for when to begin display
mov spacelow,perlow;use for letter spacing
mov spacehigh,perhigh
ldi perlow,0
ldi perhigh,0
ret
;**************************************************************
;timer 0 ISR (timer-zero overflow)
;Enters every 8 uSec

TIMER: in save, SREG
out  TCNT0, Reload; keeps clock ticking at 9 usec
push temp
adiw perlow, 1;increment period counter
cpi state,0
breq state0
cpi state,1
breq state1
cpi state,2
breq state2

state0: cp perlow,complow;compare to period/2 to begin display
brne t0end
cp perhigh,comphigh
brne t0end
ldi checksensor,0
ldi state,1
rjmp t0end

state1: rcall Getletter;Call get letter
ldi state,2
ldi letterpos,7

state2: cpi spacecounter,0;Spacing for letter display
breq state2_2
dec spacecounter
rjmp t0end

state2_2:
mov spacecounter,spacehigh
lpm
out PortB,r0;Output the next letter segment
adiw ZL,1 ;increment memory pointer
cpi letterpos,0
breq letterdone;If letter is done, reset letterpos and state
dec letterpos
rjmp t0end

letterdone:
ldi state,1
ldi letterpos,7

t0end: pop temp
out SREG, save
reti  ;back to backgound tasks
;**************************************************************




Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.