这是我的程序#include<iom128v.h>
#define SS 0
#define SCK 1
#define MOSI 2
#define MISO 3
#define OE 7
#define SS_H() PORTB|=(1<<SS)
#define SS_L() PORTB&=~(1<<SS)
#define CLR_BIT(x,y) x&=~(1<<y)
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<n;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<n;i++)
delay_1ms();
}
void SPI_MasterTransmit(unsigned char Data)
{
SPDR=Data;
while(!(SPSR&(1<<SPIF)));
//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<<OE);
PORTC&=~(1<<OE);
DDRB=0xff;
PORTB|=0xff;
DDRB|=(1<<MOSI)|(1<<SCK)|(1<<SS)|(1<<MISO);
SPCR|=(1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<SPR1);
SS_L();
//delay_1us();
SPI_MasterTransmit(Seg7_Data
);
//delay_nus(10);
SS_H();
//delay_nus(10);
delay_nms(1000);
}
}
}
这是原理图的地址,请大家帮帮忙啊
此帖出自小平头技术问答
一周热门 更多>