/*
功能:8个LED,轮流显示1-2-3-4-5------F,然后一轮回来之后,再次显示1-2-3-4------F
时间:2011-9-30
作者:cos_sin_tan
*/
#include<stdio.h>
#include<reg52.h>
char pianxuan_num[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//相当于片选信号呢
char xianshi[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,//0--7
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e// 8--F
};
//共阳极编码
/*
单片机LED共阳极段码表【0-F】
DB 0c0H,0f9H,0a4H,0b0H,99H,92H,82H,0f8H [0-7]
DB 80H,90H,88H,83H,0c6H,0a1H,86H,8eH [8-F]
*/
/*
3f,06,5b,4f (0-3)
66,6d,7d,07 (4-7)
7f,6f,77,7c (8-A)
39,5e,79,71 (b-f)
单片机LED共阴极段码表【0-F】
DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H [0-7]
DB 7FH,6FH ,77H,7CH,39H,5EH,79H,71H,76H [8-F]
*/
void delay(int count)
{
int y = 45555;
for(;count >0 ;count --)
for(;y > 0 ;y--)
;
}
void main(void )
{
int num = 0;
int i=0 ;
while(1)
{
for( ;i <16;i++)
{
P0 = xianshi[i];
P2 = pianxuan_num[i%8];
delay(4444);
delay(4444);
delay(4444);
if(i == 15)
i = -1; //注意这个呢,嘿嘿
}
}
}