基于51單片機(jī)利用八個(gè)數(shù)碼管花樣顯示如下:
xxx11xxx→xx2222xx→x333333x→44444444→x555555x→xx6666xx→x777777x→88888888
每個(gè)狀態(tài)各一秒,顯示反復(fù)循環(huán),其中x表示對(duì)應(yīng)的數(shù)碼管熄滅
問題補(bǔ)充:是共陽極的數(shù)碼管,利用595芯片驅(qū)動(dòng)的。采用C語言。
===================================================
最佳答案:程序設(shè)計(jì)完畢,采用PROTEUS仿真截圖如下。
程序如下:
//=============================================
#include
#define uint unsigned int
#define uchar unsigned char
//HC595芯片
sbit H_ds = P2^0;
sbit H_shcp = P2^1;
sbit H_stcp = P2^2;
char code DISP_8[] = {
0x00, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f};
char code TAB_64[] = {
0,0,0,1,1,0,0,0, 0,0,2,2,2,2,0,0,
0,3,3,3,3,3,3,0, 4,4,4,4,4,4,4,4,
0,5,5,5,5,5,5,0, 0,0,6,6,6,6,0,0,
0,7,7,7,7,7,7,0, 8,8,8,8,8,8,8,8};
char i = 1, j = 0;
char DISP_B[] = {0,0,0,0,0,0,0,0};
//------------------------------------------------------------------
void sendbyte_H(uchar aa) //利用HC595輸出
{
char z;
aa = ~aa;
for(z = 0; z 《 8; z++) { //循環(huán)8次移入數(shù)據(jù)
H_shcp = 0;
H_ds = aa & 128; //數(shù)據(jù)位送到HC595數(shù)據(jù)線
H_shcp = 1; //上升沿輸入數(shù)據(jù)
aa 《《= 1;
}
}
//------------------------------------------------------------------
void display()
{
char z;
for(z = 0; z 《 8; z++) DISP_B[z] = TAB_64[j * 8 + z];
j++; j %= 8;
for(z = 0; z 《 8; z++) sendbyte_H(DISP_8[DISP_B[z]]);
H_stcp = 0; H_stcp = 1; //上升沿使數(shù)據(jù)并行輸出
}
//------------------------------------------------------------------
void main()
{
TMOD = 0x01;
TH0 = (65536 - 46080) / 256;//50ms@11.0592MHz
TL0 = (65536 - 46080) % 256;
TR0 = 1;
ET0 = 1;
EA = 1;
while (1);
}
//------------------------------------------------------------------
void T0_time()interrupt 1
{
TL0 = (65536 - 46080) % 256; //重新設(shè)置初始值
TH0 = (65536 - 46080) / 256;//50ms@11.0592MHz
i--;
if (i == 0) {
i = 40;
display(); //花樣顯示
}
}
//------------------------------------------------------------------
評(píng)論
查看更多