如何改变小灯亮度
#include<reg52.h>#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P3^2;
sbit wela=P3^3;
sbit wr=P3^6;
sbit rd=P3^7;
sbit led=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void delay(uint z);
void display(uchar shi,uchar ge)
{
P0=0xff;
wela=1;
wela=0;
P0=table[shi];
dula=1;
// P0=table[shi];
dula=0;
// P0=0xff;
P0=0x0d;
wela=1;
// P0=0x7d;
wela=0;
delay(5);
P0=0xff;
wela=1;
wela=0;
P0=table[ge];
dula=1;
// P0=table[ge];
dula=0;
// P0=0xff;
P0=0x0b;
wela=1;
// P0=0x7b;
wela=0;
delay(5);
}
void main()
{
uchar a,b,shi,ge,adval;
wela=1;
P0=0xff;
wela=0;
// b=2999/1000;
b=259/10;
while(1)
{
wr=1;
_nop_();
wr=0;
_nop_();
wr=1;
for(a=10;a>0;a--)
{
display(shi,ge);
}
P1=0xff;
rd=1;
_nop_();
rd=0;
_nop_();
adval=P1;
rd=1;
/* bai=adval/b;
shi=bai/10;
ge=bai%10; */
shi=adval/b;
ge=adval%b/10;
if(adval>200)
{
led=0;
}
else
led=1;
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}