52单片机用C语言编程 要求:用中断间隔让八个小灯以一秒间隔闪烁五次,然后全亮2秒,循环。
#include
#defineucharunsignedchar
#defineuintunsignedint
voiddelay(uinta)
uchari;
while(a--)for(i=0;i<120;i++);
main()
uinti;
while(1)
for(i=0;i<5;i++)
P0=0x00;
delay(1000);
P0=0xff;
dela(1000);
P0=0x00;
delay(2000);
求一个51单片机的C语言程序,8个LED4种亮法,自上而下,自下而上,高低4位交替亮,一个个灭直到全灭。
我给你做个例子吧,把接LED灯的io口赋值0,灯亮;把接LED灯的io口赋值1,灯灭因为一般接io口的LED灯有个上拉高电平,io这端给他个低电平(0),造成电压差,就有电流通过,灯就亮了;反之,io给高电平(1),没有压差,无电流,灯灭。下面的你自己应该可以写了,锻炼下手。void delay(void)int i=10000; //这个值调整亮灯灭等快慢,越小越快越大越慢while(i--)return;//从上到下亮灯void LED_a(void)LED_IO1 = 0;delay();LED_IO2 = 0;delay();LED_IO3 = 0;delay();LED_IO4 = 0;delay();LED_IO5 = 0;delay();LED_IO6= 0;delay();LED_IO7= 0;delay();LED_IO8= 0;delay();void LED_dengmie(void)LED_IO1 = 1;LED_IO2 = 1;LED_IO3 = 1;LED_IO4 = 1;LED_IO5 = 1;LED_IO6= 1;LED_IO7= 1;LED_IO8= 1;LED_dengmie();LED_a();#include unsigned char P1;void delay05s(void)unsignedchar i,j,k;for(i=50;i>0;i--)for(j=20;j>0;j--)for(k=248;k>0;k--);void main(void)while(1)P1=0xfe;delay05s();P1=0xfd;delay05s();P1=0xfb;delay05s();P1=0xf7;delay05s();P1=0xf7;delay05s();P1=0xfb;delay05s();P1=0xfd;delay05s();P1=0xfe;delay05s();P1=0xfC;delay05s();P1=0xf3;delay05s();P1=0xf0;delay05s();P1=0xf1;delay05s();P1=0xf3;delay05s();P1=0xf7;delay05s();P1=0xff;delay05s();#include#define uchar unsigned charuchar led;void delay()uchar i,j;for(i=0;i<100;i++)for(j=0;j<125;j++);uchar i;while(1)led=0xfe;i=8;while(i--)P0=led;delay();led<<=1;led|=0x01;i=8;led=0x7f;while(i--)P0=led;delay();led>>=1;led|=0x80;i=8;led=0x0f;while(i--)P0=led;delay();led>>~led;i=8;led=0x00;P0=led;delay();while(i--)led|=0x80P0=led;delay();led>>=1;