|
mega128 HC595 驱动四位一体数码管
[复制链接]
这是我的程序#include
#define SS 0
#define SCK 1
#define MOSI 2
#define MISO 3
#define OE 7
#define SS_H() PORTB|=(1<
#define SS_L() PORTB&=~(1<
#define CLR_BIT(x,y) x&=~(1<
unsigned int i;
unsigned char Seg7_Data[]={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00};
void delay_1us(void) //1us延时函数
{
asm("nop");
}
void delay_nus(unsigned int n) //N us延时函数
{
unsigned int i=0;
for (i=0;i
delay_1us();
}
void delay_1ms(void) //1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延时函数
{
unsigned int i=0;
for (i=0;i
delay_1ms();
}
void SPI_MasterTransmit(unsigned char Data)
{
SPDR=Data;
while(!(SPSR&(1<
//CLR_BIT(SPSR,SPIF);
}
/*void HC_595_Init()
{
unsigned char data;
for(data=0;data<18;data++)
{
SS_L();
SPI_MasterTransmit(Seg7_Data[data]);
SS_H();
}
delay(1000);
}*/
void main()
{
int i;
while(1)
{
for(i=0;i<17;i++)
{
DDRC|=(1<
PORTC&=~(1<
DDRB=0xff;
PORTB|=0xff;
DDRB|=(1<
SPCR|=(1<
SS_L();
//delay_1us();
SPI_MasterTransmit(Seg7_Data);
//delay_nus(10);
SS_H();
//delay_nus(10);
delay_nms(1000);
}
}
}
这是原理图的地址,请大家帮帮忙啊
|
|