数码管不该亮度的段位,都有暗光,请问是什么原因?
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler miao:9
char num=0,fen=0,shi=0;
#pragma data:code
const SMG[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
const key[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void ld(uchar i,uchar j)
{
PORTB=0Xff;
PORTA|=BIT(1);
PORTB=SMG;
PORTA&=~BIT(1);
PORTB=0XFF;
PORTA|=BIT(4);
PORTB&=~BIT(j);
PORTA&=~BIT(4);
delay(3);
}
void lde(uchar i,uchar j)
{
PORTB=0Xff;
PORTA|=BIT(1);
PORTB=key;
PORTA&=~BIT(1);
PORTB=0XFF;
PORTA|=BIT(4);
PORTB&=~BIT(j);
PORTA&=~BIT(4);
delay(1);
}
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<1000;j++);
}
void miao()
{
if(num==59)
{
num=-1;
if(fen==59)
{
fen=-1;
if(shi==23)
{
shi=-1;
}
shi++;
}
fen++;
}
num++;
TCNT1H=0X48;
TCNT1L=0XE4;
}
void timer_init()
{
TCCR1B=0X04;
TCNT1H=0X48;
TCNT1L=0XE4;
TIMSK|=BIT(2);
SREG|=BIT(7);
}
void main()
{
DDRB=0XFF;
DDRA|=0X12;
timer_init();
while(1)
{
ld(shi/24,0);
ld(shi%24,1);
lde(6,2);
ld(fen/10,3);
ld(fen%10,4);
lde(6,5);
ld(num/10,6);
ld(num%10,7);
}
}
|