初级会员
- 积分
- 160
- 金钱
- 160
- 注册时间
- 2016-4-2
- 在线时间
- 33 小时
|
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//74HC164
sbit CLK=P1^0; // μíμçÆ½μ½¸ßμçƽ±ßÑØ′¥·¢
sbit MOSI=P1^1; // êy¾Yêäèë
unsigned char code Tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; //12òõêyÂë1ü
unsigned char DS_data[6];
/*****************************************************
oˉêy1|Äü:êyÂë1üé¨ÃèÑóê±×óoˉêy
oˉêy1|Äü:Ñóê±1ms
***************************************************/
void delay1ms()
{
unsigned char i,j;
for(i=0;i<10;i++)
for(j=0;j<33;j++)
;
}
void separateData(unsigned long dat) // datÎa6λêy
{
DS_data[0]=dat%10;
DS_data[1]=dat/10%10;
DS_data[2]=dat/100%10;
DS_data[3]=dat/1000%10;
DS_data[4]=dat/10000%10;
DS_data[5]=dat/100000%10;
}
void write_164(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
CLK=0;
if(dat&0x80) MOSI=1;
else MOSI=0;
CLK=1;
dat<<=1;
}
}
void display()
{
unsigned char i;
for(i=0;i<6;i++)
{
write_164(Tab[DS_data[i]]);
P2=0x3f&(~(0x01<<i)); //êyÂë1üλ 12òõμíμçƽѡÖDseg1¶Ôó|P2.5 seg6¶Ôó|P2.0
delay1ms();
P2=0xff; //êyÂë1üÃe
}
}
main()
{
separateData(654321);
while(1)
{
display();
}
}
|
|