#include<reg51.h>
//这边为了让你看的更容易,用的是单独操作,没有用总线
sbit led1 = P1^0;
sbit led2 = P1^1;
sbit led3 = P1^2;
sbit led4 = P1^3;
sbit led5 = P1^4;
sbit led6 = P1^5;
sbit led7 = P1^6;
//看清楚自己的管脚,不一定对应,这里采用P0对应段选
code unsigned char led_paly[5] = {0x76,0x79,0x38,0x38,0x5c};
// H E L L O
void delay(unsigned int um)//延时函数
{
int i,j;
for(i = 0;i < um;i++)
{
for(j = 0;j < 200;j++);
}
}
void display()
{
P0 = led_paly[0];//显示H
led2 = 0;
delay(50);
led2 = 1;
P0 = led_paly[1];//显示E
led3 = 0;
delay(50);
led3 = 1;
P0 = led_paly[2];//显示L
led4 = 0;
delay(50);
led4 = 1;
P0 = led_paly[3];//显示E
led5 = 0;
delay(50);
led5 = 1;
P0 = led_paly[4];//显示O
led6 = 0;
delay(50);
led6 = 1;
}
void main(void)
{
while(1)
{
display();
}
}
|