1.共阴极数码管实现HELLO
#include<reg51.h>
char str[]={0x76,0x79,0x38,0x38,0x3F}; //HELLO
char wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(int n)
{int i=0,j=0;for(i=0;i<n;i++){for(j=0;j<120;j++);}
}
void seg()
{int i;for(i=0;i<5;i++){P3=~wei[i]; //0011 1111P2=str[i];delay(5);}}
void main()
{while(1){seg(); }
}
2.共阴极数码管的动态显示(使用74s138译码器)
#include<reg51.h>
char str[]={0x76,0x79,0x38,0x38,0x3F}; //HELLO
char wei[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
void delay(int n)
{int i=0,j=0;for(i=0;i<n;i++){for(j=0;j<120;j++);}
}
void seg()
{int i;for(i=0;i<5;i++){P3=wei[i]; //0011 1111P2=str[i];delay(5);}}
void main()
{while(1){seg(); }
}
每天学一点点单片机,还要继续看C和linux,一起加油!