標(biāo)題:
單片機(jī)代碼下到板子上數(shù)碼管亮度低怎么辦?
[打印本頁(yè)]
作者:
沈洛000
時(shí)間:
2023-6-14 15:10
標(biāo)題:
單片機(jī)代碼下到板子上數(shù)碼管亮度低怎么辦?
這個(gè)代碼下到板子上數(shù)碼管亮度低怎么辦
單片機(jī)源程序如下:
#include <REGX52.H>
#define smg P0
typedef unsigned int U16;
sbit S18=P2^0;
sbit S19=P2^1;
sbit S20=P2^2;
void delay(U16 i)
{
while(i--);
}
int i;
void an()
{
if(S18==0)
{
delay(5);
if(S18==0)
{
i++;
if(i==9999)
{
i=0;
}
}
while(!S18);
}
if(S19==0)
{
delay(5);
if(S19==0)
{
i--;
if(i==0)
{
i=9999;
}
}
while(!S19);
}
if(S20==0)
{
delay(5);
if(S20==0)
{
i=0;
}
while(!S20);
}
}
void main()
{
int q,b,s,g;
int sz[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
i=0;
while(1)
{
an();
q=i/1000;
b=i%1000/100;
s=i%100/10;
g=i%10;
delay(5);
P0_0=1;
P0_1=1;
P0_2=1;
P0_3=1;
P0_0=0;
P1=sz[q];
P0_0=1;
P1=0xff;
delay(5);
P0_1=0;
P1=sz[b];
P0_1=1;
P1=0xff;
delay(5);
P0_2=0;
P1=sz[s];
P0_2=1;
P1=0xff;
delay(5);
P0_3=0;
P1=sz[g];
P0_3=1;
P1=0xff;
delay(5);
}
}
復(fù)制代碼
作者:
chxelc
時(shí)間:
2023-6-14 16:46
單片機(jī)IO驅(qū)動(dòng)能力不足,加三極管或MOS管驅(qū)動(dòng)。
作者:
xianfajushi
時(shí)間:
2023-6-14 16:48
調(diào)節(jié)數(shù)碼段顯示時(shí)間到合適
作者:
Hephaestus
時(shí)間:
2023-6-14 17:06
74行消隱和75行延遲顯然搞反了,下面一大堆類(lèi)似錯(cuò)誤。
正常流程是:
顯示
延遲
消隱(防止本段顯示數(shù)據(jù)漏到下一段,關(guān)閉顯示)
顯示下一個(gè)
延遲
消隱
…………
你剛剛顯示就關(guān)閉了,然后延遲,反復(fù)循環(huán),到底是幾個(gè)意思???
作者:
wulin
時(shí)間:
2023-6-14 20:46
數(shù)碼管顯示時(shí)間太短,消隱時(shí)間太長(zhǎng)。改一下。
#include <REG52.H>
#define smg P0
typedef unsigned int U16;
sbit S18=P2^0;
sbit S19=P2^1;
sbit S20=P2^2;
unsigned char sz[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char qbsg[4];
unsigned char i;
int num;
void delay(U16 i)
{
while(i--);
}
void an()
{
static unsigned char count=0;
static bit sign=0;
if(!S18||!S19||!S20)
{
if(++count>=20 && sign==0)
{
sign=1;
if(!S18)
{
num++;
if(num>9999)num=0;
}
if(!S19)
{
num--;
if(num<0)num=9999;
}
if(!S20)
{
num=0;
}
}
}
else
{
count=0;
sign=0;
}
}
void main()
{
while(1)
{
an();
qbsg[0]=sz[num/1000%10];
qbsg[1]=sz[num/100%10];
qbsg[2]=sz[num/10%10];
qbsg[3]=sz[num%10];
P1=0xff;
P0=0x01<<i;
P1=qbsg[i];
i=++i%4;
delay(100);
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1