電路原理圖如下:
捕11獲.PNG (46.58 KB, 下載次數(shù): 33)
下載附件
2018-8-19 18:14 上傳
程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
/******************0****1****2****3****4****5****6****7****8****9****/
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共陽(yáng)極
sbit HC595SH =P1^1; //數(shù)據(jù)輸入時(shí)鐘線
sbit HC595ST =P1^2; //輸出存儲(chǔ)器鎖存時(shí)鐘線
sbit HC595Data=P1^0; //串行數(shù)據(jù)輸入
uchar ge,shi,bai,qian;
void HC595SendByte(uchar c)
{
uchar i,num;
num=tab[c];
for(i=0;i<8;i++)
{
HC595SH=0;
// if((num&0x80)==0x80)
if((num&0x80))
HC595Data=1;
else
HC595Data=0;
HC595SH=1;
}
}
void Display(uint number)
{
uint ge,shi,bai,qian;
ge=number%10;
shi=number%100/10;
bai=number%1000/100;
qian=number/1000;
HC595ST=1;
HC595SendByte(ge);
HC595SendByte(shi);
HC595SendByte(bai);
HC595SendByte(qian);
HC595ST=0;
}
void delay(uint a)
{
while(a--);
}
void main()
{
uint b;
while(1)
{
Display(b);
delay(10000);
b+=1;
if(b==9999)b=0;
// while(1);
}
}
|