您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 单片机流水灯所有程序
#include<reg52.h>#defineucharunsignedchar//charÊÇ×Ö·ûÊý×é#defineunitunsignedintucharnum;sbitled1=P1^0;voidmain(){TMOD=0x01;//´ò¿ª¹¤×÷·½Ê½¼Ä´æÆ÷£¬Ñ¡Ôñ¹¤×÷·½Ê½1£¨00000001£©TH0=(65536-45872)/256;TL0=(65536-45872)%256;EA=1;//¿ª×ÜÖжÏET0=1;//¿ª¶¨Ê±Æ÷0ÖжÏTR0=1;//Æô¶¯¶¨Ê±Æ÷0while(1);//³ÌÐòÍ£Ö¹ÔÚÕâÀïµÈ´ýÖжϷ¢Éú}voidT0_time()interrupt1{TH1=(65536-45872)/256;//×°³õÖµ50msTL1=(65536-45872)%256;num++;//numÿ¼ÓÒ»´ÎÅжÏÊÇ·ñµ½ÁË20´Îif(num==20)//20*50ms=1000ms=1s,¼ä¸ô1s{num=0;//È»ºó°ÑnumÇå0ÖØÐÂÔÙ¼Æ20´Îled1=~led1;//È÷¢¹â¹Ü״̬ȡ·´}}Óö¨Ê±Æ÷ʹ1µÆ¼ä¸ô1sÉÁ˸#include<reg52.h>#defineucharunsignedchar#defineunitunsignedintunitnum;#defineuchaunsignedchar#defineuniunsignedintunia;uchartable[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};//????uchatable1[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};voiddelayms(unit);voidmain(){while(1){for(num=0;num<8;num++)//????{P1=table[num];delayms(500);}for(a=8;a>0;a--)//¸Ä³Éfor£¨a=0;a>8;a++){P1=table1[a];delayms(500);}}}voiddelayms(unitxms){uniti,j;for(i=xms;i>0;i--)for(j=110;j>0;j--);}ûÓÐʵÏÖÀíÏëµÄÁ÷Ë®µÆ£¬ÎÊÌâÒѽâ¾ö£¬¼ûÏÂÃæ³ÌÐò#include<reg52.h>#defineucharunsignedchar#defineunitunsignedintunitnum;uchartable[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};voiddelayms(unit);voidmain(){while(1){for(num=0;num<9;num++){P1=table[num];delayms(500);}for(num=9;num>0;num--){P1=table[num];delayms(500);}}}voiddelayms(unitxms){uniti,j;for(i=xms;i>0;i--)for(j=110;j>0;j--);}ÓÃÊý×éʵÏÖÁ÷Ë®µÆÑ»·£¬ÒÀ´ÎµãÁÁ£¬È»ºóÒÀ´ÎϨÃð#include<reg52.h>#defineucharunsignedchar//charÊÇ×Ö·ûÊý×é#defineunitunsignedintunitnum;uchartable[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//¸Ä±äÊý×évoiddelayms(unit);voidmain(){while(1){for(num=0;num<8;num++)//forÑ»·{P1=table[num];delayms(500);}}}voiddelayms(unitxms){uniti,j;for(i=xms;i>0;i--)//ÑÓ³Ù0.5s£¬ÏÂÒ»µÆÁÁ//¼ÓforÓï¾äfor(j=110;j>0;j--);}ÓÃÊý×éʵÏÖÁ÷Ë®µÆ#include<reg52.h>#include<intrins.h>//°üº¬_crol_º¯ÊýËùÔÚµÄÍ·Îļþ#defineunitunsignedintuniti,j;#defineucharunsignedcharuchara;voiddelayms(unit);voidmain(){a=0xfe;//¸³¸øa³õÖµ0xfe£¬¼´11111110£¬µÚÒ»¸öµÆÁÁwhile(1){P1=a;delayms(500);a=_crol_(a,1);//Ñ»·×óÒÆÖ¸Áî»òa=a<<1;87654321µÆ}}voiddelayms(unitxms)//×Ô¶¨ÒåºÁÃëX{uniti,j;for(i=xms;i>0;i--)//ÑÓ³ÙXmsfor(j=110;j>0;j--);}ÓÃÑ»·×óÒÆÖ¸ÁîʵÏÖÁ÷Ë®µÆ#include<reg52.h>//Í·Îļþ#defineunitunsignedint//ºê¶¨Òåuniti,j;//¶¨Òåi;jvoiddelay1s();sbitled1=P1^0;//Á¬½Ó1µÆµÄÊÇËø´æÆ÷µÄP10¶Ë¿Úsbitled2=P1^1;sbitled3=P1^2;sbitled4=P1^3;sbitled5=P1^4;sbitled6=P1^5;sbitled7=P1^6;sbitled8=P1^7;voidmain(){while(1)//Ñ»·ÓÀ²»Í£Ö¹{led1=0;delay1s();//1µÆÁÁ1Sled1=1;led2=0;//1µÆÃ𣬶þµÆÁÁdelay1s();led2=1;led3=0;delay1s();led3=1;led4=0;delay1s();led4=1;led5=0;delay1s();led5=1;led6=0;delay1s();led6=1;led7=0;delay1s();led7=1;led8=0;delay1s();led8=1;led1=0;}}voiddelay1s(){uniti,j;//for(i=500;i>0;i--)//ÑÓ³Ù0.5s£¬ÏÂÒ»µÆÁÁfor(j=110;j>0;j--);}Á÷Ë®µÆ#include<reg52.h>#defineunitunsignedintuniti,j;voiddelay1s();sbitled=P1;sbitled1=P1^0;sbitled2=P1^1;sbitled3=P1^2;sbitled4=P1^3;sbitled5=P1^4;sbitled6=P1^5;sbitled7=P1^6;sbitled8=P1^7;voidmain(){while(1){led1=0;delay1s();led2=0;delay1s();led3=0;delay1s();led4=0;delay1s();led5=0;delay1s();led6=0;delay1s();led7=0;delay1s();led8=0;delay1s();led8=1;delay1s();led7=1;delay1s();led6=1;delay1s();led5=1;delay1s();led4=1;delay1s();led3=1;delay1s();led2=1;delay1s();led1=1;delay1s();P1=0;delay1s();P1=0xff;delay1s();}}voiddelay1s(){uniti,j;for(i=500;i>0;i--)for(j=110;j>0;j--);}ÒÀ´ÎµãÁÁ£¬Ò»ÁÁ¶þÁÁ----È«ÁÁ---ÒÀ´ÎϨÃð---È«Ãð------È«ÁÁ#include<reg52.h>#defineunitunsignedintuniti,j;voiddelay1s();sbitled=P1;sbitled1=P1^0;sbitled2=P1^1;sbitled3=P1^2;sbitled4=P1^3;sbitled5=P1^4;sbitled6=P1^5;sbitled7=P1^6;sbitled8=P1^7;voidmain(){while(1){led1=0;delay1s();//1µÆÁÁ1Sled1=1;led2=0;//1µÆÃ𣬶þµÆÁÁdelay1s();led2=1;led3=0;delay1s();led3=1;led4=0;delay1s();led4=1;led5=0;delay1s();led5=1;led6=0;delay1s();led6=1;led7=0;delay1s();led7=1;led8=0;delay1s();led8=1;P1=0;delay1s();P1=0xff;}}voiddelay1s(){uniti,j;for(i=500;i>0;i--)for(j=110;j>0;j--);}ÒÀ´ÎÁÁ£¬È«ÁÁ£¬È«Ãð£¬Ñ»·#include<reg52.h>#defineunitunsignedintuniti,j;voiddelay1s();sbitLED4=P1^3;sbitLED5=P1^4;sbitdula=P2^1;voidmain(){while(1){LED4=0;delay1s();LED4=1;LED5=0;delay1s();}}voiddelay1s(){uniti,j;for(i=500;i>0;i--)for(j=110;j>0;j--);}4ÉÁ5ÁÁ#include<reg52.h>sbitLED2=P1^1;sbitdula=P2^6;voidmain(){dula=1;LED2=0;dula=0;}¶þµÆÁÁ#include<reg52.h>sbitLED4=P1^3;sbitLED5=P1^4;sbitdula=P2^1;#defineunitunsignedintuniti,j;voidmain(){while(1){LED4=0;for(i=1000;i>0;i--)for(j=110;j>0;j--);LED4=1;LED5=0;for(i=1000;i>0;i--)for(j=110;j>0;j--);}dula=1;LED4=0;dula=0;}4ÉÁ5ÁÁ#include<reg52.h>#defineunitunsignedintsbitled1=P1^0;voiddelays(unit);voidmain(){while(1){led1=0;delay1s();led1=1;delay1s();}}voiddelay1s(){uniti,j;//ʹÓþֲ¿±äÁ¿¿É½ÚÔ¼µ¥Æ¬»úÄÚ´æfor(i=500;i>0;i--)for(j=110;j>0;j--);}#include<reg52.h>sbitled=P1^0;unsignedinta;voidmain()//Ö÷º¯Êý{while(1){a=51000;led=0;while(a--);led=1;a=51000;while(a--);}}ÓÃwhileº¯Êýʵ
本文标题:单片机流水灯所有程序
链接地址:https://www.777doc.com/doc-3174917 .html