free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Rickey's World :: Discussion Forums :: Project Development :: Project Help
 
<< Previous thread | Next thread >>
Simple project
Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage
Author Post
DON JOE JOE
Mon Nov 23 2009, 08:28AM
 User Offline
Registered Member #23963
Joined: Mon Nov 23 2009, 08:11AM

Posts: 1
Thanked 0 times in 0 post
Does anyone know where I can look at an example code of some christmas lights sequences??

Here the code I'm working with
I want to add in more sequences using a switch

#include <REG51.H>
void delay(unsigned char no_loops);

void main()
{
//constant arrays to hold light sequences
unsigned char code port1[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code port3[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char i;
while(1)
{
for (i=0; i<8; i++) //loop through light sequences
{
P1 = port1[i];
P3 = port3[i];
delay(4);
}
}
}

//delay of 50msec * no_loops
//function uses timer 0 in mode 1 to generate a 50msec delay
void delay(unsigned char no_loops)
{
unsigned char x;
TR0 = 0;
TF0 = 0;
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0xB0;
TR0 = 1;
for(x=0;x<no_loops;x++)
{
while(!TF0);
TF0 = 0;
TH0 = 0x3C;
TL0 = 0xB0;
}
TR0 = 0;
}


Back to top

DavesGarage
Mon Nov 23 2009, 01:28PM

 User Offline
Registered Member #14254
Joined: Tue Jan 20 2009, 08:14AM

Posts: 621
Thanked 116 times in 112 posts
I have found it easiest to write out the patterns in binary, and convert to hex afterward when doing this sort of programming...

Here's an example:

single LED lit:
1 0 0 0 0 0 0 0 - 0x80
0 1 0 0 0 0 0 0 - 0x40
0 0 1 0 0 0 0 0 - 0x20
0 0 0 1 0 0 0 0 - 0x10
0 0 0 0 1 0 0 0 - 0x08
0 0 0 0 0 1 0 0 - 0x04
0 0 0 0 0 0 1 0 - 0x02
0 0 0 0 0 0 0 1 - 0x01

double LED lit:
1 0 0 0 0 0 0 1 - 0x81
0 1 0 0 0 0 1 0 - 0x42
0 0 1 0 0 1 0 0 - 0x24
0 0 0 1 1 0 0 0 - 0x18
0 0 0 1 1 0 0 0 - 0x18
0 0 1 0 0 1 0 0 - 0x24
0 1 0 0 0 0 1 0 - 0x42
1 0 0 0 0 0 0 1 - 0x81



Depending on your sequence, you can get pretty imaginative...

These examples only have a sequence of 8, but be creative and try different lengths...


-Dave
"Basic research is what I am doing when I don't know what I am doing"
Back to top

 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems