https://static.assets-stash.eet-china.com/album/old-resources/2009/5/14/3233c19b-f256-48a5-aff2-c5bda5bd06ed.rar#include <reg51.h>
sbit CLK = P1^0;
sbit DI = P1^1;
sbit DO = P1^3;
sbit CS = P1^2;
unsigned int adval;
code unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0xff}; //共阳数码管段码
void delay1ms()
{
unsigned char i;
for(i=124;i>0;i--); //延时124*8+10=1002us
}
void LED_display(int date) //显示4位数
{
P2=0x01; //P1.0=0,选通第一位
P0=tab[date/1000]; //取出千位,查表,输出
delay1ms();
P0=0xff; //消隐
P2=0x02; //P1.1=0,选通第二位
P0=tab[date%1000/100];
delay1ms();
P0=0xff; //消隐
P2=0x04; //P1.3=0,选通第三位
P0=tab[date%100/10];
delay1ms();
P0=0xff; //消隐
P2=0x08; //P1.3=0,选通第四位
P0=tab[date%10];
delay1ms();
P0=0xff; //消隐
}
unsigned int ad ()
{
unsigned char i;
CS="0";
CLK="0";
CLK="1";
DI="1";
CLK="0";
CLK="1";
DI="1";
CLK="0";
CLK="1";
DI="0";
CLK="1";
CLK="0";
for (i=0;i<16;i++)
{
CLK="1";
CLK="0";
if (DO)
adval= (adval >>1)| 0x80;
else
adval=(adval>>1)|0x00;
}
CS="1";
return (adval);
}
void main ()
{
while (1)
{
ad ();
LED_display(adval) ;
}
}
文章评论(0条评论)
登录后参与讨论