AN #137 - Valentine Heart |
|
Valentine Heart
This AN is written by Roland van Leusden. It is a
great gift for Valentine's day.
Support
Roland can be reached via his
homepage


This is a small project easy to make on a rainy Sunday. It is using the
Atmel AT90S2313 uC , with a 4Mhz X-tal and 2 x 22pF capacitor. Every I/O pin has
a led connected with 150 Ohm resistor in series to Vcc the Powersupply
Decoupling is done with a 100nF & 10uF (tantaal) capacitor
Reset is connected with a 47K resistor to Vcc
The PCB is shown 200% enlarged. PCB in Traxmaker format
here.
Source code written in Bascom is
here.
Only 47% of the available 2Kb is used, so there is enough room for adding more
effects.
The source code is show here :
' Valentines Heart '
' Leds connected to
Vcc with 150 Ohm to Portb & Portd '
' Portb.x = 0 ->
Led on Portb.x = 1 -> Led off '
' Portd.x = 0 ->
Led on Portd.x = 1 -> Led off '
' '
' By Roland van
leusden 2005 '
' '
$regfile = "2313def.dat"
$crystal = 4000000
Portb = &B1111_1111
Ddrb = &B1111_1111
Portd = &B1111_1111
Ddrd = &B1111_1111
Dim Jump As Byte
Dim Slow As Byte
Do
Jump = 0 ' Leave led on '
Slow = 1 ' slow = 1 500ms delay '
Gosub All_on
Gosub All_off
Gosub All_on
Gosub All_off
Gosub All_on
Gosub All_off
Gosub Rotate_clock
Gosub All_off
Gosub Rotate_anti_clock
Gosub All_off
Jump = 1 ' Jump from led to led '
Gosub Rotate_clock
Gosub All_off
Gosub All_on
Gosub All_off
Gosub Rotate_anti_clock
Gosub All_off
Gosub All_on
Gosub All_off
Slow = 0 ' slow = 0 250ms delay '
Gosub Rotate_clock
Gosub All_off
Gosub Rotate_clock
Gosub All_off
Slow = 1
Jump = 0
Gosub Top2bottom
Gosub All_off
Gosub All_on
Gosub All_off
Gosub Bottom2top
Gosub All_off
Gosub All_on
Gosub All_off
Slow = 0
Gosub Top2bottom
Gosub All_off
Gosub Bottom2top
Gosub All_off
Slow = 1
Jump = 1
Gosub Top2bottom
Gosub All_off
Gosub All_on
Gosub All_off
Gosub Bottom2top
Jump = 0
Gosub All_on
Gosub Die
Gosub Left2right
Gosub All_off
Gosub All_on
Gosub All_off
Gosub Right2left
Gosub All_off
Gosub Rotate_clock
Gosub All_off
Gosub Rotate_clock
Gosub All_off
Loop
' Subroutines '
Delay_250ms:
Waitms 250
Return
All_off:
Portb = &B1111_1111
Portd = &B1111_1111
Gosub Delay_250ms
Gosub Go_slow
Return
All_on:
Portb = &B0000_0000
Portd = &B0000_0000
Gosub Delay_250ms
Gosub Go_slow
Return
Rotate_clock:
Portb.7 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Return
Rotate_anti_clock:
Portd.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.7 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Return
Bottom2top:
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.1 = 0
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.2 = 0
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.3 = 0
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.4 = 0
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.5 = 0
Portd.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.6 = 0
Portd.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.7 = 0
Portd.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Return
Top2bottom:
Portb.7 = 0
Portd.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.6 = 0
Portd.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.5 = 0
Portd.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.4 = 0
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.3 = 0
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.2 = 0
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.1 = 0
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Gosub Check_jump
Return
Die:
Portb.7 = 1
Portd.0 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.6 = 1
Portd.1 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.5 = 1
Portd.2 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.4 = 1
Portd.3 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.3 = 1
Portd.4 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.2 = 1
Portd.5 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.1 = 1
Portd.6 = 1
Gosub Delay_250ms
Gosub Go_slow
Portb.0 = 1
Return
Left2right:
Portb.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.5 = 0
Portb.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.6 = 0
Portb.2 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.7 = 0
Portb.1 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.0 = 0
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.1 = 0
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.2 = 0
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Return
Right2left:
Portd.3 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.2 = 0
Portd.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.1 = 0
Portd.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Portd.0 = 0
Portd.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.0 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.1 = 0
Portb.7 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.2 = 0
Portb.6 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.3 = 0
Portb.5 = 0
Gosub Delay_250ms
Gosub Go_slow
Portb.4 = 0
Gosub Delay_250ms
Gosub Go_slow
Return
Check_jump:
If Jump = 1 Then
Gosub All_off
End If
Return
Go_slow:
If Slow = 1 Then
Gosub Delay_250ms
End If
Return
|