|
SPI设置
在ICCAVR里面,我一般采用的是自动设置的方式,先选择M16单片机,然后选择好7.3824M的晶振,然后,我们进行配置:
然后选择SPI,进行配置
点击确认,则出现了一些程序,程序如下:
//ICC-AVR application builder : 2009-8-27 8:41:55
// Target : M16
// Crystal: 7.3728Mhz
#include
#include
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//SPI initialize
// clock rate: 57599hz
void spi_init(void)
{
SPCR = 0xFF; //setup SPI
SPSR = 0x00; //setup SPI
}
#pragma interrupt_handler spi_stc_isr:11
void spi_stc_isr(void)
{
//byte in SPDR has been sent/received
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
spi_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
那么,我们下面只要修改一下程序,将这个spi和74HC595连接进行连接,那么我们就能调试程序了。 |
|