AVR数码管用74HC595显示问题
时间:10-02
整理:3721RD
点击:
我的开发板的数码管原理图是这样的
我的显示程序是这样的,但每次下载完程序或者上电后都不能正常显示0,要复位后才能正常显示,而下载开发板的例程则不会出现异常
#include<iom1280v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define uint32 unsigned long
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
volatile uint32 num;
void delay(uchar x)
{
uchar y;
uint z;
for(y=0;y<x;y++)
for(z=0;z<1141;z++);
}
void display(void)
{
uchar ge,shi,bai,qian;
ge=num%10;
shi=num%100/10;
bai=num%1000/100;
qian=num/1000;
SPSR=0;
SPDR=table[ge];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x01;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[shi];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x02;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[bai];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x04;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[qian];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x08;
delay(3);
PORTL=0;
}
void init(void)
{
SPCR=0x53;
DDRB|=0x0f;
PORTB=0x0f;
DDRK|=BIT(3);
DDRL|=0x0f;
num=0;
}
void main(void)
{
init();
while(1)
{
display();
}
}
我的显示程序是这样的,但每次下载完程序或者上电后都不能正常显示0,要复位后才能正常显示,而下载开发板的例程则不会出现异常
#include<iom1280v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define uint32 unsigned long
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
volatile uint32 num;
void delay(uchar x)
{
uchar y;
uint z;
for(y=0;y<x;y++)
for(z=0;z<1141;z++);
}
void display(void)
{
uchar ge,shi,bai,qian;
ge=num%10;
shi=num%100/10;
bai=num%1000/100;
qian=num/1000;
SPSR=0;
SPDR=table[ge];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x01;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[shi];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x02;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[bai];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x04;
delay(3);
PORTL=0;
SPSR=0;
SPDR=table[qian];
delay(2);
PORTK|=BIT(3);
delay(1);
PORTK&=~BIT(3);
PORTL=0x08;
delay(3);
PORTL=0;
}
void init(void)
{
SPCR=0x53;
DDRB|=0x0f;
PORTB=0x0f;
DDRK|=BIT(3);
DDRL|=0x0f;
num=0;
}
void main(void)
{
init();
while(1)
{
display();
}
}