?? spi_driver.c
字號:
#include<avr/io.h>
#include<avr/interrupt.h>
#include "SPI_Drive_Priv.h"
#include "SPI_Driver.h"
//unsigned char l_mc_flag = 0,l_mc_temp = 0;
/* spi interrupt service routine for transmitting and receiving the data */
ISR(SPI_STC_vect)
{
l_mc_temp = SPDR;
SPSR =0x00;
l_mc_flag =1;
}
/* Initailising spi with 2 MHZ clock */
void init_spi(void)
{
SPI_DTA_DIR_PORT = 0x06;
SPI_DTA_DIR_CS_PORT = 0x01;
CS_PIN = 0x01;
SPCR = 0xD0;
SPSR = 0x00;
}
/* Enabling the slave chip select pin */
void spi_cs_enable(void)
{
CS_PIN_ENABLE;
}
/* disabling the slave chip select pin */
void spi_cs_disable(void)
{
CS_PIN_DISABLE;
}
/* sending single byte of data to slave */
void spi_send_byte(unsigned char l_mc_ch)
{
l_mc_flag = 0;
SPDR = l_mc_ch;
while(l_mc_flag != 1);
}
/* receving single byte from slave */
char spi_read_byte()
{
l_mc_flag = 0;
SPDR = 0xFF;
while(l_mc_flag != 1);
return(l_mc_temp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -