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

📄 eeprom.c

📁 旋转16个LED灯控制程序
💻 C
字号:
/* 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******************************************/#include <avr/io.h>#include "eeprom.h"#include "main.h"// If we are not inline coding, define the spi_ routines as// functions.  WARNING: make sure any changes in this code// is also implemented in the macro version in eeprom.h!#ifndef SPI_INLINE// All of the following routines have been modified so they// only deal with the front leds, for speed, and to save// code space!// Move n bits of data over the serial linkvoid spi_transfer_n(uint8_t c, uint8_t n) {  // Stuff the byte to transfer into the serial data register    USIDR = c;    // Set up the status register.  On each state transition of  // the serial bus (up or down), the lower 4 bits will be  // incremented - so twice per bit.  When that overflows,  // the transfer is done.  So if they start out as 0, 8  // bits get moved.  But if you start it out at a different  // value, you can move an arbitrary number of bits    USISR = _BV(USIOIF) | (16 - (n<<1));  // While the transfer has not finished    while ( (USISR & _BV(USIOIF)) == 0) {    // Send out another bit        USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);    //NOP;  // slow down so that the eeprom isnt overwhelmed  }}// Move 4 bytes over the serial link (to the 1K/4K EEPROM or the// LED shift registers, or both!).  This code does things "blind",// clocking 16 times, to transfer the data as fast as possible.void spi_transfer(uint8_t c) {  USIDR = c;  USISR = _BV(USIOIF);  while ( (USISR & _BV(USIOIF)) == 0) {    USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);    //NOP;  // slow down so that the eeprom isnt overwhelmed  }  // The byte read, if any, will be in USIDR  }void spieeprom_read(uint16_t addr, uint8_t *buff, uint8_t len) {  uint8_t i;  SPIEE_CS_PORT &= ~_BV(SPIEE_CS); // pull CS low  NOP; NOP; NOP; NOP;  spi_transfer(SPI_EEPROM_READ);           // send READ command  spi_transfer(addr >> 8);                 // send high addr   spi_transfer(addr & 0xFF);               // send low addr  for (i=0; i<len; i++)	{				   // read in the right number of    spi_transfer(0);					   // bits, then move to buff[]    buff[i] = USIDR;  }  SPIEE_CS_PORT |= _BV(SPIEE_CS);      // pull CS high}#endif

⌨️ 快捷键说明

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