基于单片机心形流水灯C语言源程序精编
基于单片机的心形流水灯毕业设计论文
基于单片机的心形流水灯毕业设计论文此文档为WORD版可编辑修改课程设计(论文)说明书题目:心形流水灯院(系):信息与通信学院专业:通信工程学生姓名:学号:指导教师:职称:X年X月X日摘要本论文基于单片机技术与单片机芯片AT89S51芯片功能和C语言程序,实现心形流水灯的多种亮与灭的循环。
首先,我们了解单片机的一些技术,了解了单片机芯片AT89S51的一些功能;然后结合C语言编程;最后将它们运用到实际的电路,使心形LED灯实现多种亮灭方法。
本论文介绍关于流水灯的运用和单片机技术;然后介绍芯片AT89S51;最后介绍运用到的相关软件.关键词:单片机;流水灯;C语言;AbstractThis paper Based on the single chip microcomputer and single chip microcomputer chipAT89S51 chip function and C language program,Realization of flowing water light heart a variety of light and the cycle of destruction。
primarily,We know some of the single chip microcomputer technology,Understanding of the single chip microcomputer chip AT89S51 of some functions, Then based on the C language programming; Finally they are applied to the practical circuit, Make heart LED lamp achieve a variety of light out method. This paper introduces about the use of flowing water light and single chip microcomputer; and then introduced chip AT89S51; At the end of this paper applied to software.Key words:micro-computer;light water ;C programming language目录引言 (1)1 设计方案 (2)1.1 总体设计目标 (2)1.2 总体设计组成框图 (2)2 相关运用与功能................................................................ 错误!未定义书签。
单片机流水灯程序
单片机流水灯程序流水灯是一种简单而常见的电子技术实验项目,也是学习掌握单片机编程的基本操作之一。
本文将介绍如何使用C语言编写单片机流水灯程序,并通过Markdown文本格式输出。
硬件准备在开始编写流水灯程序之前,我们需要准备以下硬件设备:1.单片机开发板(如:Arduino、STM32等)2.LED灯(可根据自己的需求选择,一般使用红色、黄色、绿色等常见颜色的LED灯即可)3.杜邦线(用于连接单片机和LED灯)程序编写引入头文件首先,我们需要引入相应的头文件,以便使用单片机相关的功能库和定义常量。
#include <Arduino.h>定义引脚接下来,我们需要定义引脚,将LED灯的接口与开发板的引脚连接起来。
#define LED_PIN_1 2#define LED_PIN_2 3#define LED_PIN_3 4#define DELAY_TIME 500在这个例子中,我们使用了3个LED灯,分别连接到开发板的2、3、4号引脚。
DELAY_TIME用于控制每个灯亮起的时间间隔,单位是毫秒。
初始化引脚在进入主程序之前,我们需要对引脚进行初始化,设置引脚的输出模式。
void setup() {pinMode(LED_PIN_1, OUTPUT);pinMode(LED_PIN_2, OUTPUT);pinMode(LED_PIN_3, OUTPUT);}主程序接下来就是我们的主程序部分,我们可以使用循环语句来实现LED灯的流水效果。
void loop() {digitalWrite(LED_PIN_1, HIGH);delay(DELAY_TIME);digitalWrite(LED_PIN_1, LOW);digitalWrite(LED_PIN_2, HIGH);delay(DELAY_TIME);digitalWrite(LED_PIN_2, LOW);digitalWrite(LED_PIN_3, HIGH);delay(DELAY_TIME);digitalWrite(LED_PIN_3, LOW);}在这个例子中,我们依次点亮每个LED灯,并延迟一定的时间后熄灭,然后依次点亮下一个LED灯,以此循环。
爱心流水灯程序
#define uint unsigned int #define uchar unsigned charsbit p0_1=P0^0;sbit p0_2=P0^1;sbit p0_3=P0^2;sbit p0_4=P0^3;sbit p0_5=P0^4;sbit p0_6=P0^5;sbit p0_7=P0^6;sbit p0_8=P0^7;sbit p1_1=P1^0;sbit p1_2=P1^1;sbit p1_3=P1^2;sbit p1_4=P1^3;sbit p1_5=P1^4;sbit p1_6=P1^5;sbit p1_7=P1^6;sbit p1_8=P1^7;sbit p2_1=P2^0;sbit p2_2=P2^1;sbit p2_3=P2^2;sbit p2_4=P2^3;sbit p2_5=P2^4;sbit p2_6=P2^5;sbit p2_7=P2^6;sbit p2_8=P2^7;sbit p3_1=P3^0;sbit p3_2=P3^1;sbit p3_3=P3^2;sbit p3_4=P3^3;sbit p3_5=P3^4;sbit p3_6=P3^5;sbit p3_7=P3^6;sbit p3_8=P3^7;void delay(uint);uchar temp0;uchar temp1;uchar temp3;uint k,s;void delay(uint j){uint i;for(j;j>0;j--)for(i=120;i>0;i--);}void main(){while(1){for(k=0;k<4;k++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(500);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(500); }for(k=0;k<7;k++) {temp0=0x01;P0=temp0;delay(100);for(k=0;k<8;k++){s=temp0<<1;P0=s;delay(50);}P0=0xff;temp2=0x01;P2=temp0;delay(100);for(k=0;k<8;k++) {s=temp2<<1;P2=s;delay(50);}P2=0xff;temp3=0x01;P3=temp0;delay(100);for(k=0;k<8;k++) {s=temp3<<1;P3=s;delay(50);}P3=0xff;temp1=0x01;P1=temp0;delay(100);for(k=0;k<8;k++) {s=temp1<<1;P1=s;delay(50);}delay(500);temp1=0x01;P1=temp1;delay(100);for(k=0;k<7;k++) {s=temp1>>1;P1=s;delay(50);}P1=0xff;temp3=0x01;P3=temp3;delay(50);for(k=0;k<8;k++){s=temp3<<1;P3=s;delay(50);}P3=0xff;temp2=0x01;P2=temp2;delay(50);for(k=0;k<8;k++){s=temp2<<1;P2=s;delay(50);}P2=0xff;temp0=0x01;P0=temp0;delay(50);for(k=0;k<8;k++){s=temp0>>1;P0=s;delay(50);}P0=0xff;}delay(1000);for(k=0;k<2;k++){p1_1=0;delay(50);p1_2=0;delay(50);p1_3=0;delay(50);p1_4=0;delay(50);p1_5=0; delay(50); p1_6=0; delay(50); p1_7=0; delay(50); p1_8=0; delay(50);p3_1=0; delay(50); p3_2=0; delay(50); p3_3=0; delay(50); p3_4=0; delay(50); p3_5=0; delay(50); p3_6=0; delay(50); p3_7=0; delay(50); p3_8=0; delay(50);p2_1=0; delay(50); p2_2=0; delay(50); p2_3=0; delay(50); p2_4=0; delay(50); p2_5=0; delay(50); p2_6=0; delay(50); p2_7=0; delay(50); p2_8=0; delay(50);p0_8=0;delay(50);p0_7=0;delay(50);p0_6=0;delay(50);p0_5=0;delay(50);p0_4=0;delay(50);p0_3=0;delay(50);p0_2=0;delay(50);p0_1=0;delay(50);/*......*/p1_1=1;delay(50);p1_2=1;delay(50);p1_3=1;delay(50);p1_4=1;delay(50);p1_5=1;delay(50);p1_6=1;delay(50);p1_7=1;delay(50);p1_8=1;delay(50);p3_1=1;delay(50);p3_2=1;delay(50);p3_3=1; delay(50); p3_4=1; delay(50); p3_5=1; delay(50); p3_6=1; delay(50); p3_7=1; delay(50); p3_8=1;delay(50);p2_1=1; delay(50); p2_2=1; delay(50); p2_3=1; delay(50); p2_4=1; delay(50); p2_5=1; delay(50); p2_6=1; delay(50); p2_7=1; delay(50); p2_8=1;delay(50);p0_8=1; delay(50); p0_7=1; delay(50); p0_6=1; delay(50); p0_5=1; delay(50); p0_4=1; delay(50); p0_3=1;delay(50); p0_2=1; delay(50); p0_1=1; delay(50);/*......*/p0_1=0; delay(50); p0_2=0; delay(50); p0_3=0; delay(50); p0_4=0; delay(50); p0_5=0; delay(50); p0_6=0; delay(50); p0_7=0; delay(50); p0_8=0; delay(50);p2_8=0; delay(50); p2_7=0; delay(50); p2_6=0; delay(50); p2_5=0; delay(50); p2_4=0; delay(50); p2_3=0; delay(50); p2_2=0; delay(50); p2_1=0; delay(50);delay(50); p3_7=0; delay(50); p3_6=0; delay(50); p3_5=0; delay(50); p3_4=0; delay(50); p3_3=0; delay(50); p3_2=0; delay(50); p3_1=0; delay(50);p1_8=0; delay(50); p1_7=0; delay(50); p1_6=0; delay(50); p1_5=0; delay(50); p1_4=0; delay(50); p1_3=0; delay(50); p1_2=0; delay(50); p1_1=0; delay(50);/*......*/p0_1=1; delay(50); p0_2=1; delay(50); p0_3=1; delay(50);delay(50); p0_5=1; delay(50); p0_6=1; delay(50); p0_7=1; delay(50); p0_8=1; delay(50);p2_8=1; delay(50); p2_7=1; delay(50); p2_6=1; delay(50); p2_5=1; delay(50); p2_4=1; delay(50); p2_3=1; delay(50); p2_2=1; delay(50); p2_1=1;delay(50);p3_8=1; delay(50); p3_7=1; delay(50); p3_6=1; delay(50); p3_5=1; delay(50); p3_4=1; delay(50); p3_3=1; delay(50); p3_2=1; delay(50);delay(50);p1_8=1;delay(50);p1_7=1;delay(50);p1_6=1;delay(50);p1_5=1;delay(50);p1_4=1;delay(50);p1_3=1;delay(50);p1_2=1;delay(1);p1_1=1;delay(50);/*..........*/for(k=0;k<3;k++){p1_1=0;delay(50);p1_2=0;p0_1=0;delay(50);p1_3=0;p0_2=0;delay(50);p1_4=0;p0_3=0;delay(40);p1_5=0;p0_4=0;delay(50);p1_6=0;p0_5=0;delay(50);p1_7=0;p0_6=0;delay(50);p0_7=0;delay(50);p3_1=0;p0_8=0;delay(50);p3_2=0;p2_8=0;delay(50);p3_3=0;p2_7=0;delay(50);p3_4=0;p2_6=0;delay(50);p3_5=0;p2_5=0;delay(50);p3_6=0;p2_4=0;delay(50);p3_7=0;p2_3=0;delay(50);p3_8=0;p2_2=0;delay(50);p2_1=0;delay(50);/*......*/p2_1=1;delay(50); p3_8=1;p2_2=1;delay(35);p3_7=1;p2_3=1;delay(50); p3_6=1;p2_4=1;delay(50); p3_5=1;p2_5=1;delay(50); p3_4=1;p2_6=1;delay(35); p3_3=1;p2_7=1;delay(50); p3_2=1;p2_8=1;delay(50); p3_1=1;p0_8=1;delay(35); p1_8=1;p0_7=1;delay(50); p1_7=1;p0_6=1;delay(50); p1_6=1;p0_5=1;delay(50); p1_5=1;p0_4=1;delay(50); p1_4=1;p0_3=1;delay(50); p1_3=1;p0_2=1;delay(50); p1_2=1;p0_1=1;delay(50); p1_1=1;delay(50);}}/***********/delay(400);P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(400);for(k=0;k<4;k++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(200);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(200); }for(k=0;k<72;k++) {P0=0x55;P1=0x55;P2=0x55;P3=0x55;delay(100);P0=0xaa;P1=0xaa;P2=0xaa;P3=0xaa;delay(100); }P1=0xff;P2=0xff;P3=0xff;delay(500);/*.......*/for(k=0;k<4;k++){P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(200);P0=0xf0;delay(20);P0=0x00;delay(20);P2=0xf0;delay(20);P2=0x00;delay(300);P0=0xff;P2=0xff; delay(300);P3=0x00f;delay(20);P3=0x00;delay(20);P1=0x00f;delay(20);P1=0x00;delay(300);}for(k=0;k<7;k++){temp1=0x01;delay(100);for(k=0;k<7;k++) {s=temp1>>1;P1=s;delay(50);}P1=0xff;temp3=0x01;P3=temp3;delay(100);for(k=0;k<8;k++) {s=temp3<<1;P3=s;delay(50);}P3=0xff;temp2=0x01;P2=temp2;delay(100);for(k=0;k<8;k++) {s=temp2<<1;P2=s;delay(50);}P2=0xff;temp0=0x01;P0=temp0;delay(100);for(k=0;k<8;k++) {s=temp0>>1;P0=s;delay(50);}P0=0xff;delay(500);temp0=0x01;P0=temp0;for(k=0;k<8;k++) {s=temp0<<1;P0=s;delay(50);}P0=0xff;temp2=0x01;P2=temp0;delay(100);for(k=0;k<8;k++) {s=temp2<<1;P2=s;delay(50);}P2=0xff;temp3=0x01;P3=temp0;delay(100);for(k=0;k<8;k++) {s=temp3<<1;P3=s;delay(50);}P3=0xff;temp1=0x01;P1=temp0;delay(100);for(k=0;k<8;k++) {s=temp1<<1;P1=s;delay(50);}}for(k=0;k<3;k++) {P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(100);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(100);}delay(400);temp0=0x0f; temp2=0xf0; temp3=0x0f; temp1=0x0f;for(k;k<240;k++){P0=temp0;P2=temp2;P3=temp3;P1=temp1;temp0=_crol_(temp0,1);delay(10);temp2=_cror_(temp2,1);delay(10);temp3=_cror_(temp3,1);delay(10);temp1=_cror_(temp1,1);delay(10);}delay(500);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(1000);temp0=0x7f; temp2=0xfe; temp3=0xfe; temp1=0xfe;for(k;k<240;k++){P0=temp0;P2=temp2;P3=temp3;P1=temp1;temp0=_cror_(temp0,1);delay(70);temp2=_crol_(temp2,1);delay(700);temp3=_crol_(temp3,1);delay(70);temp1=_crol_(temp1,1);delay(70);}delay(400);P1=0xf0;delay(500);P1=0xff;P1=0x00;delay(500);P1=0xff;P3=0xf0;delay(500);P3=0xff;P3=0x0f;delay(500);P3=0xff;P2=0xf0;delay(500);P2=0xff;P2=0x0f;delay(500);P2=0xff;P0=0x0f;delay(500);P0=0xff;P0=0xf0;delay(500);P0=0xff;delay(500);for(k=0;k<49;k++){P1=0xf0;delay(20);P1=0xff;P1=0x00;delay(20);P1=0xff;P3=0xf0;delay(20);P3=0xff;P3=0x0f;delay(20);P3=0xff;P2=0xf0;delay(20);P2=0xff;P2=0x0f;delay(20);P2=0xff;P0=0x0f;delay(20);P0=0xff;P0=0xf0;delay(20);P0=0xff;}delay(1000);for(k=0;k<2;k++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(200);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(400); }delay(5000);}}。
51芯片超炫爱心流水程序灯代码
#include<reg52.h>sbit P00=P0^0;sbit P01=P0^1;sbit P02=P0^2;sbit P03=P0^3;sbit P04=P0^4;sbit P05=P0^5;sbit P06=P0^6;sbit P07=P0^7;sbit P10=P1^0;sbit P11=P1^1;sbit P12=P1^2;sbit P13=P1^3;sbit P14=P1^4;sbit P15=P1^5;sbit P16=P1^6;sbit P17=P1^7;sbit P20=P2^0;sbit P21=P2^1;sbit P22=P2^2;sbit P23=P2^3;sbit P24=P2^4;sbit P25=P2^5;sbit P26=P2^6;sbit P27=P2^7;sbit P30=P3^0;sbit P31=P3^1;sbit P32=P3^2;sbit P33=P3^3;sbit P34=P3^4;sbit P35=P3^5;sbit P36=P3^6;sbit P37=P3^7;unsigned int x,y;void rzmzy(); //红色走马左移声明void rzmyy(); //红色走马右移声明void rzmnwyd(); //红色走马内外移动声明void rtbyd(); //红色跳变移动声明void rjl(); //红色渐亮声明void rja(); //红色渐暗声明void rP0ja();//P0渐暗void zkb(unsigned char d);void delayms(int z)//延时声明,修改s的数值,就可以改变时间{int i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}void Onall() //开启所有灯{P0=0x00;P1=0x00;P2=0x00;P3=0x00;}void Offall()//关闭所有灯{P0=0xff;P1=0xff;P2=0xff;P3=0xff;}//void fxls()//逆时针逐个等时流水灯//{// P0=0xfe;delayms(50);// P0=0xfd;delayms(50);// P0=0xfb;delayms(50);// P0=0xf7;delayms(50);// P0=0xef;delayms(50);// P0=0xdf;delayms(50);// P0=0xbf;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;//// P2=0x7f;delayms(50);// P2=0xbf;delayms(50);// P2=0xdf;delayms(50);// P2=0xef;delayms(50);// P2=0xf7;delayms(50);// P2=0xfb;delayms(50);// P2=0xfd;delayms(50);// P2=0xfe;delayms(50);// P2=0xff;//// P3=0x7f;delayms(50);// P3=0xbf;delayms(50);// P3=0xdf;delayms(50);// P3=0xef;delayms(50);// P3=0xf7;delayms(50);// P3=0xfb;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;//// P1=0x7f;delayms(50);// P1=0xbf;delayms(50);// P1=0xdf;delayms(50);// P1=0xef;delayms(50);// P1=0xf7;delayms(50);// P1=0xfb;delayms(50);// P1=0xfd;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;//}//void ls()//顺时针逐个等时流水灯//{// Offall();// P1=0xfe;delayms(50);// P1=0xfd;delayms(50);// P1=0xfb;delayms(50);// P1=0xf7;delayms(50);// P1=0xef;delayms(50);// P1=0xdf;delayms(50);// P1=0xbf;delayms(50);// P1=0x7f;delayms(50);// P1=0xff;//// P3=0xfe;delayms(50);// P3=0xfd;delayms(50);// P3=0xfb;delayms(50);// P3=0xf7;delayms(50);// P3=0xef;delayms(50);// P3=0xdf;delayms(50);// P3=0xbf;delayms(50);// P3=0x7f;delayms(50);// P3=0xff;;//// P2=0xfe;delayms(50);// P2=0xfd;delayms(50);// P2=0xfb;delayms(50);// P2=0xf7;delayms(50);// P2=0xef;delayms(50);// P2=0xdf;delayms(50);// P2=0xbf;delayms(50);// P2=0xff;;//// P0=0x7f;delayms(50);// P0=0xbf;delayms(50);// P0=0xdf;delayms(50);// P0=0xef;delayms(50);// P0=0xf7;delayms(50);// P0=0xfb;delayms(50);// P0=0xfd;delayms(50);// P0=0xfe;delayms(50);// P0=0xff;//}void bsb()//双边同时流水由上至下{Offall();delayms(50);P0=0xfe;delayms(50);P0=0xfd;P1=0xfe;delayms(50);P0=0xfb;P1=0xfd;delayms(50);P0=0xf7;P1=0xfb;delayms(50);P0=0xef;P1=0xf7;delayms(50);P0=0xdf;P1=0xef;delayms(50);P0=0xbf;P1=0xdf;delayms(50);P0=0x7f;P1=0xbf;delayms(50);P0=0xff;P2=0x7f;P1=0x7f;delayms(50);P1=0xff;P2=0xbf;P3=0xfe;delayms(50);P2=0xdf;P3=0xfd;delayms(50);P2=0xef;P3=0xfb;delayms(50);P2=0xf7;P3=0xf7;delayms(50);P2=0xfb;P3=0xef;delayms(50);P2=0xfd;P3=0xdf;delayms(50);P2=0xfe;P3=0xbf;delayms(50);P2=0xff;P3=0x7f;delayms(50);P3=0xff;}//void fbsb() //半双边流水由下至上//{// Offall();// P3=0x7f;delayms(80);// P2=0xfe;P3=0xbf;delayms(80);// P2=0xfd;P3=0xdf;delayms(80);// P2=0xfb;P3=0xef;delayms(80);// P2=0xf7;P3=0xf7;delayms(80);// P2=0xef;P3=0xfb;delayms(80);// P2=0xdf;P3=0xfd;delayms(80);// P2=0xbf;P3=0xfe;delayms(80);Offall(); // P2=0x7f;P1=0x7f;delayms(80);Offall(); //// P0=0x7f;P1=0xbf;delayms(80);// P0=0xbf;P1=0xdf;delayms(80);// P0=0xdf;P1=0xef;delayms(80);// P0=0xef;P1=0xf7;delayms(80);// P0=0xf7;P1=0xfb;delayms(80);// P0=0xfb;P1=0xfd;delayms(80);// P0=0xfd;P1=0xfe;delayms(80);// P0=0xfe;P1=0xff;delayms(80);//}void ss(y)//闪烁(y为闪烁间隔时间){Onall();delayms(y);Offall();delayms(y);}//void fxsz() //反向生长//{// Offall();// P0=0xfe;delayms(50);// P0=0xfc;delayms(50);// P0=0xf8;delayms(50);// P0=0xf0;delayms(50);// P0=0xe0;delayms(50);// P0=0xc0;delayms(50);// P0=0x80;delayms(50);// P0=0x00;delayms(50);//// P2=0x7f;delayms(50);// P2=0x3f;delayms(50);// P2=0x1f;delayms(50);// P2=0x0f;delayms(50);// P2=0x07;delayms(50);// P2=0x03;delayms(50);// P2=0x01;delayms(50);// P2=0x00;delayms(50);//// P3=0x7f;delayms(50);// P3=0x3f;delayms(50);// P3=0x1f;delayms(50);// P3=0x0f;delayms(50);// P3=0x07;delayms(50); // P3=0x03;delayms(50); // P3=0x01;delayms(50); // P3=0x00;delayms(50); //// P1=0x7f;delayms(50);// P1=0x3f;delayms(50);// P1=0x1f;delayms(50);// P1=0x0f;delayms(50);// P1=0x07;delayms(50); // P1=0x03;delayms(50); // P1=0x01;delayms(50); // P1=0x00;delayms(50); //// Offall();delayms(100);// Onall();delayms(100);// Offall();delayms(100);// Onall();delayms(500);// Offall();delayms(50);//}void zxsz() //正向生长{Offall();P0=0xfe;delayms(50);P1=0xfe;delayms(50);P1=0xfc;delayms(50);P1=0xf8;delayms(50);P1=0xf0;delayms(50);P1=0xe0;delayms(50);P1=0xc0;delayms(50);P1=0x80;delayms(50);P1=0x00;delayms(50);P3=0xfe;delayms(50);P3=0xfc;delayms(50);P3=0xf8;delayms(50);P3=0xf0;delayms(50);P3=0xe0;delayms(50);P3=0xc0;delayms(50);P3=0x80;delayms(50);P3=0x00;delayms(50);P2=0xfe;delayms(50);P2=0xfc;delayms(50);P2=0xf8;delayms(50);P2=0xf0;delayms(50);P2=0xe0;delayms(50);P2=0xc0;delayms(50);P2=0x80;delayms(50);P2=0x00;delayms(50);P0=0x7e;delayms(50);P0=0x3e;delayms(50);P0=0x1e;delayms(50);P0=0x0e;delayms(50);P0=0x06;delayms(50);P0=0x02;delayms(50);P0=0x00;delayms(50);Offall();delayms(100);Onall();delayms(100);Offall();delayms(100);Onall();delayms(500);Offall();delayms(100);}//void fxsw() //反向死亡//{// Onall();// P0=0x01;delayms(50); // P0=0x03;delayms(50); // P0=0x07;delayms(50); // P0=0x0f;delayms(50);// P0=0x1f;delayms(50);// P0=0x3f;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;delayms(50);//// P2=0x80;delayms(50); // P2=0xc0;delayms(50); // P2=0xe0;delayms(50); // P2=0xf0;delayms(50);// P2=0xf8;delayms(50);// P2=0xfc;delayms(50);// P2=0xff;delayms(50);//// P3=0x80;delayms(50);// P3=0xc0;delayms(50);// P3=0xe0;delayms(50);// P3=0xf0;delayms(50);// P3=0xf8;delayms(50);// P3=0xfc;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;delayms(50);//// P1=0x80;delayms(50);// P1=0xc0;delayms(50);// P1=0xe0;delayms(50);// P1=0xf0;delayms(50);// P1=0xf8;delayms(50);// P1=0xfc;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;delayms(50);//}void c(x) //间隔闪烁x为闪烁间隔时间{Offall();P0=0xaa;P2=0x55;P3=0x55;P1=0x55;delayms(x);P0=0x55;P2=0xaa;P3=0xaa;P1=0xaa;delayms(x);}/*----------------------------------------------------------*/void cx() //出现一点点{Offall();delayms(500);P0=0xff;P2=0xff;P1=0xbf;P3=0xff;delayms(500);P0=0xdf;P2=0xbf;P1=0xbf;P3=0xff;delayms(500);P0=0xdb;P2=0xbd;P1=0xbf;P3=0xfb;delayms(500);P0=0x59;P2=0xa5;P1=0x5d;P3=0x9a;delayms(500);P0=0x11;P2=0x20;P1=0x24;P3=0x10;delayms(500);P0=0x00;P2=0x00;P1=0x00;P3=0x00;delayms(500); }//void df() //单飞//{// P0=0xfe;delayms(50);// P0=0xfc;delayms(50);// P0=0xf0;delayms(50);// P0=0xe0;delayms(50);// P0=0xc0;delayms(50);// P0=0x80;delayms(50);// P0=0x00;delayms(50);//先引出单飞//// P0=0x01;delayms(50);// P0=0x03;delayms(50);// P0=0x07;delayms(50);// P0=0x0f;delayms(50);// P0=0x1f;delayms(50);// P0=0x3f;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;delayms(50);//// P2=0x7f;delayms(50);// P2=0x3f;delayms(50);// P2=0x1f;delayms(50);// P2=0x0f;delayms(50);// P2=0xf7;delayms(50);// P2=0xf3;delayms(50);// P2=0xf1;delayms(50);// P2=0xf0;delayms(50);//// P3=0x7f;delayms(50);// P2=0x80;delayms(50);// P2=0xc0;delayms(50);// P2=0xe0;delayms(50);// P2=0xf0;delayms(50);// P2=0xf8;delayms(50);// P2=0xfc;delayms(50);// P2=0xfe;delayms(50);// P2=0xff;delayms(50);//// P3=0x7f;delayms(50);// P3=0x3f;delayms(50);// P3=0x1f;delayms(50);// P3=0x0f;delayms(50);// P3=0x07;delayms(50);// P3=0x03;delayms(50);// P3=0x01;delayms(50);// P3=0x00;delayms(50);//// P3=0xc0;delayms(50);// P3=0xe0;delayms(50);// P3=0xf0;delayms(50);// P3=0xf8;delayms(50);// P3=0xfc;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;delayms(50);//// P1=0x7f;delayms(50);// P1=0x3f;delayms(50);// P1=0x1f;delayms(50);// P1=0x0f;delayms(50);// P1=0x07;delayms(50);// P1=0x03;delayms(50);// P1=0x01;delayms(50);// P1=0x00;delayms(50);//// P0=0x01;delayms(50);// P1=0x80;delayms(50);// P1=0xc0;delayms(50);// P1=0xe0;delayms(50);// P1=0xf0;delayms(50);// P1=0xf8;delayms(50);// P1=0xfc;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;delayms(50);////}/*----------------------------------------------------------*/ void cdP00() //沉淀语句{P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0xff;P0=0x7f;delayms(30);P0=0xbf;delayms(30);P0=0xef;delayms(30);P0=0xf7;delayms(30);P0=0xfb;delayms(30);P0=0xfd;delayms(30);P0=0xfe;delayms(30);}//P00void cdP01(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x7e;delayms(30);P0=0xbe;delayms(30);P0=0xde;delayms(30);P0=0xee;delayms(30);P0=0xf6;delayms(30);P0=0xfa;delayms(30);P0=0xfc;delayms(30);}//P01void cdP02(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x7c;delayms(30);P0=0xbc;delayms(30);P0=0xdc;delayms(30);P0=0xf4;delayms(30);P0=0xf8;delayms(30);}//P02void cdP03(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x78;delayms(30);P0=0xb8;delayms(30);P0=0xd8;delayms(30);P0=0xe8;delayms(30);P0=0xf0;delayms(30);}//P03void cdP04(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x70;delayms(30);P0=0xb0;delayms(30);P0=0xd0;delayms(30);P0=0xe0;delayms(30);}//P04void cdP05(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x60;delayms(30);P0=0xa0;delayms(30);P0=0xc0;delayms(30);}//P05void cdP06(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x40;delayms(30);P0=0x80;delayms(30);}//P06void cdP07(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x00;delayms(30);}//P07void cdP27(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);}//P27void cdP26(){P3=0x7e;delayms(30);//P3=0xff;P2=0x7e;delayms(30);P2=0x7d;delayms(30);P2=0x7b;delayms(30);P2=0x77;delayms(30);P2=0x6f;delayms(30);P2=0x5f;delayms(30);P2=0x3f;delayms(30);}//P26void cdP25(){P3=0x7c;delayms(30);//P3=0xff;P2=0x3e;delayms(30);P2=0x3d;delayms(30);P2=0x3b;delayms(30);P2=0x37;delayms(30);P2=0x2f;delayms(30);P2=0x1f;delayms(30);}//P25void cdP24(){P3=0x78;delayms(30);//P3=0xff;P2=0x1e;delayms(30);P2=0x1d;delayms(30);P2=0x1b;delayms(30);P2=0x17;delayms(30);P2=0x0f;delayms(30);}//P24void cdP23(){P3=0x70;delayms(30);//P3=0xff;P2=0x0e;delayms(30);P2=0x0d;delayms(30);P2=0x0b;delayms(30);P2=0x07;delayms(30);}//P23void cdP22(){P3=0x60;delayms(30);//P3=0xff;P2=0x06;delayms(30);P2=0x05;delayms(30);P2=0x03;delayms(30);}//P22void cdP21(){P3=0x20;delayms(30);//P3=0xff;P2=0x02;delayms(30);P2=0x01;delayms(30);}//P21void cdP20(){P3=0x00;delayms(30);//P3=0xff;P2=0x00;delayms(30);}//P20void cdP10(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30) ;P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0xff;P1=0x7f;delayms(30);P1=0xbf;delayms(30);P1=0xdf;delayms(30);P1=0xef;delayms(30);P1=0xf7;delayms(30);P1=0xfb;delayms(30);P1=0xfd;delayms(30);P1=0xfe;delayms(30);}//P10void cdP11(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x7e;delayms(30);P1=0xbe;delayms(30);P1=0xde;delayms(30);P1=0xee;delayms(30);P1=0xf6;delayms(30);P1=0xfa;delayms(30);P1=0xfc;delayms(30);}//P11void cdP12(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x7c;delayms(30);P1=0xbc;delayms(30);P1=0xdc;delayms(30);P1=0xec;delayms(30);P1=0xf4;delayms(30);P1=0xf8;delayms(30);}//P12void cdP13(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x78;delayms(30);P1=0xb8;delayms(30);P1=0xd8;delayms(30);P1=0xe8;delayms(30);P1=0xf0;delayms(30);}//P13void cdP14(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x70;delayms(30);P1=0xb0;delayms(30);P1=0xd0;delayms(30);P1=0xe0;delayms(30);}//P14void cdP15(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x60;delayms(30);P1=0xa0;delayms(30);P1=0xc0;delayms(30);}//P15void cdP16(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x40;delayms(30);P1=0x80;delayms(30);}//P16void cdP17(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x00;delayms(30);}//P17void cdP30(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);}//P30void cdP31(){P3=0x7e;delayms(30);P3=0xbe;delayms(30);P3=0xde;delayms(30);P3=0xee;delayms(30);P3=0xf6;delayms(30);P3=0xfa;delayms(30);P3=0xfc;delayms(30); }//P31void cdP32(){P3=0x7c;delayms(30);P3=0xbc;delayms(30);P3=0xdc;delayms(30);P3=0xec;delayms(30);P3=0xf4;delayms(30);P3=0xfb;delayms(30); }//P32void cdP33(){P3=0x78;delayms(30);P3=0xb8;delayms(30);P3=0xd8;delayms(30);P3=0xe8;delayms(30);P3=0xf0;delayms(30); }//P33void cdP34(){P3=0x70;delayms(30);P3=0xb0;delayms(30);P3=0xd0;delayms(30);P3=0xe0;delayms(30); }//P34void cdP35(){P3=0x60;delayms(30);P3=0xa0;delayms(30);P3=0xc0;delayms(30);}//P35void cdP36(){P3=0x40;delayms(30);P3=0x80;delayms(30);}//P36void cdP37(){P3=0x00;delayms(30);}//P37/*----------------------------------------------------------*/ void cd() //由下至上沉淀{cdP00();cdP10();cdP01();cdP11();cdP02();cdP12();cdP03();cdP13();cdP04();cdP14();cdP05();cdP15();cdP06();cdP16();cdP07();cdP17();cdP27();cdP30();cdP26();cdP31();cdP25();cdP32();cdP24();cdP33();cdP23();cdP34();cdP22();cdP35();cdP21();cdP36();cdP20();cdP37();delayms(500);Offall();delayms(300);Onall();delayms(300);Offall();delayms(300);Onall();delayms(300);}/*----------------------------------------------------------*/ void szsx() //左右同时生长(由上至下){Offall();P0=0xfe;delayms(50);P0=0xfc;delayms(50);P1=0xfe;delayms(50);P0=0xf8;delayms(50);P1=0xfc;delayms(50);P0=0xf0;delayms(50);P1=0xf8;delayms(50);P0=0xe0;delayms(50);P1=0xf0;delayms(50);P0=0xc0;delayms(50);P1=0xe0;delayms(50);P0=0x80;delayms(50);P1=0xc0;delayms(50);P0=0x00;delayms(50);P1=0x80;delayms(50);P2=0x7f;delayms(50);P1=0x00;delayms(50);P2=0x3f;delayms(50);P3=0xfe;delayms(50);P2=0x1f;delayms(50);P3=0xfc;delayms(50);P2=0x0f;delayms(50);P3=0xf8;delayms(50);P2=0x07;delayms(50);P3=0xf0;delayms(50);P2=0x03;delayms(50);P3=0xe0;delayms(50);P2=0x01;delayms(50);P3=0xc0;delayms(50);P2=0x00;delayms(50);P3=0x80;delayms(50);P3=0x00;delayms(50);}/*----------------------------------------------------------*/void szxs() //左右同时生长(由下至上){Offall();P3=0x7f;delayms(50);P2=0xfe;delayms(50);P3=0x3f;delayms(50);P2=0xfc;delayms(50);P3=0x1f;delayms(50);P2=0xf8;delayms(50);P3=0x0f;delayms(50);P2=0xf0;delayms(50);P3=0x07;delayms(50);P2=0xe0;delayms(50);P3=0x03;delayms(50);P2=0xc0;delayms(50);P3=0x01;delayms(50);P2=0x80;delayms(50);P3=0x00;delayms(50);P2=0x00;delayms(50);P1=0x7f;delayms(50);P0=0x7f;delayms(50);P1=0x3f;delayms(50);P0=0x3f;delayms(50);P1=0x1f;delayms(50);P0=0x1f;delayms(50);P1=0x0f;delayms(50);P0=0x0f;delayms(50);P1=0x07;delayms(50);P0=0x07;delayms(50);P1=0x03;delayms(50);P0=0x03;delayms(50);P1=0x01;delayms(50);P0=0x01;delayms(50);P1=0x00;delayms(50);P0=0x00;delayms(50);}/*----------------------------------------------------------*/void l1d() //1个灯转{P0=0xfe,P2=0x7f,P3=0x7f,P1=0x7f;delayms(50);P0=0xfd,P2=0xbf,P3=0xbf,P1=0xbf;delayms(50);P0=0xfb,P2=0xdf,P3=0xdf,P1=0xdf;delayms(50);P0=0xf7,P2=0xef,P3=0xef,P1=0xef;delayms(50);P0=0xef,P2=0xf7,P3=0xf7,P1=0xf7;delayms(50);P0=0xdf,P2=0xfb,P3=0xfb,P1=0xfb;delayms(50);P0=0xbf,P2=0xfd,P3=0xfd,P1=0xfd;delayms(50);P0=0x7f,P2=0xfe,P3=0xfe,P1=0xfe;delayms(50); }/*----------------------------------------------------------*/ void l2d() //2个灯转{P0=0xfc,P2=0x3f,P3=0x3f,P1=0x3f;delayms(50);P0=0xf9,P2=0x9f,P3=0x9f,P1=0x9f;delayms(50);P0=0xf3,P2=0xcf,P3=0xcf,P1=0xcf;delayms(50);P0=0xe7,P2=0xe7,P3=0xe7,P1=0xe7;delayms(50);P0=0xcf,P2=0xf3,P3=0xf3,P1=0xf3;delayms(50);P0=0x9f,P2=0xf9,P3=0xf9,P1=0xf9;delayms(50);P0=0x3f,P2=0xfc,P3=0xfc,P1=0xfc;delayms(50);P0=0x7e,P2=0x7e,P3=0x7e,P1=0x7e;delayms(50); }/*----------------------------------------------------------*/ void l3d() //3个灯转{P0=0xf8,P2=0x1f,P3=0x1f,P1=0x1f;delayms(50);P0=0xf1,P2=0x8f,P3=0x8f,P1=0x8f;delayms(50);P0=0xe3,P2=0xc7,P3=0xc7,P1=0xc7;delayms(50);P0=0xc7,P2=0xe3,P3=0xe3,P1=0xe3;delayms(50);P0=0x8f,P2=0xf1,P3=0xf1,P1=0xf1;delayms(50);P0=0x1f,P2=0xf8,P3=0xf8,P1=0xf8;delayms(50);P0=0x3e,P2=0x7c,P3=0x7c,P1=0x7c;delayms(50);P0=0x7c,P2=0x3e,P3=0x3e,P1=0x3e;delayms(50);}/*----------------------------------------------------------*/ void l4d() //4个灯转{P0=0xf0,P2=0x0f,P3=0x0f,P1=0x0f;delayms(50);P0=0xe1,P2=0x87,P3=0x87,P1=0x87;delayms(50);P0=0xc3,P2=0xc3,P3=0xc3,P1=0xc3;delayms(50);P0=0x87,P2=0xe1,P3=0xe1,P1=0xe1;delayms(50);P0=0xaf,P2=0xf0,P3=0xf0,P1=0xf0;delayms(50);P0=0x1e,P2=0x78,P3=0x78,P1=0x78;delayms(50);P0=0x3c,P2=0x3c,P3=0x3c,P1=0x3c;delayms(50);P0=0x78,P2=0x1e,P3=0x1e,P1=0x1e;delayms(50);}/*----------------------------------------------------------*/void l5d() //5个灯转{P0=0xe0,P2=0x07,P3=0x07,P1=0x07;delayms(50);P0=0xc1,P2=0x83,P3=0x83,P1=0x83;delayms(50);P0=0x83,P2=0xc1,P3=0xc1,P1=0xc1;delayms(50);P0=0x87,P2=0xe0,P3=0xe0,P1=0xe0;delayms(50);P0=0x0e,P2=0x70,P3=0x70,P1=0x70;delayms(50);P0=0x1c,P2=0x38,P3=0x38,P1=0x38;delayms(50);P0=0x38,P2=0x1c,P3=0x1c,P1=0x1c;delayms(50);P0=0x70,P2=0x0e,P3=0x0e,P1=0x0e;delayms(50);}/*----------------------------------------------------------*/void l6d() //6个灯转{P0=0xc0,P2=0x03,P3=0x03,P1=0x03;delayms(50);P0=0x81,P2=0x81,P3=0x81,P1=0x81;delayms(50);P0=0x03,P2=0xc0,P3=0xc0,P1=0xc0;delayms(50);P0=0x06,P2=0x60,P3=0x60,P1=0x60;delayms(50);P0=0x0c,P2=0x30,P3=0x30,P1=0x30;delayms(50);P0=0x18,P2=0x18,P3=0x18,P1=0x18;delayms(50);P0=0x30,P2=0x0c,P3=0x0c,P1=0x0c;delayms(50);P0=0x60,P2=0x06,P3=0x06,P1=0x06;delayms(50);}void main() //主函数,由于模块化设计,只要修改下面各模块的排列顺序和时间,就可以实现各种变化模式{while(1) //无限循环{cx();//一点点出现rja(); //渐暗Onall();delayms(100);Offall();delayms(100);Onall();delayms(180);Offall();delayms(180);Onall();delayms(180);Offall();delayms(300);Onall();delayms(300);rja(); //渐暗delayms(300);// for(x=10;x>0;x--)// ss(100);/* 闪烁20次,50ms */// //ls(); /* 正向流水*/rjl();Offall();delayms(100);zxsz(); /* 正向生长*/delayms(500);rja();//渐暗rzmzy(); //拖尾从上到下rzmyy(); //拖尾从下到上for(x=6;x>0;x--) /*P00闪烁6次50ms*/{P0=0xfe,delayms(50);P0=0xff,delayms(50);}szsx(); /* 半双边生长,由上至下*/rja();//渐暗for(x=10;x>0;x--)ss(100);/* 闪烁20次,50ms */Offall();rzmnwyd();delayms(100);//走马内外移动函数//l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转rja();//渐暗for(x=6;x>0;x--) /*P00闪烁6次50ms*/{P0=0xfe,delayms(50);P0=0xff,delayms(50);}bsb();//双边同时流水由上至下szxs(); /* 半双边生长,由下至上*/rja();//渐暗ss(100); /* 闪烁10次*/l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转Onall();delayms(200);c(700),c(600),c(500);//间隔闪烁c(400),c(300),c(200);c(100),c(100),c(100),c(100);c(50),c(50),c(50),c(50);Offall();for(x=10;x>0;x--){ss(100);}/* 闪烁*/rzmzy(); //拖尾从上到下szxs();/* 半双边生长,由下至上*/szsx(); /* 半双边生长,由上至下*/rja(); //渐暗delayms(100);rzmzy(); //拖尾从上到下//fbsb();/* 半双边流水由下至上*/for(x=10;x>0;x--){P3=0x7f;delayms(50);Offall();delayms(50); /* P37闪烁6次,50ms */ }cd(); /* 由下至上沉淀*///fxsw(); /* 反向死亡*/rja(); //渐暗rzmyy(); //拖尾从下到上bsb();//双边同时流水由上至下// fxsz();Offall(); /* 反向生长*/szsx();/* 左右同时生长由上至下*/rja();delayms(200);for(x=20;x>0;x--){ss(100);} /* 闪烁20次*/rjl(); //渐亮delayms(500);rja(); //渐暗rzmyy(); //拖尾从下到上szsx(); /* 半双边生长,由上至下*/Offall();delayms(100);rjl(); //渐亮Offall();delayms(500); //开启所有灯2sfor(x=20;x>0;x--){c(100);} /* 闪烁20次*/l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转for(x=3;x>0;x--){Onall();delayms(200);Offall();delayms(200);}Onall();delayms(500);rja(); //渐暗delayms(100);rzmzy(); //拖尾从上到下rzmyy(); //拖尾从下到上szsx();/* 左右同时生长由上至下*/delayms(300);rja(); //渐暗rjl(); //渐亮delayms(300);rzmnwyd(); //走马内外移动delayms(300);rja(); //渐暗delayms(300);rtbyd(); //眨眼rtbyd(); //眨眼Onall();delayms(180);Offall();delayms(180);Onall();delayms(180);Offall();delayms(180);Onall();delayms(500);Offall();delayms(300);szsx();/* 左右同时生长由上至下*/delayms(300);szsx();/* 左右同时生长由上至下*/rja();delayms(1000);Onall();delayms(2000);}}void rzmyy() //走马拖尾右移函数{Offall();delayms(200);P3=0x7f;delayms(60);P3=0xbf;P2=0xfe;if(P37==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P37 = 0;for(i = 0; i < 15; i++); //调节亮度高低P37 = 1;for(i = 0; i < 50; i++);}}P3=0xdf;P2=0xfd;if(P36==1 && P20==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P36 = 0;P20 = 0;for(i = 0; i < 15; i++); //调节亮度高低P37 = 0;for(i = 0; i < 1; i++); //调节亮度高低P36 = 1;P20 = 1;P37 = 1;for(i = 0; i < 50; i++);}}P3=0xef;P2=0xfb;if(P35==1 && P21 ==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P35 = 0;P21 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P36 = 0;P20 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P35 = 1;P21 = 1;P36 = 1;P20 = 1;for(i = 0; i < 50; i++);}}P3=0xf7;P2=0xf7;if(P34==1 && P22 == 1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P34 = 0;P22 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P35 = 0;P21 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P34 = 1;P22 = 1;P35 = 1;P21 = 1;for(i = 0; i < 50; i++);}}P3=0xfb;P2=0xef;if(P33==1 && P23==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P33 = 0;P23 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P34 = 0;P22 = 0;for(i = 0; i < 1; i++); //调节亮度高低P33 = 1;P23 = 1;P34 = 1;P22 = 1;for(i = 0; i < 50; i++);}}P3=0xfd;P2=0xdf;if(P32==1 && P24==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P32 = 0;P24 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P33 = 0;P24 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P32 = 1;P24 = 1;P33 = 1;P23 = 1;for(i = 0; i < 50; i++);}}P3=0xfe;//P3^0P2=0xbf;//P2^6if(P31==1 && P25==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P31 = 0;P25 = 0;for(i = 0; i < 15; i++); //调节亮度高低P32 = 0;。
多种方法写出的51单片机流水灯C语言程序
多种方法写出的51单片机流水灯C语言程序流水灯最原始下面是一个最基本的流水灯程序,使用了51单片机的寄存器编程方法。
include "reg51.h"sbit p0=P1^0;sbit p1=P1^1;sbit p2=P1^2;sbit p3=P1^3;sbit p4=P1^4;sbit p5=P1^5;sbit p6=P1^6;sbit p7=P1^7;void mdelay(unsigned int t){unsigned char n;for(;t>0;t--)for(n=0;n<125;n++)void main()while(1)P1=0;p0=1;mdelay(1000);p0=0;p1=1;mdelay(1000);p1=0;p2=1;流水灯位左移在流水灯的基础上,我们可以通过左移位的方式来实现流水灯的效果。
void main()unsigned char led = 0x01.// 初始化led为xxxxxxxxwhile(1)P1 = ~led。
// 取反输出,因为我们的电路是低电平亮灯mdelay(1000);led <<= 1.// 左移一位if(led == 0) // 如果led变为0了,说明已经左移到最后一位了,需要重新开始led = 0x01;流水灯移位函数为了方便实现流水灯的位移,我们可以封装一个移位函数。
void shift_left(unsigned char *led。
unsigned char n)for(unsigned char i=0.i<n。
i++)led <<= 1;if(*led == 0)led = 0x01;void main()unsigned char led = 0x01;while(1)P1 = ~led;mdelay(1000);shift_left(&led。
51单片机流水灯汇编与c语言程序
ALEA B C D E F G DPALE A B C D E F G D P1234ALE 2134XTAL218XTAL119ALE 30EA31PSEN 29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.0/T21P1.1/T2EX 2P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD 10P3.1/TXD 11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR 16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C52234567891RP1RESPACK-8D02D13D24D35D46D57D68D79Q019Q118Q217Q316Q415Q514Q613Q712LE 11OE 1U274HC573R1R2R3R4R5R6R7R8D1LED-REDD2LED-YELLOW D3LED-GREEND4LED-GREEND5LED-REDD6LED-YELLOWD7LED-GREEND8LED-GREEND02D13D24D35D46D57D68D79Q019Q118Q217Q316Q415Q514Q613Q712LE 11OE 1U374HC573R171kR181kR191kR201k/*******flowing water light*********///晶振:12M ,P0口接8个led进行流水灯显示,74HC573驱动,8位led共阴接法ORG 0000HLJMP MAINORG 0030H //主程序从程序存储器0030H单元开始存放MAIN: MOV P0,#0FFH //P0口初始化MOV A,#01H //共阴接法,点亮最低位LEDLOOP: MOV P0,ALCALL DELAY_1S //延时1sRL A //循环左移一次,点亮下一位SJMP LOOP //跳转到LOOP处执行,死循环// 3层嵌套软件延时子程序,延时1sDELAY_1S: MOV R1,#10 //最外层循环体执行10次DELAY0: MOV R2,#200 //中间层循环体执行200次DELAY1: MOV R3,#248 //最内层循环体执行248次DJNZ R3,$ //循环子程序最内层,执行时间248*2=496usNOP //空操作,为了凑到准确的500us执行时间DJNZ R2,DELAY1 //中间层循环体(1+496+1+2)*200=100000us=100msDJNZ R1,DELAY0 //最外层循环体(100ms+2us)*10=1000.02msRETEND/*******flowing water light*********/#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned int//延时函数void Delay_ms(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}//主函数void main(){P0=0xff; //P0口初始化P0=0x01; //共阴接法,点亮最低位LEDwhile(1){Delay_ms(1000); //延时约1sP0=_crol_(P0,1); //P0 的值向左循环移动,_crol_()函数在头文件intrins.h中}}。
心型流水灯程序
心型流水灯程序#include <REG52.H> //包含51头文件 #include <intrins.h> //使用左移右移头文件 #define uint unsigned int#define uchar unsigned char //宏定义void delay_ms(uint x) //毫秒级延时函数 {uint y;for(;x>0;x--)for(y=110;y>0;y--); }void main() //主函数{uchar i,aa;uint k;while(1){//-------------顺时针流动5次------------//for(k=0;k<2;k++){aa=0xFE;for(i=0;i<8;i++){P0=aa;aa=_crol_(aa,1); //crol是左移delay_ms(200);}P0=0xFF;aa=0x7F;for(i=0;i<8;i++){P2=aa;aa=_cror_(aa,1); //cror是右移delay_ms(200);}P2=0xFF;aa=0x7F;for(i=0;i<8;i++){P3=aa;aa=_cror_(aa,1);delay_ms(200);}P3=0xFF;aa=0x7F;for(i=0;i<8;i++){P1=aa;aa=_cror_(aa,1);delay_ms(200);}aa=P1=0xFF;}P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00; //与P3=0xFF;相同delay_ms(500);//----------------逆时针流动5次--------------// for(k=0;k<2;k++){for(i=0;i<8;i++){P1=~(0x01<<i);delay_ms(200);}P1=0xFF;for(i=0;i<8;i++){P3=~(0x01<<i);delay_ms(200);}P3=0xFF;for(i=0;i<8;i++){P2=~(0x01<<i);delay_ms(200);}P2=0xFF;for(i=0;i<8;i++){P0=~(0x80>>i);delay_ms(200);}P0=0xFF;}P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00;delay_ms(500);//---------------------上到下画爱心--------------// for(k=0;k<2;k++){for(i=0;i<8;i++){P1=~(0x01<<i);P0=~(0x01<<i);delay_ms(200);}P1=0xFF;P0=0xFF;for(i=0;i<8;i++){P3=~(0x01<<i);P2=~(0x80>>i);delay_ms(200);}P3=0xFF;P2=0xFF;}P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00;delay_ms(500);//----------------下到上画爱心---------------// for(k=0;k<2;k++){for(i=0;i<8;i++){P2=~(0x01<<i);P3=~(0x80>>i);delay_ms(200);}P2=0xFF;P3=0xFF;for(i=0;i<8;i++){P1=~(0x80>>i);P0=~(0x80>>i);delay_ms(200);}P1=0xFF;P0=0xFF;}P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00;delay_ms(500);//-----------------累加1---------------// for(k=0;k<=255;k++){aa++;P1=~aa;P0=~aa;delay_ms(60);}aa=0;P1=0xFF;P0=0xFF;for(k=0;k<=255;k++){aa++;P3=~aa;P2=~aa;delay_ms(60);}aa=0;P3=0xFF;P2=0xFF;//-----------------累加2---------------// for(k=0;k<255;k++){aa++;P1=~aa;P0=~aa;delay_ms(60);}aa=0;for(k=0;k<255;k++){aa++;P3=~aa;P2=~aa;delay_ms(60);}aa=0;delay_ms(3500);P3=0xFF;P2=0xFF;P1=0xFF;P0=0xFF;delay_ms(500);//------------------卷动笑脸-----------------// for(k=0;k<=40;k++){aa++;aa=_crol_(aa,7);P0=~aa;P1=~aa;P3=0x3F;P2=0xf8;delay_ms(200);}aa=0;P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;//-----------------循环5次闪烁---------------// for(k=0;k<5;k++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay_ms(500);P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00; //与P3=0xFF一样delay_ms(500);}//---------------最后的笑脸显示------------//for(k=0;k<5;k++){P1=0x83;P3=0x3F;P2=0xf8;P0=0xC1;delay_ms(1000); }P0=~0x00;P1=~0x00;P2=~0x00;P3=~0x00;}}。
51单片机流星灯c语言源程序
51单片机流星灯c语言源程序大家自己根据程序中的io定义部分接上灯即可实现流星灯的效果!!// ................................................................. //内控自走程序//CPU: STC12C2052//主频:18. 432MHZ (外部晶振144),内部晶振5MHZ//日期:2008/11/30// ................................................................. ttinclude ;ttinclude ;ttinclude ;ttinclude ;^include;//产生随机数SAND ();ttdefine uchar unsigned charttdefine uint unsigned int#define TO_DAH 160;#define TO_DAL 160;#define Speed_Data 0x2;voiddelay(uint);voidOut_Put (void); sfr P3Ml=0xB2;void Read_Prol(void);void Read_Pro2(void); voidPwm_Out (void);voidRead_Pro_R(uchar QW_Datai);/////////////////////////////// //////////IO 口定义///////////// /////////////////////////////// sbitExPortl=P1^0;sbit ExPort8=Pl^l;//2 sbitExPort7=Pr2;//8 sbitExPort6=P1^3;//7 sbit ExPort5=Pr4;//6 sbitExPort4=Pl"5;//5 sbit ExPort 3 二P「6; //4 sbitExPort2=Pl 7;//3 sbitExport9=P3^0;// sbitExportlO=P3^1;// //定义RAM sfr PlM0=0x91; sfrPIMl二0x92;sfr P3M0=0xBl;sfrWDT_CONTR=Oxel;sfr ISP_TRIG=0xe6;sfr SPSTAT=0x84;sfrPCA_PWM0=0xf2;sfrunml=0xf3;sfr unm2=0xf4;sfrunm3=0xf5;sfr unm4=0xf6;sfrunm5=0xf7;sfr unm6=0xf8:bit TimeO_Flag;uchar Speed, TimeO_Dec, Latch, Add_speed; uchar delay_X, Run_S, Run_S1;uint delay_z;ucharDisplay_Data[10];///////////////////////////////////////////共十六等级//////////////////////////////////////////////voidtimer_0 (void) interrupt 1//共十六等级sfr P3Ml=0xB2;TimeO_Flag=l;P3Ml=0x03;TimeO_Dec ——;/ /%J< ^X^X// xrx xjx xjx xjx xjx XjS XjS XTX Zr^ xrx ✓Tx ✓Tx xjx xjx XjX xTx zTv^Tx Z T ^ Z T ^ Z TX x?^ xr^ xT^ xT% xTx xTx xTx xr^**//// 主函数功能 // //主要产生花样数据/// /%J<//xrx xjx xjx xjx xjx XjS XjS XTX Zr^xrx ✓Tx ✓Tx xjx xjx XjXxTx zTv^Tx Z T ^ Z T ^ Z TX x?^ xr^ xT^ xT% xTx xTx xTx xr^voidmain(void)///////////////////////////////////////////////// /////////////////////IO 口初始化/////////////////////////////////////////////////////////////////////////// /////*************************读入 ID 号K |>/✓Jx xjxxTx zjv xT% xTx xTx x7^/P3M0二0x00;memset(Display_Data, 0x00, sizeof(Display_Data)); P3Ml=0x03;//产生一个随机字符型数据TM0D=0xl2;TR1=1;delay_z = ((THl;O;i--) //]短{辻(i=4)B_W 二64;辻(i==3)B_W=35;辻(i==2)B_W=10;辻(i==l)B_W=l;Read_Pro_R(B_W);}for (i=Run_S;i>;0;i--){Read_Pro_R(0);}for(j=0;j;0;i--)//2 长{if (i==7)B_W=64;辻(i==6)B_W=63;辻(i==5)B_W=62;if (i==4)B_W=60;辻(i==3)B_W=55;辻(i==2)B_W=40;辻(i==l)B_W=15;//* *-(0)旷0%—p歸出 (一一!:0:〈!人一uq二!)JOJ:(M_9)旷0%—pp汨4[二([二二!)J!:0WF2(Z=!)J!•gg=M_9(£=T)JT•S9=M_9(^=T)JT•^9=M_9(g=T)JT}申乙//(一一!:0:『:0二『)4。
单片机心型流水灯程序
for(i=0;i<5;i++)
{
P0=0xaa; P1=0xaa; P2=0xaa; P3=0xaa;
delay(300);
P0=~P0; P1=~P1; P2=~P2; P3=~P3;
delay(300);
}
P0=0xff; P2=0xff; P1=0xff; P3=0xff;
delay(300);
voiddisp22装态222个led自上而下移动循环5次且频率渐快到最快时持续循环16次然后循环5次频率再逐渐降低forj0
#include <REGX52.H>
#defineuintunsigned int
#defineucharunsigned char
uchar code table0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//LED从低位往高位移
}
}
void disp12()//间断8格的4个LED亮,然后顺时针逐渐点亮(直到全部点亮)
{
for(i=0;i<8;i++)
{
P0=table2[i];
P2=table3[i];
P1=table3[i];
P3=table3[i];
delay(100);
}
delay(1000);
}
void disp13()//状态13从LED全部亮到全不亮(间断8格的4个LED开始顺时针熄灭)
}
void disp18()//状态18 LED从P0.7开始逆时针逐步点亮(每亮8位后就熄灭)
{
for(i=0;i<8;i++)
32种花样流水灯c语言程序,32LED单片机心形花样流水灯程序+视频
32种花样流⽔灯c语⾔程序,32LED单⽚机⼼形花样流⽔灯程序+视频include#include#define uint unsigned int#define uchar unsigned charuchar code zou[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//单个从0到7uchar code you[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//单个从7到0uchar code liang0_7[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}; // 逐个点亮0~7uchar code liang7_0[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; // 逐个点亮7~0uchar code mie0_7[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; // 逐个灭0~7uchar code mie7_0[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; // 逐个灭7~0/***********************************************************/void delay(uint t); //延时void zg(uint t,uchar a);//两边逐个亮void qs(uint t,uchar a);//全部闪烁void zgxh(uint t,uchar a); // 逆时针逐个点亮//void zgxh1(uint t,uchar a); // 顺时针逐个点亮void djs(uint t,uchar a); //对⾓闪void lbzgm(uint t,uchar a);//两边逐个灭//void sszgm(uint t,uchar a); // 顺时针逐个灭void nszgm(uint t,uchar a); // 逆时针逐个灭void sztl(uint t,uchar a);//顺时逐个同步亮void nztl(uint t,uchar a);//逆时逐个同步亮void sztm(uint t,uchar a);//顺时逐个同步灭void nztm(uint t,uchar a);//逆时逐个同步灭void hwzjl(uint t,uchar a); //横往中间亮void hwzjm(uint t,uchar a); //横往中间灭//void swzjl(uint t,uchar a); //竖往中间亮//void swzjm(uint t,uchar a); //竖往中间灭void nzdl(uint t,uchar a); //逆时逐段亮void nzdgl(uint t,uchar a); //逆时逐段⼀个点亮void jgs(uint t,uchar a); //间隔闪/**********************************************************/ void zg(uint t,uchar a)//两边逐个亮{uchar i,j;for(j=0;j{P0=P1=P2=P3=0x00;P0=0x01;delay(t);for(i=0;i<7;i++){P0=liang0_7[i+1];P3=liang7_0[i];delay(t);}P3=0xff;P1=0x01;delay(t);for(i=0;i<7;i++){P1=liang0_7[i+1];P2=liang7_0[i];delay(t);}P2=0xff;delay(t);}}void qs(uint t,uchar a) //全部闪烁{uchar j;for(j=0;j。
心型流水灯的制作包括代码和电路图
#include <intrins.h>
#defineuint unsigned int
#defineuchar unsigned char
uchar code table[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00}; //逐个点亮0~7
void hwzjm(uint t,uchar a); //横往中间灭
//void swzjl(uint t,uchar a); //竖往中间亮
//void swzjm(uint t,uchar a); //竖往中间灭
void nzdl(uint t,uchar a); //逆时逐段亮
void nzdgl(uint t,uchar a); //逆时逐段一个点亮
{
uchar i,j;
for (j=0;j<a;j++)
{
P0=P1=P2=P3=0xff;
for(i=0;i<8;i++)
{
P0=P2=P1=table[i];
P3=table1[i];delay(t);
}
}
}
void swzjm(uint t,uchar a) //竖往中间灭
{
uchar i,j;
}
P3=0x00;delay(t);
}
}
void qs(uint t,uchar a)//全部闪烁
{
uchar j;
for(j=0;j<a;j++)
{
P0=P1=P2=P3=0xff;
delay(t);
P0=P1=P2=P3=0x00;
32LED心形灯程序源代码(包含仿真图)
#include<reg52.h>unsigned int m=1;void delayms(int n)//延时{int i;for(;n>0;n--)for(i=330;i>0;i--);}void way1() //花样1:32个LED灯同时从灭到亮{ int k;k=m+5;while(k){int i=5,j=5;for(;j>0;j--)P0=0X00;P1=0X00;P2=0X00;P3=0X00;delayms(200);for(;i>0;i--)P0=0Xff;P1=0Xff;P2=0Xff;P3=0Xff;delayms(200);k--;}}void way2() //花样2:交叉点亮,从右往左依次点亮,再依返回。
{unsigned int k;unsigned char temp,temp1,sum=0;unsigned int i,j;k=m;while(k){for(j=2;j>0;j--)P0=0X00;P1=0X00;P2=0X00; P3=0X00;//r->l delayms(500);P0=0Xff;P1=0Xff;P2=0xff;P3=0xff;temp=0x01;for(i=0;i<9;i++){P0=~temp;delayms(70);temp=temp<<1;}temp=0x01;for(i=0;i<9;i++){P2=~temp;delayms(70);temp=temp<<1;}temp=0x01;for(i=0;i<9;i++){P3=~temp;delayms(70);temp=temp<<1;}temp=0x01;for(i=0;i<9;i++){P1=~temp;delayms(70);temp=temp<<1;}P0=0X00;P1=0X00;P2=0X00; P3=0X00;//l->r delayms(500);P0=0Xff;P1=0Xff;P2=0xff;P3=0xff;temp=0x80;for(i=0;i<9;i++){P1=~temp;delayms(70);temp=temp>>1;}temp=0x80;for(i=0;i<9;i++){P3=~temp;delayms(70);temp=temp>>1;}temp=0x80;for(i=0;i<9;i++){P2=~temp;delayms(70);temp=temp>>1;}temp=0x80;for(i=0;i<9;i++){P0=~temp;delayms(70);temp=temp>>1;}P0=0X00;P1=0X00;P2=0X00; P3=0X00; delayms(500);P0=0Xff;P1=0Xff;P2=0xff;P3=0xff;temp=0x01;temp1=0x80;for(i=0;i<9;i++){P0=~temp;P1=~temp1;temp=temp<<1;temp1=temp1>>1;delayms(70);}temp=0x01;temp1=0x80;for(i=0;i<9;i++){P2=~temp;P3=~temp1;temp=temp<<1;temp1=temp1>>1;delayms(70);}temp=0x01;temp1=0x80;for(i=0;i<9;i++){P3=~temp;P2=~temp1;temp=temp<<1;temp1=temp1>>1;delayms(70);}temp=0x01;temp1=0x80;for(i=0;i<9;i++){P1=~temp;P0=~temp1;temp=temp<<1;temp1=temp1>>1;delayms(70);}}k--;}}void way3(){unsigned int i,sum,sum1,k,temp1;unsigned int temp=0x01;k=m;P0=0Xff; //两边同时向下闪P1=0Xff;P2=0xff;P3=0xff;while(k){temp1=0xfe;temp=0x7f;sum=0;for(i=0;i<8;i++){P0=temp1;P1=temp;delayms(100);temp1=temp1<<1;temp=temp>>1;}temp1=0xfe;temp=0x7f;sum=0;for(i=0;i<8;i++){P2=temp1;P3=temp;delayms(100);temp1=temp1<<1;temp=temp>>1;}P0=0X00; //全亮P1=0X00;P2=0x00;P3=0x00;delayms(100);temp=0x01;//返回temp1=0x80;sum=0;sum1=0;for(i=0;i<8;i++){sum=sum+temp;P3=sum;temp=temp<<1;sum1=sum1+temp1;P2=sum1;temp1=temp1>>1;delayms(100);}P2=0Xff; P3=0xff;delayms(100);temp=0x01;temp1=0x80;sum=0;sum1=0;for(i=0;i<8;i++){sum=sum+temp;P1=sum;temp=temp<<1;sum1=sum1+temp1;P0=sum1;temp1=temp1>>1;delayms(100);}P0=0Xff; //两边同时向上闪P1=0Xff;P2=0xff;P3=0xff;temp1=0xfe;temp=0x7f;sum=0;for(i=0;i<8;i++){P3=temp1;P2=temp;delayms(100);temp1=temp1<<1;temp=temp>>1;}temp1=0xfe;temp=0x7f;sum=0;for(i=0;i<8;i++){P1=temp1;P0=temp;delayms(100);temp1=temp1<<1;temp=temp>>1;}P0=0X00; //全亮P1=0X00;P2=0x00;P3=0x00;delayms(100);temp=0x01;//返回temp1=0x80;sum=0;sum1=0;for(i=0;i<8;i++){sum=sum+temp;P0=sum;temp=temp<<1;sum1=sum1+temp1;P1=sum1;temp1=temp1>>1;delayms(100);}temp=0x01;temp1=0x80;sum=0;sum1=0;for(i=0;i<8;i++){sum=sum+temp;P2=sum;temp=temp<<1;sum1=sum1+temp1;P3=sum1;temp1=temp1>>1;delayms(100);}k--;}}void way4()//相间交叉闪烁{unsigned int temp=0x55;unsigned int k,j;k=m+3;j=m+3;while(k){P0=~temp;P1=~temp;P2=~temp;P3=~temp;delayms(200);P0=temp;P1=temp;P2=temp;P3=temp;delayms(200);k--;}while(j){P0=temp;P1=temp;P2=temp;P3=temp;delayms(200);P0=~temp;P1=~temp;P2=~temp;P3=~temp;delayms(200);j--;}}void way5(){unsigned int k,j;//8个灯一起亮并旋转k=m+4;j=m+4;while(k){P0=0xaa;delayms(200);P0=0xff;P0=0x55;delayms(200);P0=0xff;P2=0xaa;delayms(200);P2=0xff;P2=0x55;delayms(200);P2=0xff;P3=0xaa;delayms(200);P3=0xff;P3=0x55;delayms(200);P3=0xff;P1=0xaa;delayms(200);P1=0xff;P1=0x55;delayms(200);P1=0xff;}while(j){P1=0x55;delayms(200);P1=0xff;P1=0xaa;delayms(200);P1=0xff;P3=0x55;delayms(200);P3=0xff;P3=0xaa;delayms(200);P3=0xff;P2=0x55;delayms(200);P2=0xff;P2=0xaa;delayms(200);P2=0xff;P0=0x00;delayms(200);P0=0xff;P0=0xaa;delayms(200);P0=0xff;j--;}}void way6()//两边同时对称闪{unsigned int i,j,sum,sum1,k,temp1; k=m+1;while(k){P0=0Xff;P1=0Xff;P2=0xff;P3=0xff;for(j=3;j>0;j--){temp1=0xfe;for(i=0;i<8;i++){P0=temp1;P3=temp1;delayms(100);temp1=temp1<<1;temp1=0xfe;for(i=0;i<8;i++){P2=temp1;P1=temp1;delayms(100);temp1=temp1<<1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0Xff;delayms(100);}for(j=3;j>0;j--){temp1=0x7f;//返回for(i=0;i<8;i++){P1=temp1;P2=temp1;temp1=temp1>>1;delayms(100);}temp1=0x7f;for(i=0;i<8;i++){P3=temp1;P0=temp1;temp1=temp1>>1;delayms(100);}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0xff;delayms(100);}way3();for(j=3;j>0;j--){temp1=0xfe;for(i=0;i<8;i++){P0=temp1;P3=temp1;delayms(100);temp1=temp1<<1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0Xff;delayms(100);temp1=0xfe;for(i=0;i<8;i++){P2=temp1;P1=temp1;delayms(100);temp1=temp1<<1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0Xff;delayms(100);}for(j=3;j>0;j--){temp1=0xfe;for(i=0;i<8;i++){P0=temp1;P3=temp1;delayms(100);temp1=temp1<<1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0Xff;delayms(100);temp1=0xfe;for(i=0;i<8;i++){P2=temp1;P1=temp1;delayms(100);temp1=temp1<<1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0Xff;delayms(100);}for(j=3;j>0;j--){temp1=0x7f;//返回for(i=0;i<8;i++){P1=temp1;P2=temp1;delayms(100);temp1=temp1>>1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0xff;delayms(100);temp1=0x7f;for(i=0;i<8;i++){P3=temp1;P0=temp1;delayms(100);temp1=temp1>>1;}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0xff;delayms(100);}k--;}}void way7(){unsigned int temp,temp1,temp2,i,j;temp1=0xfe;for(j=0;j<8;j++){temp=temp1;for(i=0;i<8;i++){P0=temp;temp=temp<<1;delayms(100);}P0=temp1;delayms(100);temp=temp1;for(i=0;i<8;i++){P2=temp;temp=temp<<1;delayms(100);}P2=temp1;delayms(100);temp=temp1;for(i=0;i<8;i++){P3=temp;temp=temp<<1;delayms(100);}P3=temp1;delayms(100);temp=temp1;for(i=0;i<8;i++){P1=temp;temp=temp<<1;delayms(100);}P1=temp1;delayms(100);temp1=temp1<<1; delayms(100);}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0xff;delayms(100);temp2=0x7f;for(j=0;j<8;j++){temp=temp2;for(i=0;i<8;i++){P1=temp;temp=temp>>1;delayms(100); }P1=temp2; delayms(100);temp=temp2;for(i=0;i<8;i++){P3=temp;temp=temp>>1;delayms(100); }P3=temp2; delayms(100);temp=temp2;for(i=0;i<8;i++){P2=temp;temp=temp>>1;delayms(100); }P2=temp2; delayms(100);temp=temp2;for(i=0;i<8;i++){P0=temp;temp=temp>>1;delayms(100);}P0=temp2;delayms(100);temp2=temp2>>1;delayms(100);}P0=0Xff; //全灭P1=0Xff;P2=0xff;P3=0xff;delayms(100);}void main(){while (1){way1();way2();way3();way6();way3();way7();way4();way5();}}。
心形流水灯
假设无双面板,红色线拿导线连,用到32个LED灯和32个电阻,灯用5MM七彩快闪较好看,电阻220欧到1000欧皆可,我用的是220欧的,剩下的便是单片机最小系统的元件,这是程序//***********************************************// 本例通过两种方法实现相同的流水灯功能//***********************************************#include<reg51.h>//************8位将流水灯编码存于单片机程序存储中******************unsigned char code LED1_shun[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; //顺时针点亮数据unsigned char code LED2_ni[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE}; //逆时针点亮数据unsigned int N=300;void delay(unsigned int n){unsigned int i;unsigned char j;for(i=0;i<n;i++)for(j=100;j>0;j--);}void Display_One(void){unsigned char i,j;unsigned char temp;for(j=0;j<2;j++){//------------------顺时针------------------temp=0x7F;for(i=0;i<8;i++){P0=temp;delay(N);temp=((temp>>1)|0x80);}P0=0xFF;temp=0xFE;for(i=0;i<8;i++){P1=temp;delay(N);temp=((temp<<1)|0x01);}P1=0xFF;temp=0xFE;for(i=0;i<8;i++){P2=temp;delay(N);temp=((temp<<1)|0x01);}P2=0xFF;temp=0xFE;for(i=0;i<8;i++){P3=temp;delay(N);temp=((temp<<1)|0x01);}P3=0xFF;//----------------------------逆时针------------------------ temp=0x7F;for(i=0;i<8;i++){P3=temp;delay(N);temp=((temp>>1)|0x80);}P3=0xFF;temp=0x7F;for(i=0;i<8;i++){P2=temp;delay(N);temp=((temp>>1)|0x80);}P2=0xFF;temp=0x7F;for(i=0;i<8;i++){P1=temp;delay(N);temp=((temp>>1)|0x80);}P1=0xFF;temp=0xFE;for(i=0;i<8;i++){P0=temp;delay(N);temp=((temp<<1)|0x01);}P0=0xFF;}}void Display_Two(void){unsigned char i,j;unsigned char temp1,temp2;for(j=0;j<2;j++){//------------------------------------------temp1=0x7F;for(i=0;i<8;i++){P0=temp1;P3=temp1;delay(N);temp1=((temp1>>1)|0x80);}P0=0xFF;P3=0xFF;temp1=0xFE;temp2=0x7F;for(i=0;i<8;i++){P1=temp1;P2=temp2;delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}P1=0xFF;P2=0xFF;//-------------------------------------------- temp1=0xFE;temp2=0x7F;for(i=0;i<8;i++){P1=temp2;P2=temp1;delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}P1=0xFF;P2=0xFF;temp1=0xFE;for(i=0;i<8;i++){P0=temp1;P3=temp1;delay(N);temp1=((temp1<<1)|0x01);}P0=0xFF;P3=0xFF;}}void Display_Three(void){unsigned char i,j;unsigned char temp1,temp2;for(j=0;j<4;j++){temp1=0x77;temp2=0xEE;for(i=0;i<4;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N+N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;delay(N);}}void Display_Four(void){unsigned char i,j;unsigned char temp1;for(j=0;j<2;j++){//------------------------------------------- temp1=0x7F;for(i=0;i<8;i++){P0=temp1;delay(N);temp1=(temp1>>1);}temp1=0xFE;for(i=0;i<8;i++){P1=temp1;delay(N);temp1=(temp1<<1);}temp1=0xFE;for(i=0;i<8;i++){P2=temp1;delay(N);temp1=(temp1<<1);}temp1=0xFE;for(i=0;i<8;i++){P3=temp1;delay(N);temp1=(temp1<<1);}//------------------------------------------------ temp1=0x80;for(i=0;i<8;i++){P0=temp1;delay(N);temp1=((temp1>>1)|0x80);}temp1=0x01;for(i=0;i<8;i++){P1=temp1;delay(N);temp1=((temp1<<1)|0x01);}temp1=0x01;for(i=0;i<8;i++){P2=temp1;delay(N);temp1=((temp1<<1)|0x01);}temp1=0x01;for(i=0;i<8;i++){P3=temp1;delay(N);temp1=((temp1<<1)|0x01);}}}void Display_Five(void){unsigned char i,j;unsigned char temp1,temp2;//-----------------------------------------------for(j=0;j<4;j++){temp1=0x07;temp2=0xE0;for(i=0;i<4;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N+N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}temp1=0x70;temp2=0x0E;for(i=0;i<4;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N+N);temp1=(temp1>>1);temp2=(temp2<<1);}delay(N);}//---------------------------------------------for(j=0;j<4;j++){temp1=0xE0;temp2=0x07;for(i=0;i<4;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N+N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}temp1=0x0E;temp2=0x70;for(i=0;i<4;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N+N);// temp1=((temp1<<1)|0x01);// temp2=((temp2>>1)|0x80);temp1=(temp1<<1);temp2=(temp2>>1);}delay(N);}}void Display_Six(void){unsigned char i;for(i=0;i<4;i++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(N+N+N);P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;delay(N+N+N);}}void Display_Seven(void){unsigned char i;unsigned char temp1,temp2;temp1=0x7F;temp2=0xFE;for(i=0;i<8;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}temp1=0x7F;temp2=0xFE;for(i=0;i<8;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}temp1=0x7F;temp2=0xFE;for(i=0;i<7;i++){P0=(temp1&0xFE);P1=(temp2&0x7F);P2=(temp2&0x7F);P3=(temp2&0x7F);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);temp1=0x7F;temp2=0xFE;for(i=0;i<6;i++){P0=(temp1&0xFC);P1=(temp2&0x3F);P2=(temp2&0x3F);P3=(temp2&0x3F);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01); }temp1=0x7F;temp2=0xFE;for(i=0;i<5;i++){P0=(temp1&0xF8);P1=(temp2&0x1F);P2=(temp2&0x1F);P3=(temp2&0x1F);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01); }temp1=0x7F;temp2=0xFE;for(i=0;i<4;i++){P0=(temp1&0xF0);P1=(temp2&0x0F);P2=(temp2&0x0F);P3=(temp2&0x0F);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01); }temp1=0x7F;temp2=0xFE;for(i=0;i<3;i++)P0=(temp1&0xE0);P1=(temp2&0x07);P2=(temp2&0x07);P3=(temp2&0x07);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}temp1=0x7F;temp2=0xFE;for(i=0;i<2;i++){P0=(temp1&0xC0);P1=(temp2&0x03);P2=(temp2&0x03);P3=(temp2&0x03);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}temp1=0x7F;temp2=0xFE;for(i=0;i<1;i++){P0=(temp1&0x80);P1=(temp2&0x01);P2=(temp2&0x01);P3=(temp2&0x01);delay(N);temp1=((temp1>>1)|0x80);temp2=((temp2<<1)|0x01);}delay(N+N+N);}void Display_Eight(void){unsigned char i;unsigned char temp1,temp2;temp1=0x7F;temp2=0xFE;for(i=0;i<1;i++){P0=(temp1&0x80);P1=(temp2&0x01);P2=(temp2&0x01);P3=(temp2&0x01);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xBF;temp2=0xFD;for(i=0;i<2;i++){P0=(temp1&0xC0);P1=(temp2&0x03);P2=(temp2&0x03);P3=(temp2&0x03);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xDF;temp2=0xFB;for(i=0;i<3;i++){P0=(temp1&0xE0);P1=(temp2&0x07);P2=(temp2&0x07);P3=(temp2&0x07);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xEF;temp2=0xF7;for(i=0;i<4;i++){P0=(temp1&0xF0);P1=(temp2&0x0F);P2=(temp2&0x0F);P3=(temp2&0x0F);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xF7;temp2=0xEF;for(i=0;i<5;i++){P0=(temp1&0xF8);P1=(temp2&0x1F);P2=(temp2&0x1F);P3=(temp2&0x1F);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xFB;temp2=0xDF;for(i=0;i<6;i++){P0=(temp1&0xFC);P1=(temp2&0x3F);P2=(temp2&0x3F);P3=(temp2&0x3F);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80); }temp1=0xFD;temp2=0xBF;for(i=0;i<7;i++){P0=(temp1&0xFE);P1=(temp2&0x7F);P2=(temp2&0x7F);P3=(temp2&0x7F);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}temp1=0xFE;temp2=0x7F;for(i=0;i<7;i++){P0=(temp1&0xFE);P1=(temp2&0x7F);P2=(temp2&0x7F);P3=(temp2&0x7F);delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}temp1=0xFE;temp2=0x7F;for(i=0;i<8;i++){P0=temp1;P1=temp2;P2=temp2;P3=temp2;delay(N);temp1=((temp1<<1)|0x01);temp2=((temp2>>1)|0x80);}delay(N+N+N);}void Display_Nine(void){unsigned char i;for(i=0;i<8;i++){P0=0x55;P1=0xAA;P2=0xAA;P3=0xAA;delay(N);P0=0xAA;P1=0x55;P3=0x55;delay(N);}}void Display_Ten(void) {unsigned char i;for(i=0;i<8;i++){P0=0x7E;P1=0x7E;P2=0x7E;P3=0x7E;delay(N);P0=0xBD;P1=0xBD;P2=0xBD;P3=0xBD;delay(N);P0=0xDB;P1=0xDB;P2=0xDB;P3=0xDB;delay(N);P0=0xE7;P1=0xE7;P2=0xE7;P3=0xE7;delay(N);P0=0xDB;P1=0xDB;P2=0xDB;P3=0xDB;delay(N);P0=0xBD;P1=0xBD;P2=0xBD;P3=0xBD;delay(N);P0=0x7E;P1=0x7E;P2=0x7E;delay(N);}P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;}void Display_Twelve(void){unsigned char i;unsigned char temp1;temp1=0x7F;for(i=0;i<8;i++){P0=temp1;delay(N);temp1=(temp1>>1);}delay(N);temp1=0x80;for(i=0;i<8;i++){P0=temp1;delay(N);temp1=((temp1>>1)|0x80);}delay(N+N);temp1=0xFE;for(i=0;i<8;i++){P1=temp1;delay(N);temp1=(temp1<<1);}delay(N);temp1=0x01;for(i=0;i<8;i++){P1=temp1;delay(N);temp1=((temp1<<1)|0x01);}delay(N+N);P1=0xFF;temp1=0xFE;for(i=0;i<8;i++){P2=temp1;delay(N);temp1=(temp1<<1);}delay(N);temp1=0x01;for(i=0;i<8;i++){P2=temp1;delay(N);temp1=((temp1<<1)|0x01);}P2=0xFF;delay(N+N);temp1=0xFE;for(i=0;i<8;i++){P3=temp1;delay(N);temp1=(temp1<<1);}delay(N);temp1=0x01;for(i=0;i<8;i++){P3=temp1;delay(N);temp1=((temp1<<1)|0x01);}delay(N+N);P3=0xFF;}void main(void){// unsigned char i;// unsigned char LED_temp;while(1){Display_One();delay(N+N+N);Display_Two();delay(N+N+N);Display_Three();delay(N+N+N);Display_Four();delay(N+N+N);Display_Five();delay(N+N+N);Display_Six();delay(N+N+N);Display_Seven();delay(N+N+N);Display_Eight();delay(N+N+N);Display_Nine();delay(N+N+N);Display_Ten();delay(N+N+N); //Display_Twelve();delay(N+N+N);}}。
单片机c语言编程控制流水灯
说了这么多了,相信你也看了很多资料了,手头应该也有必备的工具了吧!(不要忘了上面讲过几个条件的哦)。
那个单片机究竟有什么功能和作用呢?先不要着急!接下来让我们点亮一个LED(搞电子的应该知道LED是什么吧^_^)我们在单片机最小系统上接个LED,看我们能否点亮它!对了,上面也有好几次提到过单片机最小系统了,所谓单片机最小系统就是在单片机上接上最少的外围电路元件让单片机工作。
一般只须连接晶体、VCC、GND、RST即可,一般情况下,AT89C51的31脚须接高电平。
#include<reg51.h> //头文件定义。
或用#include<at89x51.h>其具体的区别在于:后者定义了更多的地址空间。
//在Keil安装文件夹中,找到相应的文件,比较一下便知!sbit P1_0 = P1 ^ 0; //定义管脚void main (void){while(1){P1_0 = 0;//低电平有效,如果把LED反过来接那么就是高电平有效}}就那么简单,我们就把接在单片机P1_0上的LED点亮了,当然LED是低电平,才能点亮。
因为我们把LED的正通过电阻接至VCC。
P1_0 = 0; 类似与C语言中的赋值语句,即把0 赋给单片机的P1_0引脚,让它输出相应的电平。
那么这样就能达到了我们预先的要求了。
while(1)语句只是让单片机工作在死循环状态,即一直输出低电平。
如果我们要试着点亮其他的LED,也类似上述语句。
这里就不再讲了。
点亮了几个LED后,是不是让我们联想到了繁华的街区上流动的彩灯。
我们是不是也可以让几个LED依次按顺序亮呢?答案是肯定的!其实显示的原理很简单,就是让一个LED灭后,另一个立即亮,依次轮流下去。
假设我们有8个LED分别接在P1口的8个引脚上。
硬件连接,在P1_1--P1_7上再接7个LED即可。
例程如下:#include<reg51.h>sbit P1_0 = P1 ^ 0;sbit P1_1 = P1 ^ 1;sbit P1_2 = P1 ^ 2;sbit P1_3 = P1 ^ 3;sbit P1_4 = P1 ^ 4;sbit P1_5 = P1 ^ 5;sbit P1_6 = P1 ^ 6;sbit P1_7 = P1 ^ 7;void Delay(unsigned char a){unsigned char i;while( --a != 0){for(i = 0; i < 125; i++); //一个; 表示空语句,CPU空转。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基于单片机心形流水灯C语言源程序精编Document number:WTT-LKK-GBB-08921-EIGG-22986#include<>unsigned int x,y;void delayms(unsigned int z) //延时{unsigned int i,j;for(i=z;i>0;i--)for(j=150;j>0;j--);}void On_all() //开启所有灯{P0=0x00; P1=0x00; P2=0x00; P3=0x00; }void Off_all()//关闭所有灯{P0=0xff; P1=0xff; P2=0xff; P3=0xff; }void ls()//正向流水灯{P0=0x00; delayms(400);P2=0x00; delayms(400);P3=0x00; delayms(400);P1=0x00; delayms(400);P0=0x01; delayms(50);P0=0x02; delayms(50);P0=0x04; delayms(50);P0=0x08; delayms(50);P0=0x10; delayms(50);P0=0x20; delayms(50);P0=0x40; delayms(50);P0=0x80; delayms(50);P0=0x00;P2=0x01; delayms(50);P2=0x04; delayms(50); P2=0x08; delayms(50);P2=0x10; delayms(50); P2=0x20; delayms(50);P2=0x40; delayms(50); P2=0x80; delayms(50);P2=0x00;P3=0x80; delayms(50);P3=0x40; delayms(50); P3=0x20; delayms(50);P3=0x10; delayms(50);P3=0x08; delayms(50); P3=0x04; delayms(50);P3=0x02; delayms(50); P3=0x01; delayms(50); P3=0x00;P1=0x80; delayms(50);P1=0x40; delayms(50);P1=0x20; delayms(50); P1=0x10; delayms(50);P1=0x08; delayms(50); P1=0x04; delayms(50);P1=0x02; delayms(50); P1=0x01; delayms(50); P1=0x00;Off_all();P0=0xfe; delayms(50);P0=0xfd; delayms(50);P0=0xfb; delayms(50); P0=0xf7; delayms(50); P0=0xef; delayms(50); P0=0xdf; delayms(50);P0=0x7f; delayms(50);P0=0xff;P2=0xfe; delayms(50);P2=0xfd; delayms(50);P2=0xfb; delayms(50);P2=0xf7; delayms(50);P2=0xef; delayms(50);P2=0xdf; delayms(50);P2=0xbf; delayms(50);P2=0x7f; delayms(50); P2=0xff;P3=0x7f; delayms(50);P3=0xbf; delayms(50);P3=0xdf; delayms(50);P3=0xef; delayms(50);P3=0xf7; delayms(50);P3=0xfb; delayms(50);P3=0xfd; delayms(50);P3=0xfe; delayms(50);P3=0xff;P1=0x7f; delayms(50);P1=0xbf; delayms(50);P1=0xdf; delayms(50);P1=0xef; delayms(50);P1=0xf7; delayms(50);P1=0xfb; delayms(50);P1=0xfd; delayms(50);P1=0xfe; delayms(50);P1=0xff;P0=0xfe; delayms(50);P0=0xfc; delayms(50);P0=0xf8; delayms(50);P0=0xf0; delayms(50);P0=0xe0; delayms(50);P0=0xc0; delayms(50);P0=0x80; delayms(50);P0=0x00; delayms(50);P2=0xfe; delayms(50);P2=0xfc; delayms(50);P2=0xf8; delayms(50);P2=0xf0; delayms(50);P2=0xe0; delayms(50);P2=0xc0; delayms(50);P2=0x80; delayms(50);P2=0x00; delayms(50);P3=0x7f; delayms(50);P3=0x3f; delayms(50);P3=0x1f; delayms(50);P3=0x0f; delayms(50);P3=0x07; delayms(50);P3=0x03; delayms(50);P3=0x01; delayms(50);P3=0x00; delayms(50);P1=0x7f; delayms(50);P1=0x3f; delayms(50);P1=0x1f; delayms(50);P1=0x0f; delayms(50);P1=0x07; delayms(50);P1=0x03; delayms(50);P1=0x01; delayms(50);P1=0x00; delayms(50);}void fan_ls()//反向流水灯{Off_all(); delayms(300);On_all(); delayms(300); Off_all(); delayms(300); P1=0x00;delayms(400);P3=0x00;delayms(400);P2=0x00;delayms(400);P0=0x00;delayms(400); P1=0x01;delayms(50);P1=0x02;delayms(50);P1=0x04;delayms(50);P1=0x08;delayms(50);P1=0x10;delayms(50);P1=0x20;delayms(50);P1=0x40;delayms(50);P1=0x80;delayms(50);P1=0x00;P3=0x01;delayms(50);P3=0x02;delayms(50);P3=0x04;delayms(50);P3=0x08;delayms(50);P3=0x10;delayms(50);P3=0x20;delayms(50);P3=0x40;delayms(50);P3=0x80;delayms(50);P3=0x00;P2=0x80;delayms(50);P2=0x40;delayms(50);P2=0x20;delayms(50);P2=0x10;delayms(50);P2=0x08;delayms(50);P2=0x04;delayms(50);P2=0x02;delayms(50);P2=0x01;delayms(50);P2=0x00;P0=0x80;delayms(50);P0=0x40;delayms(50);P0=0x20;delayms(50);P0=0x10;delayms(50);P0=0x08;delayms(50);P0=0x04;delayms(50); P0=0x02;delayms(50);P0=0x01;delayms(50);P0=0x00;Off_all();P1=0xfe; delayms(50);P1=0xfd; delayms(50);P1=0xfb; delayms(50); P1=0xf7; delayms(50); P1=0xef; delayms(50); P1=0xdf; delayms(50); P1=0xbf; delayms(50); P1=0x7f; delayms(50);P1=0xff;P3=0xfe; delayms(50);P3=0xfd; delayms(50);P3=0xfb; delayms(50); P3=0xf7; delayms(50); P3=0xef; delayms(50); P3=0xdf; delayms(50); P3=0xbf; delayms(50); P3=0x7f; delayms(50);P3=0xff;P2=0x7f; delayms(50);P2=0xbf; delayms(50); P2=0xdf; delayms(50);P2=0xef; delayms(50); P2=0xf7; delayms(50);P2=0xfb; delayms(50); P2=0xfd; delayms(50); P2=0xfe; delayms(50);P2=0xff;P0=0x7f; delayms(50);P0=0xbf; delayms(50);P0=0xdf; delayms(50);P0=0xef; delayms(50);P0=0xf7; delayms(50);P0=0xfb; delayms(50); P0=0xfd; delayms(50); P0=0xfe; delayms(50);P0=0xff;P1=0xfe; delayms(50);P1=0xfc; delayms(50);P1=0xf8; delayms(50);P1=0xf0; delayms(50);P1=0xe0; delayms(50);P1=0xc0; delayms(50); P1=0x80; delayms(50); P1=0x00; delayms(50);P3=0xfe; delayms(50);P3=0xfc; delayms(50);P3=0xf8; delayms(50);P3=0xf0; delayms(50);P3=0xe0; delayms(50);P3=0xc0; delayms(50); P3=0x80; delayms(50); P3=0x00; delayms(50);P2=0x7f; delayms(50);P2=0x3f; delayms(50);P2=0x1f; delayms(50);P2=0x0f; delayms(50);P2=0x07; delayms(50);P2=0x03; delayms(50);P2=0x01; delayms(50);P2=0x00; delayms(50);P0=0x7f; delayms(50);P0=0x3f; delayms(50);P0=0x1f; delayms(50);P0=0x0f; delayms(50);P0=0x07; delayms(50);P0=0x03; delayms(50);P0=0x01; delayms(50);P0=0x00; delayms(50);Off_all();On_all();Off_all();On_all();Off_all();}void ban_shan()//半边交替闪{Off_all();P1=0x00;P3=0x00;delayms(50);P0=0xff;P2=0xff;d elayms(50);P1=0xff;P3=0xff;delayms(50);P0=0x00;P2=0x00;d elayms(50);P1=0x00;P3=0x00;delayms(50);P0=0xff;P2=0xff;d elayms(50);P1=0xff;P3=0xff;delayms(50);P0=0x00;P2=0x00;d elayms(50);P1=0x00;P3=0x00;delayms(50);P0=0xff;P2=0xff;d elayms(50);P1=0xff;P3=0xff;delayms(50);P0=0x00;P2=0x00;d elayms(50);P1=0x00;P3=0x00;delayms(50);P0=0xff;P2=0xff;d elayms(50);P1=0xff;P3=0xff;delayms(50);P0=0x00;P2=0x00;d elayms(50);P1=0x00;P3=0x00;delayms(50);P0=0xff;P2=0xff;d elayms(50);P1=0xff;P3=0xff;delayms(50);P0=0x00;P2=0x00;d elayms(50);}void shangxia_shan()//上下交替闪{On_all();Off_all();P0=0x00;P1=0x00;delayms(50);P2=0xff;P3=0xff;d elayms(50);P0=0xff;P1=0xff;delayms(50);P2=0x00;P3=0x00;d elayms(50);P0=0x00;P1=0x00;delayms(50);P2=0xff;P3=0xff;d elayms(50);P0=0xff;P1=0xff;delayms(50);P2=0x00;P3=0x00;d elayms(50);P0=0x00;P1=0x00;delayms(50);P2=0xff;P3=0xff;d elayms(50);P0=0xff;P1=0xff;delayms(50);P2=0x00;P3=0x00;d elayms(50);P0=0x00;P1=0x00;delayms(50);P2=0xff;P3=0xff;d elayms(50);P0=0xff;P1=0xff;delayms(50);P2=0x00;P3=0x00;d elayms(50);P0=0x00;P1=0x00;delayms(50);P2=0xff;P3=0xff;d elayms(50);P0=0xff;P1=0xff;delayms(50);P2=0x00;P3=0x00;d elayms(50);}void huayang_shan()//花样闪烁{On_all();delayms(400);P0=0xff;P2=0x00;P3=0x00;P1=0x00;delayms(200);P0=0x00;P2=0xff;P3=0x00;P1=0x00;delayms(200);P0=0x00;P2=0x00;P3=0xff;P1=0x00;delayms(200);P0=0x00;P2=0x00;P3=0x00;P1=0xff;delayms(200);P0=0x00;P2=0x00;P3=0xff;P1=0x00;delayms(200);P0=0x00;P2=0xff;P3=0x00;P1=0x00;delayms(200);P0=0xff;P2=0x00;P3=0x00;P1=0x00;delayms(200);On_all();delayms(400);P0=0x00;P2=0x00;P3=0x00;P1=0xff;delayms(200);P0=0x00;P2=0x00;P3=0xff;P1=0x00;delayms(200);P0=0x00;P2=0xff;P3=0x00;P1=0x00;delayms(200);P0=0xff;P2=0x00;P3=0x00;P1=0x00;delayms(200);P0=0x00;P2=0xff;P3=0x00;P1=0x00;delayms(200);P0=0x00;P2=0x00;P3=0xff;P1=0x00;delayms(200);P0=0x00;P2=0x00;P3=0x00;P1=0xff;delayms(200);On_all();delayms(400);Off_all();delayms(400);P0=0x00;delayms(200);P3=0x00;delayms(200);P1=0x00;delayms(200);P2=0x00;delayms(200);On_all();delayms(400);Off_all();delayms(400);P1=0x00;delayms(200);P2=0x00;delayms(200);P0=0x00;delayms(200);P3=0x00;delayms(200);On_all();delayms(400);Off_all();delayms(50);On_all();delayms(50);Off_all();delayms(50);On_all();delayms(50);Off_all();delayms(50);}void main(){On_all(); delayms(300);Off_all(); delayms(300);On_all(); delayms(300);Off_all(); delayms(300);On_all(); delayms(300);Off_all(); delayms(300);ls(); //正向流水fan_ls(); //反向流水ban_shan(); //半边交替闪shangxia_shan(); //上下交替闪烁huayang_shan();// 花样闪烁}。