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

📄 eeprom.h

📁 旋转16个LED灯控制程序
💻 H
字号:
/* Stripped to just what CharPOV needs *//******************************************SpokePOV V1.0 firmwareSpokePOV firmware is distributed under CC license. For more info on CC go to www.creativecommons.orgFor more info on SpokePOV go to www.ladyada.net/make/spokepovCreative Commons DeedAttribution-NonCommercial-ShareAlike 2.5You are free:    * to copy, distribute, display, and perform the work    * to make derivative worksUnder the following conditions:Attribution.   You must attribute the work in the manner specified by the    author or licensor.Noncommercial.    You may not use this work for commercial purposes.Share Alike.    If you alter, transform, or build upon this work, you may    distribute the resulting work only under a license identical to this one.    * For any reuse or distribution, you must make clear to others       the license terms of this work.    * Any of these conditions can be waived if you get permission       from the copyright holder.Your fair use and other rights are in no way affected by the above.A more detailed version of this license is available at:http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode******************************************/#define SPIEE_CS_PORT PORTB#define SPIEE_CS 4#define SPI_EEPROM_READ 0x3#define SPI_EEPROM_WRITE 0x2#define SPI_EEPROM_WREN 0x6#define SPI_EEPROM_RDSR 0x5#define SPI_EEPROM_WRSR 0x1#ifndef EEWE#define EEWE 1#endif#ifndef EEMWE#define EEMWE 2#endif/* Do we implement the spi_ routines inline, or as functions? *//* Inline might make the interrupt routines a wee bit faster, *//* but costs about 200 bytes...								  *//* This code is part of my experimentation to improve the	  *//* maximum RPM that the blade can handle					  */// #define SPI_INLINE	1/* functions in the library */#ifndef SPI_INLINE  void spi_transfer(uint8_t c);  void spi_transfer_n(uint8_t c, uint8_t n);  void spieeprom_read(uint16_t addr, uint8_t *buff, uint8_t len);#else// These are the macro versions of above// Move n bits of data over the serial link#define spi_transfer_n(c,n)												\  USIDR = c;															\  USISR = _BV(USIOIF) | (16 - (n<<1));									\  while ( (USISR & _BV(USIOIF)) == 0) {									\    USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);		\  }#define spi_transfer(c)													\  USIDR = c;															\  USISR = _BV(USIOIF);													\  while ( (USISR & _BV(USIOIF)) == 0) {									\    USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);		\  }#define spieeprom_read(addr,buff,len)		\  SPIEE_CS_PORT &= ~_BV(SPIEE_CS);			\  NOP; NOP; NOP; NOP;						\  spi_transfer(SPI_EEPROM_READ);			\  spi_transfer(addr >> 8);					\  spi_transfer(addr & 0xFF);				\  {											\    uint8_t i;								\    char *p = (char *)(buff);				\    for (i=0; i<len; i++) {					\      spi_transfer(0);						\      *p++ = USIDR;						\    }										\  }											\  SPIEE_CS_PORT |= _BV(SPIEE_CS); #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -