最近在用AT45DB041B 谁能给我个MSP430F149中AT45DB041B的设置和读写的程序呀?谢谢大侠们了
试试这个可以不
void Send_Byte(void)
{
int i;
int Tamp;
for (i=0;i<8;i++)
{
P6OUT &= 0xDF;
Tamp = word;
Tamp &= 0x80;
if(!Tamp)
P6OUT &= 0xEF;
else
P6OUT |= 0x10;
P6OUT |= 0x20;
word = word << 1;
}
}
void Send_Start(void)
{
P6DIR |= 0X30;
P6OUT |= 0X20;
word = cmd_word;
Send_Byte();
}
void Stop(void)
{
P6DIR &= 0X00;
P6DIR |= 0X63;
P6OUT |= 0X63;
}
void Flash_B_Write(void)
{
int j;
P6DIR |= 0X40;
P6OUT &= 0XBF;
cmd_word = 0x84;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
for(j=0;j<16;j++)
{
word = tab[j];
Send_Byte();
}
Buff_addr = (int *)0x1A;
Stop();
}
void Receive_Byte(void)
{
int i;
P6DIR |= 0X20;
P6DIR &= 0XF7;
R_word = 0x00;
P6OUT &= 0xBF;
for(i=0;i<8;i++)
{
P6OUT &= 0xDF;
P6OUT |= 0X20;
if(P6IN & 0x08)
R_word |= 0x01;
else
R_word &= 0xFE;
P6OUT &= 0xDF;
R_word = R_word << 1;
}
R_word = R_word >> 1;
}
void Flash_B_Read(void)
{
int j;
P6DIR |= 0X40;//CS out
P6OUT &= 0XBF;
cmd_word = 0x54;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
word = 0xff;
Send_Byte();
for(j=0;j<16;j++)
{
Receive_Byte();
*Ram_addr++ = R_word;
}
Stop();
}
虽然不是1系列的...呵呵
#i nclude <msp430x26x.h>
#i nclude "Memory_Process.h"
#define IO_SET_WP_OUTPUT() (P5DIR |= BIT7)
#define IO_SET_WP() (P5OUT |= BIT7)
#define IO_CLR_WP() (P5OUT &= ~BIT7)
#define IO_SET_RESET_OUTPUT() (P5DIR |= BIT6)
#define IO_SET_RESET() (P5OUT |= BIT6)
#define IO_CLR_RESET() (P5OUT &= ~BIT6)
#define IO_SET_CS_OUTPUT() (P3DIR |= BIT0)
#define IO_SET_CS() (P3OUT |= BIT0)
#define IO_CLR_CS() (P3OUT &= ~BIT0)
void Memery_IO_Initial(void)
{
IO_SET_WP_OUTPUT();
IO_SET_RESET_OUTPUT();
IO_SET_CS_OUTPUT();
IO_SET_WP();
IO_SET_RESET();
IO_SET_CS();
}
void Memery_Interrupt_Initial(void)
{
P3SEL |= 0x0E; // P3.1,2,3 SPI option select
U0CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U0TCTL = SSEL1 + STC; // Polarity, SMCLK, 3-wire CKPL +
U0BR0 = 0x00; // SPICLK = SMCLK/2
U0BR1 = 0x00;
U0MCTL = 0x00;
ME1 |= USPIE0; // Module ena××e
U0CTL &= ~SWRST; // SPI ena××e
}
void Memery_Read_Page(unsigned int w_Page,char *pby_Data)
{
char by_High_Page,by_Low_Page;
unsigned int w_Dat;
w_Page = w_Page << 1;
by_High_Page = (char)(w_Page >> 8);
by_Low_Page = (char)w_Page;
IO_CLR_CS();
for(char by_Loop = 0;by_Loop < 8;by_Loop++)
{
if(by_Loop == 0) U0TXBUF = 0xd2;
else if(by_Loop == 1)U0TXBUF = by_High_Page;
else if(by_Loop == 2)U0TXBUF = by_Low_Page;
else U0TXBUF = 0;
while(!(U0TCTL & TXEPT));
}
w_Dat = 0;
IFG1 &= ~URXIFG0;
while(1)
{
U0TXBUF = 0X0;
if(IFG1 & URXIFG0)
{
*(pby_Data + w_Dat) = U0RXBUF;
IFG1 &= ~URXIFG0;
w_Dat++;
}
if(w_Dat == PAGE_SIZE)break;
}
IO_SET_CS();
}
void Memery_Write_To_Buffer(char by_Buffer,char *pby_Data)
{
char by_Com;
unsigned int w_Dat = 0;
if(by_Buffer == 1) by_Com = 0x84;
else if(by_Buffer == 2) by_Com = 0x87;
else return;
IO_CLR_CS();
U0TXBUF = by_Com;
while(!(U0TCTL & TXEPT));
U0TXBUF = 0X0;
while(!(U0TCTL & TXEPT));
U0TXBUF = 0X0;
while(!(U0TCTL & TXEPT));
U0TXBUF = 0X0;
while(!(U0TCTL & TXEPT));
while(1)
{
for(w_Dat = 0;w_Dat < PAGE_SIZE;w_Dat++)
{
U0TXBUF = *(pby_Data + w_Dat);
while(!(U0TCTL & TXEPT));
}
if(w_Dat == PAGE_SIZE)break;
}
IO_SET_CS();
}
void Memery_Buffer_Write_To_Page(char by_Buffer,unsigned int w_Page)
{
char by_High_Address,by_Low_Address;
char by_Com;
if(by_Buffer == 1) by_Com = 0x83;
else if(by_Buffer == 2) by_Com = 0x86;
else return;
w_Page = w_Page << 1;
by_High_Address = (char)(w_Page >> 8);
by_Low_Address = (char)(w_Page);
IO_CLR_CS();
U0TXBUF = by_Com;
while(!(U0TCTL & TXEPT));
U0TXBUF = by_High_Address;
while(!(U0TCTL & TXEPT));
U0TXBUF = by_Low_Address;
while(!(U0TCTL & TXEPT));
U0TXBUF = 0X0;
while(!(U0TCTL & TXEPT));
IO_SET_CS();
}