#define OE_PORT PORTC
#define OE_PIN PINC
#define OE_DDR DDRC
#define OE 7
#define Seg7_Bit0 4
#define Seg7_Bit1 5
#define Seg7_Bit2 6
#define Seg7_Bit3 7
#define dp 7
#define Seg7_Bitselect_PORT PORTB
#define Seg7_Bitselect_PIN PINB
#define Seg7_Bitselect_DDR DDRB
#define Seg7_Bit0_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit0_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit1_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit1_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit2_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit2_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit3_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit3_Dis() {Seg7_Bitselect_DDR|=(1<#define SS 0
#define SCK 1
#define MOSI 2
#define MISO 3
#define SS_H() PORTB|=(1<#define SS_L() PORTB&=~(1<#include
const unsigned char duan[]={0x3F,0x06,0x5B,0x4F,0x66, //0,1,2,3,4
0x6D,0x7D,0x07,0x7F,0x6F}; //5,6,7,8,9
unsigned char buffer;
void spi_init()
{
DDRB |= (1< SPCR = (1<}
void SPI_MasterTransmit(char Data)
{
/* 启动数据传输 */
SPDR = Data;
/* 等待传输结束 */
while(!(SPSR & (1<}
void HC_595_init(void)
{
DDRC |= (1<<7); //DDRC7=1 output
PORTC &= (1<<7);//PORTC7=1 , 595 enable
PORTB = 0x0F;
//PORTB |=((1<<7)|(1<<6)|(1<<5)); //位选,高四位控制四个数码管,高电平有效
spi_init();
}
void HC_595_OUT(unsigned char data)
{
SS_L(); //PORTB0=0
SPI_MasterTransmit(data);
SS_H(); //PORTB0=1
}
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;
HC_595_init();
while(1)
{
for(cnt=0;cnt<10;cnt++)
{
Seg7_Bit0_En(); //PORTB4=1,选中最后一个数码管
buffer=duan[cnt];
HC_595_OUT(buffer);
delay(300);
//Seg7_Bit0_Dis();//PORTB4=0,关闭最后一个数码管
delay(300);
}
}
}
阅读(951) | 评论(0) | 转发(0) |