#include
#define uchar unsigned char
#define uint unsigned int
uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Da
void DelayMs(uint i)
{uchar j;
for(;i!=0;i--)
{for(j=2000;j!=0;j--) {;}}
}
void Display(uchar *p)
{uchar i,sel=0x01;
for(i=0;i<4;i++)
{PORTA=sel;
PORTC=0xff-Table[p[i]];
DelayMs(10);
sel=sel<<1;
}
}
void DelayNOP(uchar i)
{for(;i!=0;i--)
{ NOP();}
}
void Convert(uchar *p,uchar i)
{p[0]=0;
p[1]=i/100;
p[2]=(i-p[1]*100)/10;
p[3]=i-p[1]*100-p[2]*10;
}
void Write_Byte(uchar Address,uchar Da
{uchar clear;
PORTB=PORTB|0x10; //使能SPI器件
SPDR=Address;
while(!(SPSR&0x80)) {;}
clear=SPSR;
clear=SPDR;
SPDR=Da
while(!(SPSR&0x80)) {;}
clear=SPSR;
clear=SPDR;
PORTB=PORTB&0xef;
}
uchar Read_Byte(uchar Address)
{uchar clear;
uchar Da
PORTB=PORTB|0x10;
SPDR=Address;
while(!(SPSR&0x80)) {;}
clear=SPSR;
clear=SPDR;
SPDR=Address;//发空数据
while(!(SPSR&0x80)) {;}
clear=SPSR;
Da
PORTB=PORTB&0xef;
return(Da
}
void main(void)
{uchar value;
DDRA=0xff;
DDRC=0xff;
DDRB=0xbf;
PORTA=0xff;
PORTC=0x00;
DelayMs(3000);
PORTC=0xff;
SPCR=0x5c;//0101 1100
Write_Byte(0x80,0xf0);//8位,自由转换模式
while(1)
{value=Read_Byte(0x01);
value=Read_Byte(0x02);
Convert(Da
Display(Da
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』