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

📄 大容量串行false45db081 c51读写源程序.c

📁 串行大容量存储器的c51 读写源程序特点:占用io口线少
💻 C
📖 第 1 页 / 共 2 页
字号:
sfr16 ADC0GT   = 0xc4;                 // ADC0 greater than window
sfr16 ADC0LT   = 0xc6;                 // ADC0 less than window
sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
sfr16 T2       = 0xcc;                 // Timer2
sfr16 DAC0     = 0xd2;                 // DAC0 data
sfr16 DAC1     = 0xd5;                 // DAC1 data
unsigned int Count1msInc;
void SYSCLK_Init (void);
void PORT_Init (void);
void SPI0_Init (void);
void Timer0_Init (void);
void main (void) {
unsigned char xdata MyBuff[1000];
unsigned char xdata MyBuff1[1000];
unsigned int i,j;
WDTCN = 0xde;                       // disable watchdog timer
WDTCN = 0xad;
SYSCLK_Init ();                     // initialize oscillator
Timer0_Init();
PORT_Init ();                       // initialize crossbar and GPIO
EA=1;
DF_RESET;
SPI0_Init ();                       // initialize SPI0
RAM_CHIP_SELECT_BANK0;
    EMI0CF = 0x2F; 
    i=1;
    if (i)
{ 
Count1msInc=0;
ErasingDataFlash(); //整片擦除
Count1msInc=0;
      for (i=0;i<2;i++)
{ 
AT450XXPageAddr=i;
for (j=0;j<255;j++)
{
MyBuff[j]=j+i;
}
if (i%2)
FlashAutoProgViaBuffer1
(0,264,MyBuff); //将指定数据通过缓存1写入Flash指定位置(先擦除)
else
FlashAutoProgViaBuffer2
(0,264,MyBuff); //将指定数据通过缓存2写入Flash指定位置(先擦除)
}
      /*  for(i=0;i<520;i++)
{ if(i<260)
  MyBuff[i]=0x00;
  else 
  MyBuff[i]=0x01;

}*/
    AT450XXPageAddr=0;
FlashBuffer1Write(20,14,"1234567890UUAA");
FlashBuffer1Read(0,260,MyBuff1);
    FlashBuffer1Write(20,14,"1234567890UUAA");
    FlashBuffer1Read(20,14,MyBuff); //在此处设置断点,观察
MyBuff的内容
FlashBuffer1ProgNoErase();
    PageToBuffer2();
    FlashBuffer2Read(20,14,MyBuff); 
    Count1msInc=0;
    FlashBuffer2Read(100,14,MyBuff);
    Count1msInc=0;
    FlashBuffer1Write(20,14,"1234567890UUAA");
    Count1msInc=0;
    FlashBuffer1Read(100,14,MyBuff);
    Count1msInc=0;
    FlashBuffer1ProgNoErase(); 
    Count1msInc=0;
    PageToBuffer2();
    Count1msInc=0;
    FlashBuffer2Read(100,14,MyBuff);
    FlashProgViaBuffer1(100,14,MyBuff);
ErasingDataFlash();
EraseFlashPage(); 
FlashBuffer1Read(1,1, MyBuff); //从缓冲区1的指定位置(0-
263)中读入指定字节
FlashBuffer2Read(1,1,MyBuff); //从缓冲区2的指定位置(0-263)
中读入指定字节
FlashBuffer1Write(1,1,"!");
FlashBuffer2Write(1,1,"1");
GetFlashStatus();
PageToBuffer1();
PageToBuffer2();
FlashBuffer1ProgNoErase();
FlashBuffer2ProgNoErase();
FlashBuffer1ProgAutoErase();
FlashBuffer2ProgAutoErase();
FlashProgViaBuffer1(1,1, MyBuff);
FlashProgViaBuffer2(1,1, MyBuff);
FlashAutoProgViaBuffer1(1,1, MyBuff);
FlashAutoProgViaBuffer2(1,1, MyBuff);
}
xxx:   goto xxx;
}
void SYSCLK_Init (void)
{
   int i;                              // delay counter
   OSCXCN = 0x67;                      // start external oscillator with
                                       // 11.0592MHz crystal
   for (i=0; i < 256; i++) ;           // Wait for osc. to start up
   while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle
   OSCICN = 0x88;                      // select external oscillator as SYSCLK
                                       // source and enable missing clock
}
void PORT_Init (void)
{
   XBR0    = 0x07;                     // Enable SMBus, SPI0, and UART0
   XBR1    = 0x00;
   XBR2    = 0x44;                     // Enable crossbar and weak pull-ups
   EMI0TC  = 0x21;

   P74OUT  = 0x0F;
   P0MDOUT = 0x15;
}
void SPI0_Init (void)
{
   SPI0CFG = 0x07;                     // data sampled on 1st SCK rising edge
                                       // 8-bit data words
   SPI0CFG|=0xC0;//CKPOL =1;

   SPI0CN = 0x03;                      // Master mode; SPI enabled; flags
                                       // cleared
   SPI0CKR = SYSCLK/2/2000000-1;       // SPI clock <= 8MHz (limited by 
                                       // EEPROM spec.)
}

void Timer0_Init (void)
{
   CKCON|=0x8;
   TMOD|=0x1;    //16Bit
   TR0 = 0;                          // STOP Timer0
   TH0 = (-SYSCLK/1000) >> 8;     // set Timer0 to overflow 
in 1ms
   TL0 = -SYSCLK/1000;
   TR0 = 1;    // START Timer0
   IE|= 0x2; 
}
void Timer0_ISR (void) interrupt 1  //1ms
{
TH0 = (-SYSCLK/1000) >> 8;  
    TL0 = -SYSCLK/1000;
Count1msInc++;
}

在给你一个(23294字)龙路[20次]2004-5-20 14:32:22
#include <reg51.h>
#include <intrins.h>
#include <lcd1602.h>
#define uchar unsigned char
#define uint unsigned int
sbit FLASH_CS=P1^7;
sbit FLASH_SCK=P1^6;
sbit FLASH_SI=P1^5;
sbit FLASH_SO=P1^4;

sbit     a0 = ACC^0;
sbit  a1 = ACC^1;
sbit  a2 = ACC^2;
sbit  a3 = ACC^3;
sbit  a4 = ACC^4;
sbit  a5 = ACC^5;
sbit  a6 = ACC^6;
sbit  a7 = ACC^7;
uchar c,i;
uchar buf1[8],buf2[8];
void DelayNMs(uint n) //延时 Nms
{    uchar data ii;
    while(n--){    ii=100;while(ii--);    }
}

void  ICOutPage(uint Page)  /*发送页面地址*/
{
    ACC = (uchar)(Page>>8);
    FLASH_SI = a2;      FLASH_SCK = 0;                FLASH_SCK = 1;
    FLASH_SI = a1;      FLASH_SCK = 0;                FLASH_SCK = 1;
    FLASH_SI = a0;      FLASH_SCK = 0;                FLASH_SCK = 1;
        ACC = (uchar)(Page%0xff);
    FLASH_SI = a7;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a6;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a5;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a4;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a3;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a2;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a1;      FLASH_SCK = 0;              FLASH_SCK = 1;
    FLASH_SI = a0;      FLASH_SCK = 0;              FLASH_SCK = 1;
}
void  ICOutAddr(uint ByteAddr)     /*发送字节地址*/
{
    ACC = (uchar)(ByteAddr>>8);
    FLASH_SI = a0;             FLASH_SCK = 0;      FLASH_SCK = 1;
        ACC = (uchar)(ByteAddr%0xff);
    FLASH_SI = a7;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a6;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a5;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a4;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a3;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a2;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a1;      FLASH_SCK = 0;     FLASH_SCK = 1;
    FLASH_SI = a0;      FLASH_SCK = 0;     FLASH_SCK = 1;
}
void  ICOutXBits(uchar N)                    /*发送N个任意字符*/
{
    FLASH_SI = 0;
    while (N>0)
    {
        FLASH_SCK = 0;
        FLASH_SCK = 1;
        N--;
    }
}
//---------------------------------------------------
void  ICWriteByte(uchar b)      /*连续写下一个字节*/
{
    ACC = b;
    FLASH_SI = a7;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a6;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a5;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a4;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a3;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
FLASH_SCK = 0;
    FLASH_SI = a2;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a1;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
    FLASH_SI = a0;         FLASH_SCK = 1;                
                            
      FLASH_SCK = 0;
}
//---------------------------------------------------
uchar ICReadByte()     /*连续读下一个字节*/
{
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a7;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a6;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a5;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a4;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a3;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a2;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a1;
     FLASH_SCK = 1;FLASH_SCK = 0; FLASH_SO = a0;
    return (ACC);
}
uchar ICStatus() //读状态寄存器
{
  uchar d;
    ICWriteByte(0x57);
    d=ICReadByte();
  FLASH_CS=1;
  return(d);
}
//---------------------------------------------------
void  ICWaitReady()      /*等待IC卡准备好*/
{
    uchar c;
    while (1)
    {
        c = ICStatus();
        if (c&0x80) break;
    }
}
//主存贮器页读,不通过缓冲器
void Flash_Read(uint start_page,uint start_addr,uint len, uchar *buf)
{
     FLASH_CS=0;
     ICWriteByte(0x52);
      ICOutXBits(4);
   ICOutPage(start_page);
   ICOutAddr(start_addr);
   ICOutXBits(32);
     ICReadByte();
   while(len--)    {  *buf=ICReadByte();    buf++;    }
   FLASH_CS=1;
}
//写buf中的数据到start_page页的start_addr开始的地址
void Flash_Write(uint start_page,uint start_addr,uint len,uchar *buf)
{
    FLASH_CS=0;
    ICWriteByte(0x82);
    ICOutXBits(4);
    ICOutPage(start_page);
    ICOutAddr(start_addr);
    while(len--) {    ICWriteByte(*buf); buf++;    }
    FLASH_CS=1;
    DelayNMs(10);
}
void IC_Init()
{
    FLASH_CS=1;
    FLASH_SI=1;
    FLASH_SO=1;
    FLASH_SCK=0;
}
void main()
{
    i=0;
    LcdReset();
    IC_Init();
    while(1)
    {
        for(i=0;i<8;i++) {    buf1[i]='A'+i; buf2[i]='a'+i;    }
      Flash_Write(0,0,8,buf1);
        ShowMessage(0,0,buf1);
      Flash_Read(0,0,8,buf2);
        Delay1Ms(500);
    }
}

⌨️ 快捷键说明

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