Personal tools
User menu

Difference between revisions of "ChristmasTree2012"

From Francois Louw

Jump to: navigation, search
Line 5: Line 5:
 
==Schematic==
 
==Schematic==
 
[[File:tree-2012-schematic.jpg|300px]]
 
[[File:tree-2012-schematic.jpg|300px]]
 +
The MCLR resistor is 4.7K and the LED resistors will depend on your LEDs. Remember that there is a limit on the amount of current that the PIC can supply. I limited my 2V LEDs to 0.8mA by using 3.8K Resistors.
 +
 +
==Source Code==
 +
The code was written in C using MPLAB 8.6 and the HiTech C Compiler.
 +
 +
Here's the source code
 +
<source lang="c">
 +
#include <htc.h>
 +
__CONFIG(HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS & DEBUGEN);
 +
 +
#define LW RB0
 +
#define HR RB1
 +
#define LR RB2
 +
#define TR RB3
 +
#define MR RB4
 +
#define TW RB5
 +
#define MG RC0
 +
#define LG RC1
 +
#define HG RC2
 +
#define TG RC3
 +
#define HW RC6
 +
#define MW RC7
 +
#define HB RA0
 +
#define TB RA1
 +
#define MB RA2
 +
#define LB RA3
 +
 +
#ifndef _XTAL_FREQ
 +
#define _XTAL_FREQ 10000000
 +
#endif
 +
 +
void delay()
 +
{
 +
__delay_ms(500);
 +
}
 +
 +
void all(int i)
 +
{
 +
LW = i;
 +
MW = i;
 +
HW = i;
 +
TW = i;
 +
 +
LR = i;
 +
MR = i;
 +
HR = i;
 +
TR = i;
 +
 +
LG = i;
 +
MG = i;
 +
HG = i;
 +
TG = i;
 +
 +
LB = i;
 +
MB = i;
 +
HB = i;
 +
TB = i;
 +
 +
}
 +
 +
void white(int i)
 +
{
 +
LW = i;
 +
MW = i;
 +
HW = i;
 +
TW = i;
 +
}
 +
void red(int i)
 +
{
 +
LR = i;
 +
MR = i;
 +
HR = i;
 +
TR = i;
 +
}
 +
void green(int i)
 +
{
 +
LG = i;
 +
MG = i;
 +
HG = i;
 +
TG = i;
 +
}
 +
void blue(int i)
 +
{
 +
LB = i;
 +
MB = i;
 +
HB = i;
 +
TB = i;
 +
}
 +
void low(int i)
 +
{
 +
LW = i;
 +
LR = i;
 +
LG = i;
 +
LB = i;
 +
}
 +
void middle(int i)
 +
{
 +
MW = i;
 +
MR = i;
 +
MG = i;
 +
MB = i;
 +
}
 +
void high(int i)
 +
{
 +
HW = i;
 +
HR = i;
 +
HG = i;
 +
HB = i;
 +
}
 +
void top(int i)
 +
{
 +
TW = i;
 +
TR = i;
 +
TG = i;
 +
TB = i;
 +
}
 +
void north(int i)
 +
{
 +
LB = i;
 +
MG = i;
 +
HW = i;
 +
TR = i;
 +
}
 +
void east(int i)
 +
{
 +
LG = i;
 +
MW = i;
 +
HR = i;
 +
TB = i;
 +
}
 +
void south(int i)
 +
{
 +
LW = i;
 +
MR = i;
 +
HB = i;
 +
TG = i;
 +
}
 +
void west(int i)
 +
{
 +
LR = i;
 +
MB = i;
 +
HG = i;
 +
TW = i;
 +
}
 +
 +
void spiralbottom(int i)
 +
{
 +
LW = i;
 +
delay();
 +
MW = i;
 +
delay();
 +
HW = i;
 +
delay();
 +
TW = i;
 +
delay();
 +
 +
LR = i;
 +
delay();
 +
MR = i;
 +
delay();
 +
HR = i;
 +
delay();
 +
TR = i;
 +
delay();
 +
 +
LG = i;
 +
delay();
 +
MG = i;
 +
delay();
 +
HG = i;
 +
delay();
 +
TG = i;
 +
delay();
 +
 +
LB = i;
 +
delay();
 +
MB = i;
 +
delay();
 +
HB = i;
 +
delay();
 +
TB = i;
 +
delay();
 +
}
 +
 +
void main(void)
 +
{
 +
OPTION = 0;
 +
GIE = 0;
 +
 +
TMR1ON = 0;
 +
TMR2ON = 0;
 +
 +
SSPEN = 0;
 +
SPEN = 0;
 +
SREN = 0;
 +
CREN = 0;
 +
ADDEN = 0;
 +
 +
 +
//set ports and timers
 +
TRISA0 = 0;
 +
TRISA1 = 0;
 +
TRISA2 = 0;
 +
TRISA3 = 0;
 +
TRISA4 = 1;
 +
TRISA5 = 0;
 +
 +
TRISB0 = 0;
 +
TRISB1 = 0;
 +
TRISB2 = 0;
 +
TRISB3 = 0;
 +
TRISB4 = 0;
 +
TRISB5 = 0;
 +
 +
TRISC0 = 0;
 +
TRISC1 = 0;
 +
TRISC2 = 0;
 +
TRISC3 = 0;
 +
TRISC4 = 0;
 +
TRISC5 = 0;
 +
TRISC6 = 0;
 +
TRISC7 = 0;
 +
 +
//disable A/D
 +
ADON = 0;
 +
//all digital
 +
PCFG3 = 0;//no ref
 +
PCFG2 = 1;
 +
PCFG1 = 1;
 +
PCFG0 = 0;//no care
 +
 +
//diable capture compare
 +
CCP1CON = 0;
 +
CCP2CON = 0;
 +
 +
all(0);
 +
 +
while(1)
 +
{
 +
//flash all
 +
all(1);
 +
delay();
 +
all(0);
 +
delay();
 +
all(1);
 +
delay();
 +
all(0);
 +
delay();
 +
all(1);
 +
delay();
 +
all(0);
 +
delay();
 +
all(1);
 +
delay();
 +
all(0);
 +
delay();
 +
all(1);
 +
delay();
 +
all(0);
 +
delay();
 +
 +
//colours
 +
white(1);
 +
delay();
 +
white(0);
 +
red(1);
 +
delay();
 +
red(0);
 +
green(1);
 +
delay();
 +
green(0);
 +
blue(1);
 +
delay();
 +
blue(0);
 +
delay();
 +
 +
//reset
 +
all(0);
 +
 +
//bottom to top
 +
low(1);
 +
delay();
 +
middle(1);
 +
delay();
 +
high(1);
 +
delay();
 +
top(1);
 +
delay();
 +
 +
//top to bottom
 +
top(0);
 +
delay();
 +
high(0);
 +
delay();
 +
middle(0);
 +
delay();
 +
low(0);
 +
delay();
 +
 +
//side to side circle on
 +
north(1);
 +
delay();
 +
east(1);
 +
delay();
 +
south(1);
 +
delay();
 +
west(1);
 +
delay();
 +
//side to side circle off
 +
north(0);
 +
delay();
 +
east(0);
 +
delay();
 +
south(0);
 +
delay();
 +
west(0);
 +
delay();
 +
 +
//spiral colours up
 +
spiralbottom(1);
 +
spiralbottom(0);
 +
}
 +
 +
}
 +
</source>
 +
 +
==Result==
 +
Here are pictures of the final result (ignore the quality of the makeshift wire tree)

Revision as of 18:12, 16 December 2012