⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi_driver.c

📁 ps2 key board drivers and source code with mega8
💻 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 + -