AVR心形流水灯制作
以下内容为本人大二时给朋友做的生日礼物后写的笔记,最近偶然翻到,所以发出来也算留一下备份,所以文笔相当稚嫩,代码相当粗糙(手动狗头),欢迎各位大神批评指正。视频改日再贴。。。
AVR心形流水灯制作
视频如下:
AVR心形流水灯
这个可能看着比较难做,但是其实一点都不难,有一点焊接基础的人可能半个多小时就能焊完(小编当时排版就用了半个小时,焊了1天多。。。)最难的其实是程序,不过小编一会会在后面把程序分享给大家(小编当时写了3天,默默哭3分钟心形流水灯制作)。
下面说说都需要什么零件和工具,一个ATmega16单片机心形流水灯制作
下面附上该单片机原理图。这个单片机应该是这些零件里面最贵的了,貌似网上卖7.9,还需要一个底座,买个最便宜的网上貌似0.22(如果你觉得你的焊接技术足够可以可以不买),1个9*15的万用板(小编用了2个,另一个用铜柱固定在流水灯下面当底座,被同学骂成败家。。。)一个电池盒(3节5号电池的),小编做的是两种供电方式的,还有用usb供电的东西,但是那东西不零卖,所以咱们还是消停点就单独用电池盒供电得了。。。一个开关(什么开关无所谓),16个5mmLED灯,个人觉得蓝色和白色的比较好看。16个电阻(470欧姆到1k欧姆都可以),一个8M晶振,2个30pF电容,一个0.1pF电容。零件就这些,下面说一下工具:电烙铁,焊锡,吸锡器,跳线(杜邦线什么的都可以),螺丝,螺丝刀。
下面要开始制作了,先说一下最重要的面子活——排版,一定确定自己排的是心形。。。(小编的逗比同学硬生生排成了菱形,被小编嘲笑了好久),尽量把灯向左排,这样右面剩下的地方就能放下一个电池盒。一定要注意灯的负极指向的是单片机引脚(PS:长脚是正极,短脚是负极,这应该没有人不知道吧。。。)。排完之后先把单片机和灯焊上,下一步按照单片机最小系统原理图把各种元件焊上让单片机能工作心形流水灯制作
心形流水灯制作。下一步插电阻,小编建议尽量把电阻插在引脚旁边,这样看起来比较整齐。接下来就要开始布线,建议先拿记号笔把自己要排的线画出来,尽量做到不冲突,不然就要跳线了,因为小编是认识人中第一个焊的,没有参考,所以跳的线有点多。。。最后焊完之后从单片机的VCC和GND各自引出一根线用来给单片机供电(VCC是正极,GND是负极),开关放在VCC和GND哪条引线上都行,接下来开始最后一步,先把电池盒固定上:先选好要把电池盒放在哪,然后在它旁边钻一个洞(可以拿螺丝刀弄,也可以拿烙铁烫,小编是拿烙铁烫的,那味道,,,结果小编差点没被室友撵出去,,,所以建议还是拿螺丝刀慢慢钻把。。。),把电池盒的两条线从洞里面穿出去,红线接到VCC上,黑线接到GND上,再去随便找一个有ATmega16开发板或者最小系统的朋友,让他把程序下进去就可以了,最后试试好不好使,要是不好使检查一下连线有没有错误,不要来打小编
程序如下:
//作者:Kevin Wang
//开发环境:ICC7
//时间:2016.03.24
#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
unsigned int count;
char a;
char b;
char temp1;
char temp2;
char c;
char d;
char temp3;
char temp4;
char e;
char temp5;
char temp6;
char f;
char temp7;
char temp8;
char g;
char temp9;
char temp10;
char h;
char temp11;
char temp12;
/*********以下是延时函数*********/
void Delay_ms(uint xms)
{
int i,j;
for(i=0;i<xms;i++)
for(j=0;j<1140;j++);
}
/**********huxi_Init**********/
void huxi()
{
for(count=100;count<256;count++) //OCR=0时,LED最亮,然后逐渐变暗
{
OCR0=count; //比较匹配寄存器赋值
Delay_ms(2); //延时一段时间,以观察效果
}
for(count=255;count>99;count--) //OCR=255时,LED最暗,然后逐渐变亮
{
OCR0= count;
Delay_ms(2);
}
}
void port_init()
{
DDRA=0xff;
DDRD=0xff;
PORTA=0x00;
PORTD=0x00;
DDRB|=(1<<PB3); //PB3配置为输出(为1时用或符号|)
PORTB&=(0<<PB3); //PB3输出0(为0时与符号&)
}
/********定时器0初始化********/
void timer0_init()
{
TCCR0|=(1<<WGM01)|(1<<WGM00);//定时器0快速PWM模式
TCCR0|=(1<<COM01)|(1<<COM00);//比较匹配发生时OC0A置位,计数到TOP时OC0清零
TCCR0|=(0<<CS02)|(1<<CS01)|(1<<CS00); //定时器1024分频
OCR0=0;
SREG = 0x80;
}
/******************呼吸 中速***********************/
void huxizhong()
{
PORTA=0x00;
PORTD=0x00;
for(count=100;count<256;count++) //OCR=0时,LED最亮,然后逐渐变暗
{
OCR0=count; //比较匹配寄存器赋值
Delay_ms(5); //延时一段时间,以观察效果
}
for(count=255;count>99;count--) //OCR=255时,LED最暗,然后逐渐变亮
{
OCR0= count;
Delay_ms(5);
}
}
/*****************呼吸 快速*******************/
void huxikuai()
{
PORTA=0x00;
PORTD=0x00;
for(count=100;count<256;count++) //OCR=0时,LED最亮,然后逐渐变暗
{
OCR0=count; //比较匹配寄存器赋值
Delay_ms(3); //延时一段时间,以观察效果
}
for(count=255;count>99;count--) //OCR=255时,LED最暗,然后逐渐变亮
{
OCR0= count;
Delay_ms(3);
}
}
/****************呼吸 超快***************/
void huxichaokuai()
{
PORTA=0x00;
PORTD=0x00;
for(count=100;count<256;count++) //OCR=0时,LED最亮,然后逐渐变暗
{
OCR0=count; //比较匹配寄存器赋值
Delay_ms(2); //延时一段时间,以观察效果
}
for(count=255;count>99;count--) //OCR=255时,LED最暗,然后逐渐变亮
{
OCR0= count;
Delay_ms(2);
}
}
/*************流水1**************/
void liushui1()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
Delay_ms(200);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(200);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(200);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(200);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(200);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(200);
PORTA=0x07;
PORTD=0x03;
Delay_ms(200);
PORTA=0x03;
PORTD=0x01;
Delay_ms(200);
PORTA=0x01;
PORTD=0x00;
Delay_ms(200);
PORTA=0x00;
PORTD=0x00;
Delay_ms(200);
}
/*************流水1 反*************/
void liushui1fan()
{
OCR0=count;
count=100;
PORTA=0x00;
PORTD=0x00;
Delay_ms(200);
PORTA=0x01;
PORTD=0x00;
Delay_ms(200);
PORTA=0x03;
PORTD=0x01;
Delay_ms(200);
PORTA=0x07;
PORTD=0x03;
Delay_ms(200);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(200);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(200);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(200);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(200);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(200);
PORTA=0xff;
PORTD=0xff;
Delay_ms(200);
}
/************流水灯 1 +呼吸*********/
void liushui1huxi()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
huxi();
PORTA=0xff;
PORTD=0x7f;
huxi();
PORTA=0x7f;
PORTD=0x3f;
huxi();
PORTA=0x3f;
PORTD=0x1f;
huxi();
PORTA=0x1f;
PORTD=0x0f;
huxi();
PORTA=0x0f;
PORTD=0x07;
huxi();
PORTA=0x07;
PORTD=0x03;
huxi();
PORTA=0x03;
PORTD=0x01;
huxi();
PORTA=0x01;
PORTD=0x00;
huxi();
PORTA=0x00;
PORTD=0x00;
huxi();
}
/*************流水1 呼吸 反*************/
void liushui1huxifan()
{
OCR0=count;
count=100;
PORTA=0x00;
PORTD=0x00;
huxi();
PORTA=0x01;
PORTD=0x00;
huxi();
PORTA=0x03;
PORTD=0x01;
huxi();
PORTA=0x07;
PORTD=0x03;
huxi();
PORTA=0x0f;
PORTD=0x07;
huxi();
PORTA=0x1f;
PORTD=0x0f;
huxi();
PORTA=0x3f;
PORTD=0x1f;
huxi();
PORTA=0x7f;
PORTD=0x3f;
huxi();
PORTA=0xff;
PORTD=0x7f;
huxi();
PORTA=0xff;
PORTD=0xff;
huxi();
}
/*****************流水 2************///2个灯跑
void liushui2()
{
OCR0=count;
count=100;
PORTA=0xfc;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf9;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf3;
PORTD=0xff;
Delay_ms(100);
PORTA=0xe7;
PORTD=0xff;
Delay_ms(100);
PORTA=0xcf;
PORTD=0xff;
Delay_ms(100);
PORTA=0x9f;
PORTD=0xff;
Delay_ms(100);
PORTA=0x3f;
PORTD=0xff;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xff;
PORTD=0x3f;
Delay_ms(100);
PORTA=0xff;
PORTD=0x9f;
Delay_ms(100);
PORTA=0xff;
PORTD=0xcf;
Delay_ms(100);
PORTA=0xff;
PORTD=0xe7;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf3;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf9;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfc;
Delay_ms(100);
}
/*************流水 2 反**************/
void liushui2fan()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xfc;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf9;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf3;
Delay_ms(100);
PORTA=0xff;
PORTD=0xe7;
Delay_ms(100);
PORTA=0xff;
PORTD=0xcf;
Delay_ms(100);
PORTA=0xff;
PORTD=0x9f;
Delay_ms(100);
PORTA=0xff;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x7f;
Delay_ms(100);
PORTA=0x3f;
PORTD=0xff;
Delay_ms(100);
PORTA=0x9f;
PORTD=0xff;
Delay_ms(100);
PORTA=0xcf;
PORTD=0xff;
Delay_ms(100);
PORTA=0xe7;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf3;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf9;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfc;
PORTD=0xff;
Delay_ms(100);
}
/***********流水 3************/
void liushui3()
{
OCR0=count;
count=100;
PORTA=0x55;
PORTD=0xaa;
Delay_ms(500);
PORTA=0xaa;
PORTD=0x55;
Delay_ms(500);
}
/**********流水 3快1**********/
void liushui3kuai1()
{
OCR0=count;
count=100;
PORTA=0x55;
PORTD=0xaa;
Delay_ms(300);
PORTA=0xaa;
PORTD=0x55;
Delay_ms(300);
}
/************流水 3快2**********/
void liushui3kuai2()
{
OCR0=count;
count=100;
PORTA=0x55;
PORTD=0xaa;
Delay_ms(100);
PORTA=0xaa;
PORTD=0x55;
Delay_ms(100);
}
/***********流水 4*********/ //1个灯流水
void liushui4()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
temp1=0xfe;
temp2=0x7f;
for(a=0;a<8;a++)
{
PORTA=temp1;
Delay_ms(100);
temp1=temp1<<1;
}
for(b=0;b<8;b++)
{
PORTD=temp2;
Delay_ms(100);
temp2=temp2>>1;
}
}
/************流水4 反************/
void liushui4fan()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
temp3=0xff;
temp4=0xfe;
for(c=0;c<8;c++)
{
PORTD=temp4;
Delay_ms(100);
temp4=temp4<<1;
}
for(d=0;d<8;d++)
{
PORTA=temp3;
Delay_ms(100);
temp3=temp3>>1;
}
}
/*************流水灯 5*********/ //1个灯跑
void liushui5()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xff;
Delay_ms(100);
PORTA=0xef;
PORTD=0xff;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xff;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xff;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xff;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xff;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xff;
PORTD=0xdf;
Delay_ms(100);
PORTA=0xff;
PORTD=0xef;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfe;
Delay_ms(100);
}
/****************流水灯 5 反**********/ //1个灯跑 反
void liushui5fan()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
PORTA=0xff;
PORTD=0xfe;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xff;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xff;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xff;
PORTD=0xef;
Delay_ms(100);
PORTA=0xff;
PORTD=0xdf;
Delay_ms(100);
PORTA=0xff;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xff;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xff;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xff;
Delay_ms(100);
PORTA=0xef;
PORTD=0xff;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
}
/****************流水 6**********/
void liushui6()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
temp5=0xfe;
temp6=0x7f;
for(e=0;e<8;e++)
{
PORTA=temp5;
PORTD=temp6;
Delay_ms(100);
temp5=temp5<<1;
temp6=temp6>>1;
}
}
/****************流水 6 反**********/
void liushui6fan()
{
OCR0=count;
count=100;
temp7=0x7f;
temp8=0xfe;
for(e=0;e<8;e++)
{
PORTA=~temp7;
PORTD=~temp8;
Delay_ms(100);
temp7=temp7>>1;
temp8=temp8<<1;
}
}
/************流水灯 7*********/
void liushui7()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
Delay_ms(5);
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xfe;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xef;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xef;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xdf;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xfe;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xfd;
PORTD=0x7e;
Delay_ms(100);
PORTA=0xfb;
PORTD=0x7d;
Delay_ms(100);
PORTA=0xf7;
PORTD=0x7b;
Delay_ms(100);
PORTA=0xef;
PORTD=0x77;
Delay_ms(100);
PORTA=0xdf;
PORTD=0x6f;
Delay_ms(100);
PORTA=0xbf;
PORTD=0x5f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7e;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7d;
PORTD=0x3e;
Delay_ms(100);
PORTA=0x7b;
PORTD=0x3d;
Delay_ms(100);
PORTA=0x77;
PORTD=0x3b;
Delay_ms(100);
PORTA=0x6f;
PORTD=0x37;
Delay_ms(100);
PORTA=0x5f;
PORTD=0x2f;
Delay_ms(100);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x3e;
PORTD=0x1f;
Delay_ms(150);
PORTA=0x3d;
PORTD=0x1e;
Delay_ms(150);
PORTA=0x3b;
PORTD=0x1d;
Delay_ms(150);
PORTA=0x37;
PORTD=0x1b;
Delay_ms(150);
PORTA=0x2f;
PORTD=0x17;
Delay_ms(150);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(150);
PORTA=0x1e;
PORTD=0x0f;
Delay_ms(150);
PORTA=0x1d;
PORTD=0x0e;
Delay_ms(150);
PORTA=0x1b;
PORTD=0x0d;
Delay_ms(150);
PORTA=0x17;
PORTD=0x0b;
Delay_ms(150);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(150);
PORTA=0x0e;
PORTD=0x07;
Delay_ms(200);
PORTA=0x0d;
PORTD=0x06;
Delay_ms(200);
PORTA=0x0b;
PORTD=0x05;
Delay_ms(200);
PORTA=0x07;
PORTD=0x03;
Delay_ms(200);
PORTA=0x06;
PORTD=0x03;
Delay_ms(200);
PORTA=0x05;
PORTD=0x02;
Delay_ms(200);
PORTA=0x03;
PORTD=0x01;
Delay_ms(200);
PORTA=0x02;
PORTD=0x01;
Delay_ms(200);
PORTA=0x01;
PORTD=0x00;
Delay_ms(200);
///////////////////////////////////////
PORTA=0x01;
PORTD=0x00;
Delay_ms(200);
PORTA=0x02;
PORTD=0x01;
Delay_ms(200);
PORTA=0x03;
PORTD=0x01;
Delay_ms(200);
PORTA=0x05;
PORTD=0x02;
Delay_ms(200);
PORTA=0x06;
PORTD=0x03;
Delay_ms(200);
PORTA=0x07;
PORTD=0x03;
Delay_ms(200);
PORTA=0x0b;
PORTD=0x05;
Delay_ms(200);
PORTA=0x0d;
PORTD=0x06;
Delay_ms(200);
PORTA=0x0e;
PORTD=0x07;
Delay_ms(200);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(150);
PORTA=0x17;
PORTD=0x0b;
Delay_ms(150);
PORTA=0x1b;
PORTD=0x0d;
Delay_ms(150);
PORTA=0x1d;
PORTD=0x0e;
Delay_ms(150);
PORTA=0x1e;
PORTD=0x0f;
Delay_ms(150);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(150);
PORTA=0x2f;
PORTD=0x17;
Delay_ms(150);
PORTA=0x37;
PORTD=0x1b;
Delay_ms(150);
PORTA=0x3b;
PORTD=0x1d;
Delay_ms(150);
PORTA=0x3d;
PORTD=0x1e;
Delay_ms(150);
PORTA=0x3e;
PORTD=0x1f;
Delay_ms(150);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x5f;
PORTD=0x2f;
Delay_ms(100);
PORTA=0x6f;
PORTD=0x37;
Delay_ms(100);
PORTA=0x77;
PORTD=0x3b;
Delay_ms(100);
PORTA=0x7b;
PORTD=0x3d;
Delay_ms(100);
PORTA=0x7d;
PORTD=0x3e;
Delay_ms(100);
PORTA=0x7e;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(100);
PORTA=0xbf;
PORTD=0x5f;
Delay_ms(100);
PORTA=0xdf;
PORTD=0x6f;
Delay_ms(100);
PORTA=0xef;
PORTD=0x77;
Delay_ms(100);
PORTA=0xf7;
PORTD=0x7b;
Delay_ms(100);
PORTA=0xfb;
PORTD=0x7d;
Delay_ms(100);
PORTA=0xfd;
PORTD=0x7e;
Delay_ms(100);
PORTA=0xfe;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xdf;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xef;
Delay_ms(100);
PORTA=0xef;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xfe;
Delay_ms(100);
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
}
/************流水灯 7快*********/
void liushui7kuai()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
Delay_ms(5);
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xfe;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xef;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xef;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xdf;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xfe;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xfd;
PORTD=0x7e;
Delay_ms(100);
PORTA=0xfb;
PORTD=0x7d;
Delay_ms(100);
PORTA=0xf7;
PORTD=0x7b;
Delay_ms(100);
PORTA=0xef;
PORTD=0x77;
Delay_ms(100);
PORTA=0xdf;
PORTD=0x6f;
Delay_ms(100);
PORTA=0xbf;
PORTD=0x5f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7e;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7d;
PORTD=0x3e;
Delay_ms(100);
PORTA=0x7b;
PORTD=0x3d;
Delay_ms(100);
PORTA=0x77;
PORTD=0x3b;
Delay_ms(100);
PORTA=0x6f;
PORTD=0x37;
Delay_ms(100);
PORTA=0x5f;
PORTD=0x2f;
Delay_ms(100);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x3e;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x3d;
PORTD=0x1e;
Delay_ms(100);
PORTA=0x3b;
PORTD=0x1d;
Delay_ms(100);
PORTA=0x37;
PORTD=0x1b;
Delay_ms(100);
PORTA=0x2f;
PORTD=0x17;
Delay_ms(100);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(100);
PORTA=0x1e;
PORTD=0x0f;
Delay_ms(100);
PORTA=0x1d;
PORTD=0x0e;
Delay_ms(100);
PORTA=0x1b;
PORTD=0x0d;
Delay_ms(100);
PORTA=0x17;
PORTD=0x0b;
Delay_ms(100);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(100);
PORTA=0x0e;
PORTD=0x07;
Delay_ms(100);
PORTA=0x0d;
PORTD=0x06;
Delay_ms(100);
PORTA=0x0b;
PORTD=0x05;
Delay_ms(100);
PORTA=0x07;
PORTD=0x03;
Delay_ms(100);
PORTA=0x06;
PORTD=0x03;
Delay_ms(100);
PORTA=0x05;
PORTD=0x02;
Delay_ms(100);
PORTA=0x03;
PORTD=0x01;
Delay_ms(100);
PORTA=0x02;
PORTD=0x01;
Delay_ms(100);
PORTA=0x01;
PORTD=0x00;
Delay_ms(100);
///////////////////////////////////////
PORTA=0x01;
PORTD=0x00;
Delay_ms(100);
PORTA=0x02;
PORTD=0x01;
Delay_ms(100);
PORTA=0x03;
PORTD=0x01;
Delay_ms(100);
PORTA=0x05;
PORTD=0x02;
Delay_ms(100);
PORTA=0x06;
PORTD=0x03;
Delay_ms(100);
PORTA=0x07;
PORTD=0x03;
Delay_ms(100);
PORTA=0x0b;
PORTD=0x05;
Delay_ms(100);
PORTA=0x0d;
PORTD=0x06;
Delay_ms(100);
PORTA=0x0e;
PORTD=0x07;
Delay_ms(100);
PORTA=0x0f;
PORTD=0x07;
Delay_ms(100);
PORTA=0x17;
PORTD=0x0b;
Delay_ms(100);
PORTA=0x1b;
PORTD=0x0d;
Delay_ms(100);
PORTA=0x1d;
PORTD=0x0e;
Delay_ms(100);
PORTA=0x1e;
PORTD=0x0f;
Delay_ms(100);
PORTA=0x1f;
PORTD=0x0f;
Delay_ms(100);
PORTA=0x2f;
PORTD=0x17;
Delay_ms(100);
PORTA=0x37;
PORTD=0x1b;
Delay_ms(100);
PORTA=0x3b;
PORTD=0x1d;
Delay_ms(100);
PORTA=0x3d;
PORTD=0x1e;
Delay_ms(100);
PORTA=0x3e;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x3f;
PORTD=0x1f;
Delay_ms(100);
PORTA=0x5f;
PORTD=0x2f;
Delay_ms(100);
PORTA=0x6f;
PORTD=0x37;
Delay_ms(100);
PORTA=0x77;
PORTD=0x3b;
Delay_ms(100);
PORTA=0x7b;
PORTD=0x3d;
Delay_ms(100);
PORTA=0x7d;
PORTD=0x3e;
Delay_ms(100);
PORTA=0x7e;
PORTD=0x3f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0x3f;
Delay_ms(100);
PORTA=0xbf;
PORTD=0x5f;
Delay_ms(100);
PORTA=0xdf;
PORTD=0x6f;
Delay_ms(100);
PORTA=0xef;
PORTD=0x77;
Delay_ms(100);
PORTA=0xf7;
PORTD=0x7b;
Delay_ms(100);
PORTA=0xfb;
PORTD=0x7d;
Delay_ms(100);
PORTA=0xfd;
PORTD=0x7e;
Delay_ms(100);
PORTA=0xfe;
PORTD=0x7f;
Delay_ms(100);
PORTA=0xff;
PORTD=0x7f;
Delay_ms(100);
PORTA=0x7f;
PORTD=0xbf;
Delay_ms(100);
PORTA=0xbf;
PORTD=0xdf;
Delay_ms(100);
PORTA=0xdf;
PORTD=0xef;
Delay_ms(100);
PORTA=0xef;
PORTD=0xf7;
Delay_ms(100);
PORTA=0xf7;
PORTD=0xfb;
Delay_ms(100);
PORTA=0xfb;
PORTD=0xfd;
Delay_ms(100);
PORTA=0xfd;
PORTD=0xfe;
Delay_ms(100);
PORTA=0xfe;
PORTD=0xff;
Delay_ms(100);
}
/**********流水灯 7 +呼吸***********/
void liushui7huxi()
{
OCR0=count;
count=100;
PORTA=0xff;
PORTD=0xff;
Delay_ms(5);
PORTA=0xfe;
PORTD=0xff;
huxi();
PORTA=0xfd;
PORTD=0xfe;
huxi();
PORTA=0xfb;
PORTD=0xfd;
huxi();
PORTA=0xf7;
PORTD=0xfb;
huxi();
PORTA=0xef;
PORTD=0xf7;
huxi();
PORTA=0xdf;
PORTD=0xef;
huxi();
PORTA=0xbf;
PORTD=0xdf;
huxi();
PORTA=0x7f;
PORTD=0xbf;
huxi();
PORTA=0xff;
PORTD=0x7f;
huxi();
PORTA=0xfe;
PORTD=0x7f;
huxi();
PORTA=0xfd;
PORTD=0x7e;
huxi();
PORTA=0xfb;
PORTD=0x7d;
huxi();
PORTA=0xf7;
PORTD=0x7b;
huxi();
PORTA=0xef;
PORTD=0x77;
huxi();
PORTA=0xdf;
PORTD=0x6f;
huxi();
PORTA=0xbf;
PORTD=0x5f;
huxi();
PORTA=0x7f;
PORTD=0x3f;
huxi();
PORTA=0x7e;
PORTD=0x3f;
huxi();
PORTA=0x7d;
PORTD=0x3e;
huxi();
PORTA=0x7b;
PORTD=0x3d;
huxi();
PORTA=0x77;
PORTD=0x3b;
huxi();
PORTA=0x6f;
PORTD=0x37;
huxi();
PORTA=0x5f;
PORTD=0x2f;
huxi();
PORTA=0x3f;
PORTD=0x1f;
huxi();
PORTA=0x3e;
PORTD=0x1f;
huxi();
PORTA=0x3d;
PORTD=0x1e;
huxi();
PORTA=0x3b;
PORTD=0x1d;
huxi();
PORTA=0x37;
PORTD=0x1b;
huxi();
PORTA=0x2f;
PORTD=0x17;
huxi();
PORTA=0x1f;
PORTD=0x0f;
huxi();
PORTA=0x1e;
PORTD=0x0f;
huxi();
PORTA=0x1d;
PORTD=0x0e;
huxi();
PORTA=0x1b;
PORTD=0x0d;
huxi();
PORTA=0x17;
PORTD=0x0b;
huxi();
PORTA=0x0f;
PORTD=0x07;
huxi();
PORTA=0x0e;
PORTD=0x07;
huxi();
PORTA=0x0d;
PORTD=0x06;
huxi();
PORTA=0x0b;
PORTD=0x05;
huxi();
PORTA=0x07;
PORTD=0x03;
huxi();
PORTA=0x06;
PORTD=0x03;
huxi();
PORTA=0x05;
PORTD=0x02;
huxi();
PORTA=0x03;
PORTD=0x01;
huxi();
PORTA=0x02;
PORTD=0x01;
huxi();
PORTA=0x01;
PORTD=0x00;
huxi();
///////////////////////////////////////
PORTA=0x01;
PORTD=0x00;
huxi();
PORTA=0x02;
PORTD=0x01;
huxi();
PORTA=0x03;
PORTD=0x01;
huxi();
PORTA=0x05;
PORTD=0x02;
huxi();
PORTA=0x06;
PORTD=0x03;
huxi();
PORTA=0x07;
PORTD=0x03;
huxi();
PORTA=0x0b;
PORTD=0x05;
huxi();
PORTA=0x0d;
PORTD=0x06;
huxi();
PORTA=0x0e;
PORTD=0x07;
huxi();
PORTA=0x0f;
PORTD=0x07;
huxi();
PORTA=0x17;
PORTD=0x0b;
huxi();
PORTA=0x1b;
PORTD=0x0d;
huxi();
PORTA=0x1d;
PORTD=0x0e;
huxi();
PORTA=0x1e;
PORTD=0x0f;
huxi();
PORTA=0x1f;
PORTD=0x0f;
huxi();
PORTA=0x2f;
PORTD=0x17;
huxi();
PORTA=0x37;
PORTD=0x1b;
huxi();
PORTA=0x3b;
PORTD=0x1d;
huxi();
PORTA=0x3d;
PORTD=0x1e;
huxi();
PORTA=0x3e;
PORTD=0x1f;
huxi();
PORTA=0x3f;
PORTD=0x1f;
huxi();
PORTA=0x5f;
PORTD=0x2f;
huxi();
PORTA=0x6f;
PORTD=0x37;
huxi();
PORTA=0x77;
PORTD=0x3b;
huxi();
PORTA=0x7b;
PORTD=0x3d;
huxi();
PORTA=0x7d;
PORTD=0x3e;
huxi();
PORTA=0x7e;
PORTD=0x3f;
huxi();
PORTA=0x7f;
PORTD=0x3f;
huxi();
PORTA=0xbf;
PORTD=0x5f;
huxi();
PORTA=0xdf;
PORTD=0x6f;
huxi();
PORTA=0xef;
PORTD=0x77;
huxi();
PORTA=0xf7;
PORTD=0x7b;
huxi();
PORTA=0xfb;
PORTD=0x7d;
huxi();
PORTA=0xfd;
PORTD=0x7e;
huxi();
PORTA=0xfe;
PORTD=0x7f;
huxi();
PORTA=0xff;
PORTD=0x7f;
huxi();
PORTA=0x7f;
PORTD=0xbf;
huxi();
PORTA=0xbf;
PORTD=0xdf;
huxi();
PORTA=0xdf;
PORTD=0xef;
huxi();
PORTA=0xef;
PORTD=0xf7;
huxi();
PORTA=0xf7;
PORTD=0xfb;
huxi();
PORTA=0xfb;
PORTD=0xfd;
huxi();
PORTA=0xfd;
PORTD=0xfe;
huxi();
PORTA=0xfe;
PORTD=0xff;
huxi();
}
/***************流水灯 8*************/
void liushui8()
{
OCR0=count;
count=100;
temp9=0xff;
temp10=0xff;
for(g=0;g<8;g++)
{
PORTA=~temp9;
PORTD=~temp10;
for(count=100;count<256;count++) //OCR=0时,LED最亮,然后逐渐变暗
{
OCR0=count; //比较匹配寄存器赋值
Delay_ms(2); //延时一段时间,以观察效果
}
for(count=255;count>99;count--) //OCR=255时,LED最暗,然后逐渐变亮
{
OCR0= count;
Delay_ms(2);
}
temp9=temp9>>1;
temp10=temp10<<1;
}
}
void liushui8fan()
{
OCR0=count;
count=100;
temp11=0xff;
temp12=0xff;
for(h=0;h<8;h++)
{
PORTA=temp11;
PORTD=temp12;
huxi();
temp11=temp11<<1;
temp12=temp12>>1;
}
}
/*********以下是主函数*********/
void main(void)
{
port_init();
timer0_init();
while(1)
{
huxizhong();
huxikuai();
huxichaokuai();
liushui1();
liushui1fan();
liushui5(); //一个灯跑
liushui5fan();
liushui2fan();
liushui2(); //两个灯跑
liushui4(); //一个灯流水
liushui4fan();
liushui3();
liushui3();
liushui3kuai1();
liushui3kuai1();
liushui3kuai1();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui4(); //一个灯流水
liushui4fan();
liushui7();
liushui7huxi();
liushui5(); //一个灯跑
liushui5fan();
liushui2fan();
liushui2(); //两个灯跑
liushui4(); //一个灯流水
liushui4fan();
liushui6();
liushui6fan();
liushui2fan();
liushui2(); //两个灯跑
liushui4(); //一个灯流水
liushui4fan();
liushui3();
liushui3();
liushui7kuai();
liushui2fan();
liushui2(); //两个灯跑
liushui4(); //一个灯流水
liushui4fan();
liushui6();
liushui6fan();
liushui8();
liushui8fan();
liushui1();
liushui1fan();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui3kuai2();
liushui7kuai();
liushui1huxifan();
liushui1huxi();
}
}
上一篇: SpringBoot整合mongoDB
下一篇: springboot整合MongoDB