#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=120;t>0;t--);
}
}
void main()
{
uchar k,m=0x40;
P0=0xff;
P2=0x00;
while(1)
{
for(k=0;k<4;k++)
{
m=_crol_(m,1);
P2=~m;
P0=DSY_CODE[k+1];
DelayMS(2);
}
}
}
#include "reg51.h"
#include "intrins.h"
#include "math.h"
unsigned char code data_led[17]= {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};
//{ 0, 1, 2,3,4,5,6,7,8,9,A,b,C,d,E,F,-}; 数码管显示段码
// sbit wd=P3^6;
void delay(unsigned char i)
{
while(i--);
}
unsigned char kzw[]={0xFE,0xFD,0xFB,0xF7}; //位码
void main()
{
unsigned char i;
while(1)
{
for(i=1;i<=3;i++)
{
P2=kzw[i];
P1=data_led[i];
delay(800);
P1=0xff;
}
// wd=0;
}
}
这是显示1213的程序,自己改改就行了。注意IO口
刷新率太快了,把时间放慢一些,一个显示循环的时间不超过1/50秒就可以了 这个也是转载来的 很不错哦,你可以试下的 呵呵