#include
#define uchar unsigned char
#define uint unsigned int
#define wei4_en {DDRB|=(1<<7); PORTB|=(1<<7);}
#define wei4_dis {DDRB|=(1<<7); PORTB&=~(1<<7);}
#define wei3_en {DDRB|=(1<<6); PORTB=(1<<6);}
#define wei3_dis {DDRB|=(1<<6); PORTB&=~(1<<6);}
#define wei2_en {DDRB|=(1<<5); PORTB|=(1<<5);}
#define wei2_dis {DDRB|=(1<<5); PORTB&=~(1<<5);}
#define wei1_en {DDRB|=(1<<4); PORTB|=(1<<4);}
#define wei1_dis {DDRB|=(1<<4); PORTB&=~(1<<4);}
#define t4 0x80
#define t3 0x40
#define t2 0x20
#define t1 0x10
//#define wei1 {DDRB=t4; PORTB=t4;}
//#define wei2 {DDRB=t3; PORTB=t3;}
//#define wei3 {DDRB=t2; PORTB=t2;}
//#define wei4 {DDRB=t1; PORTB=t1;}
//uchar wei[]={0x80,0x40,0x20,0x10};
//uchar buffer3,buffer2,buffer1,buffer0;
uint buffer3=0x00;
uint buffer2=0x00;
uint buffer1=0x00;
uint buffer0=0x00;
const unsigned int tt[]={0x3F,0x06,0x5B,0x4F,0x66, //0,1,2,3,4
0x6D,0x7D,0x07,0x7F,0x6F,0X00}; //5,6,7,8,9
void HC_595_OUT(unsigned int data)
{
DDRC |= (1<<7);//OE=7,OE_DDR=DDRC
PORTC &= (1<<7);//OE_PORT=PORTC
PORTB = 0x0f;
DDRB |= (1<<2)|(1<<1)|(1<<0);//设置MOSI,SCK输出
SPCR = (1<
PORTB|=(1<<0);
/* 启动数据传输 */
SPDR = data;
/* 等待传输结束 */
while(!(SPSR & (1< PORTB&=~(1<<0);
//PORTB=0X70;
}
void display(uint tmp)
{
//uint buffer;
//百位数码管显示
buffer0=tt[tmp%1000/100];
HC_595_OUT(buffer0);
//PORTB&=~(1<<4);
wei1_en;
delay1(60);
wei1_dis;
//十位数码管显示
buffer2=tt[tmp%100/10];
HC_595_OUT(buffer2);
wei3_en;;
delay1(60);
wei3_dis;
//千位数码管显示
buffer1=tt[tmp/1000];
HC_595_OUT(buffer1);
wei2_en;
// PORTB&=~(1<<5);
delay1(60);
wei2_dis;
//个位数码管显示
buffer3=tt[tmp%10];
HC_595_OUT(buffer3);
wei4_en;
//PORTB&=~(1<<7);
delay1(60);
wei4_dis;
}
void delay( unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=1140;y>0;y--);
}
void delay1(unsigned int z)
{
while(z--);
}
void main()
{
unsigned int cnt;
while(1)
{
display(5678);
}
}
阅读(2281) | 评论(0) | 转发(0) |