最新免费av在线观看,亚洲综合一区成人在线,中文字幕精品无码一区二区三区,中文人妻av高清一区二区,中文字幕乱偷无码av先锋

登錄 免費(fèi)注冊(cè) 首頁(yè) | 行業(yè)黑名單 | 幫助
維庫(kù)電子市場(chǎng)網(wǎng)
技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng)
驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe

轉(zhuǎn)一個(gè)Mega8 SPI讀寫DataFlash的代碼,測(cè)試好用的

作者:zlei 欄目:單片機(jī)
轉(zhuǎn)一個(gè)MEGA8 SPI讀寫DataFlash的代碼,測(cè)試好用的
;***************************************************************************
;
; File NAME        :'DFlash.asm"
; Title            :SPI interface to Serial DataFlash
; Date            :2003.06.01.
; Version        :1.0.0
; SUPPORT telephone    :+36-70-333-4034,  old: +36-30-9541-658 VFX
; SUPPORT fax        :
; SUPPORT Email        :info@vfx.hu
; Target MCU        :ATMEGA8
;
;***************************************************************************
;    D E S C R I P T I O N
;
; SPI interface to AT45DBxxx Serial DataFlash
;
; Functions to access the ATMEL AT45Dxxx dataFLASH series
;  SUPPORTs 1Mbit - 128Mbit
;
;***************************************************************************
;    M O D I F I C A T I O N   H I S T O R Y
;
;
;       rev.      date      who      why
;    ----    ----------  ---        ------------------------------------
;    0.01    2003.06.01  VFX        Creation
;
;***************************************************************************
;HARDWARE
;***************************************************************************
;*
;*    SYSCLK: f=16.000 MHz (T= 62.5 ns)
;*
;***************************************************************************
;
; CS    - Chip SELECT
; SCK   - Serial Clock
; SI    - Serial Input
; SO    - Serial OUTPUT
; WP    - HARDWARE Page Write Protect Pin
; RESET - Chip Reset
; RDY/BUSY - Ready/Busy
;
; To provide optimal flexibility, the MEMORY array of the AT45DB081B is
;divided into three levels of granularity comprising of sectors, blocks,
;and pages. All program operations to the DataFlash occur on a page-by-page
;basis; however, the optional erase operations can be performed at the block
;or page level.
;
;
;The DEVICE operation is controlled by instructions from the host processor.
;The list of instructions and their associated opcodes are contained in
;Tables 1 through 4. A valid instruction starts with the falling edge of CS
;followed by the appropriate 8-bit opcode and the desired buffer or main MEMORY
;address location. While the CS pin is low, tog-gling the SCK pin controls the
;loading of the opcode and the desired buffer or main MEMORY address location
;through the SI (serial input) pin. All instructions, addresses and data are
;transferred with the most significant bit (MSB) first.
;Buffer addressing is referenced in the datasheet using the terminology
;BFA8 - BFA0 to denote the nine address bits required to designate a byte address
;within a buffer. Main MEMORY addressing is referenced using the terminology
;PA11 - PA0 and BA8 - BA0 where PA11 - PA0 denotes the 12 address bits required
;to designate a page address and BA8 - BA0 denotes the nine address bits
;required to designate a byte address within the page.
;
;
;Status Register Format
;Bit   7      6    5   4  3  2  1  0
;  RDY/BUSY COMP   1   0  0  1  X  X    45DB161
;***************************************************************************
;* Const Def
;

;Look-up table for these sizes ->  512K, 1M, 2M, 4M, 8M, 16M, 32M, 64M
;FLASH unsigned CHAR DF_pagebits[]  ={  9,  9,  9,  9,  9,  10,  10,  11};    //index of internal page address bits



;DataFLASH opcodes
.equ MainMemPageRead    =     0x52    ;Main MEMORY Page Read Inactive Clk Pol Low or High
.equ FlashPageRead    =    0x52    ;Main MEMORY page read
.equ FlashToBuf1Transfer=    0x53    ;Main MEMORY page to buffer 1 transfer
.equ Buf1Read        =    0x54    ;Buffer 1 read
.equ FlashToBuf2Transfer=    0x55    ;Main MEMORY page to buffer 2 transfer
.equ Buf2Read        =    0x56    ;Buffer 2 read
.equ StatusReg        =    0x57    ;Status register
.equ StatusRegMode3    =    0xD7    ;Status register read SPI Mode 0 or 3
.equ AutoPageReWrBuf1    =    0x58    ;Auto page rewrite through buffer 1
.equ AutoPageReWrBuf2    =    0x59    ;Auto page rewrite through buffer 2
.equ FlashToBuf1Compare    =    0x60    ;Main MEMORY page to buffer 1 compare
.equ FlashToBuf2Compare    =    0x61    ;Main MEMORY page to buffer 2 compare
.equ ContArrayRead    =    0x68    ;Continuous Array Read (Note : ONLY A/B-parts supported)
.equ FlashProgBuf1    =    0x82    ;Main MEMORY page program through buffer 1
.equ Buf1ToFlashWE    =    0x83    ;Buffer 1 to main MEMORY page program with built-in erase
.equ Buf1Write        =    0x84    ;Buffer 1 write
.equ FlashProgBuf2    =    0x85    ;Main MEMORY page program through buffer 2
.equ Buf2ToFlashWE    =    0x86    ;Buffer 2 to main MEMORY page program with built-in erase
.equ Buf2Write        =    0x87    ;Buffer 2 write
.equ Buf1ToFlash    =    0x88    ;Buffer 1 to main MEMORY page program without built-in erase
.equ Buf2ToFlash    =    0x89    ;Buffer 2 to main MEMORY page program without built-in erase
.equ MainMemPageReadSPI =    0xD2    ;Main MEMORY Page Read SPI Mode 0 or 3
.equ ContArrayReadSPI   =    0xE8    ;Continuous Array Read SPI Mode 0 or 3


;Table 2. Program and Erase Commands
.equ Buffer1Write       = 0x84 ;Buffer 1 Write
.equ Buffer2Write       =
2樓: >>參與討論
hujiahua
DataFlash 是不是 MULTI Media Card?
 
3樓: >>參與討論
lizy927
大哥 怎么搞個(gè)匯編的過(guò)來(lái)呀
 
4樓: >>參與討論
zlei
要c的嗎?咬咬牙把移植測(cè)試好的C代碼貼出來(lái)了
//來(lái)自 ATMEL.html">ATMEL 已經(jīng)移植gcc了
//CPU MEGA16L @7.3728MHZ
//*****************************************************************************
//
//      COPYRIGHT (c) ATMEL Norway, 1996-2001
//
//      The COPYRIGHT to the document(s) herein is the property of
//      ATMEL Norway, Norway.
//
//      The document(s) may be used  and/or copied ONLY with the written
//      permission from ATMEL Norway or in accordance with the terms and
//      conditions stipulated in the agreement/contract under which the
//      document(s) have been supplied.
//
//*****************************************************************************
//
//  File........: DATAFLASH.C
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: All AVRs with built-in HW SPI
//
//  DESCRIPTION.: Functions to access the ATMEL AT45Dxxx dataFLASH series
//                SupPORTs 512Kbit - 64Mbit
//
//  Revisions...:
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20011017 - 1.00 - Beta release                                  -  RM
//  20011017 - 0.10 - Generated file                                -  RM
//  20050403          PORT to avr-gcc/avr-libc                      - zlei
//
//*****************************************************************************


// Includes

#include <avr/io.h>
#include <inttypes.h>
#include <avr/pgmspace.h>

#include "dataFLASH.h"

// Constants
//Look-up table for these sizes ->  512K, 1M, 2M, 4M, 8M, 16M, 32M, 64M
const uint8_t DF_pagebits[] PROGMEM ={  9,  9,  9,  9,  9,  10,  10,  11};        //index of internal page address bits
//Look-up table for these sizes ->  512K, 1M,  2M,  4M,  8M, 16M, 32M, 64M
const uint16_t DF_pagesize[] PROGMEM ={264,264, 264, 264, 264, 528, 528,1056};    //index of pagesizes


// Globals
unsigned CHAR PageBits = 0;
unsigned int  PageSize = 0;
// Functions

/*****************************************************************************
*
*    Function NAME : DF_SPI_init
*
*    Returns :        None
*
*    Parameters :    None
*
*    Purpose :        Sets up the HW SPI in MASTER mode, Mode 3
*                    Note -> Uses the SS LINE to CONTROL the DF CS-LINE.
*
******************************************************************************/
void DF_SPI_init (void)
{
    PORTB |= (1<<PB4) | (1<<PB5) | (1<<PB6) | (1<<PB7);
    DDRB |= (1<<DDB5) | (1<<DDB7) | (1<<DDB4);        //Set MOSI, SCK AND SS as OUTPUTs

    SPSR = (1<<SPI2X);                                 //SPI double speed settings
    SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<CPOL);    //Enable SPI in MASTER mode, mode 3, Fosc/4
}

/*****************************************************************************
*
*    Function NAME : DF_SPI_RW
*
*    Returns :        Byte read from SPI data register (any VALUE)
*
*    Parameters :    Byte to be written to SPI data register (any VALUE)
*
*    Purpose :        Read and writes one byte from/to SPI MASTER
*
******************************************************************************/
unsigned CHAR DF_SPI_RW (unsigned CHAR OUTPUT)
{
    unsigned CHAR input;
    
    SPDR = OUTPUT;                            //put byte 'OUTPUT' in SPI data register
    while(!(SPSR & 0x80));                    //wait for transfer complete, poll SPIF-flag
    input = SPDR;                            //read VALUE in SPI data reg.
    
    return input;                            //return the byte clocked in from SPI slave
}        


/*****************************************************************************
*
*    Function NAME : Read_DF_status
*
*    Returns :        One status byte. Consult DataFLASH datasheet for further
*                    decoding info
*
*    Parameters :    None
*
*    Purpose :        Status info concerning the DataFLASH is busy or not.
*                    Status info concerning compare between buffer and FLASH page
*                    Status info concerning size of actual DEVICE
*
******************************************************************************/
unsigned CHAR Read_DF_status (void)
{
    unsigned CHAR result,index_copy;
    
    DF_CS_DISABLE;             
5樓: >>參與討論
zlei
頭文件和測(cè)試代碼
#ifndef __DATAFLASH_INCLUDED
#define __DATAFLASH_INCLUDED

//General macro definitions
//changed to *DF for avr-libc future compatiblity
#define sbiDF(PORT,bit)    (PORT |=  (1<<bit))
#define cbiDF(PORT,bit)    (PORT &= ~(1<<bit))


#define SetBit(x,y)        (x |= (y))
#define ClrBit(x,y)        (x &=~(y))
#define ChkBit(x,y)        (x  & (y))


//DataFLASH opcodes
#define FlashPageRead                0x52    // Main MEMORY page read
#define FlashToBuf1Transfer         0x53    // Main MEMORY page to buffer 1 transfer
#define Buf1Read                    0x54    // Buffer 1 read
#define FlashToBuf2Transfer         0x55    // Main MEMORY page to buffer 2 transfer
#define Buf2Read                    0x56    // Buffer 2 read
#define StatusReg                    0x57    // Status register
#define AutoPageReWrBuf1            0x58    // Auto page rewrite through buffer 1
#define AutoPageReWrBuf2            0x59    // Auto page rewrite through buffer 2
#define FlashToBuf1Compare            0x60    // Main MEMORY page to buffer 1 compare
#define FlashToBuf2Compare            0x61    // Main MEMORY page to buffer 2 compare
#define ContArrayRead                0x68    // Continuous Array Read (Note : ONLY A/B-parts supPORTed)
#define FlashProgBuf1                0x82    // Main MEMORY page program through buffer 1
#define Buf1ToFlashWE               0x83    // Buffer 1 to main MEMORY page program with built-in erase
#define Buf1Write                    0x84    // Buffer 1 write
#define FlashProgBuf2                0x85    // Main MEMORY page program through buffer 2
#define Buf2ToFlashWE               0x86    // Buffer 2 to main MEMORY page program with built-in erase
#define Buf2Write                    0x87    // Buffer 2 write
#define Buf1ToFlash                 0x88    // Buffer 1 to main MEMORY page program without built-in erase
#define Buf2ToFlash                     0x89    // Buffer 2 to main MEMORY page program without built-in erase
#define PageErase                   0x81    // Page erase, added by Martin THOMAS

//Pin definitions for interface to the DataFLASH


//DataFLASH macro definitions

//PB4(SS#) for dataFLASH CS#
#define DF_CS_ENABLE        cbiDF(PORTB,4)
#define DF_CS_DISABLE        sbiDF(PORTB,4)

//PB1 for dataFLASH WP#
#define DF_WP_PIN            1
#define DF_WP_ON            sbiDF(PORTB,DF_WP_PIN)  
#define DF_WP_OFF            sbiDF(PORTB,DF_WP_PIN)

//Function definitions
void DF_SPI_init (void);
unsigned CHAR DF_SPI_RW (unsigned CHAR OUTPUT);
unsigned CHAR Read_DF_status (void);
void Page_To_Buffer (unsigned int PageAdr, unsigned CHAR BufferNo);
unsigned CHAR Buffer_Read_Byte (unsigned CHAR BufferNo, unsigned int IntPageAdr);
void Buffer_Read_Str (unsigned CHAR BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned CHAR *BufferPtr);
void Buffer_Write_Enable (unsigned CHAR BufferNo, unsigned int IntPageAdr);
void Buffer_Write_Byte (unsigned CHAR BufferNo, unsigned int IntPageAdr, unsigned CHAR Data);
void Buffer_Write_Str (unsigned CHAR BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned CHAR *BufferPtr);
void Buffer_To_Page (unsigned CHAR BufferNo, unsigned int PageAdr);
void Cont_Flash_Read_Enable (unsigned int PageAdr, unsigned int IntPageAdr);

//Function definitions 2,use macro to replace above function NAME for using
#define dfSpiInit                DF_SPI_init
#define dfSpiRW                    DF_SPI_RW
#define dfReadStatus            Read_DF_status
#define dfPageToBuffer            Page_To_Buffer
#define dfBufferReadByte         Buffer_Read_Byte
#define dfBufferReadStr         Buffer_Read_Str
#define dfBufferWriteEnable     Buffer_Write_Enable
#define dfBufferWriteByte         Buffer_Write_Byte
#define dfBufferWriteStr         Buffer_Write_Str
#define dfBufferToPage            Buffer_To_Page
#define dfContFlashReadEnable    Cont_Flash_Read_Enable

// *****************************[ End Of DATAFLASH.H ]*****************************


void AT45Test(void)
{
    u08 i=0;
    
    
    //---------------
    rprintf("Start AT45 data FLASH TEST !\n\r");
    
    i=dfReadStatus();
    writeSeg7(i);
    rprintf("\n\r1. Read DF Status : %x \n\r",i);
    
    dfPageToBuffer(1,1);
    rprintf("\n\r2. Transfers Page 1 To Buffer 1 \n\r");
    
    timerPause(100);
    i=dfBufferReadByte(1,0x10)
參與討論
昵稱:
討論內(nèi)容:
 
 
相關(guān)帖子
用mega16和lm629做控制,lm629的CLK怎樣使用?
請(qǐng)問:m8515外接存儲(chǔ)器怎么接?
誰(shuí)能告訴我,關(guān)于GCC一個(gè)問題的答案!
讀外部I2C器件過(guò)來(lái)的數(shù)據(jù)信號(hào)應(yīng)該讀PINX還是PORTX啊?
如何改熔絲位?
免費(fèi)注冊(cè)為維庫(kù)電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入


Copyright © 1998-2006 www.udpf.com.cn 浙ICP證030469號(hào)