您的位置 首页 发布

MSP430F149单片机对SDRAM操控程序设计

MSP430的内核结构采用具有高透明格式的精简指令集(RISC)设计。指令分为硬件实现的内核指令和利用这一硬件结构的具有更高效率的模拟指令,

MSP430的内核结构选用具有高通明格局的精简指令集(RISC)规划。指令分为硬件完结的内核指令和运用这一硬件结构的具有更高功率的模仿指令,运用起来十分便利。在本控制系统中,单片机完结初始化使命(设置标志位、看门狗的工作方式)后,就进入低功耗睡觉状况。中止将其唤醒,转而进入相应的子程序。根据MSP430F149单片机的SDRAM控制程序如下。

#include <msp430x14x.h>

void Init(void);

void Send(char* Data, unsigned int Length);

void SendAddress(unsigned int Address);

void SendData(unsigned int Data);

unsigned int ReceiveData(void);

char ReadData[20], Buffer[20];

unsigned char i=0, j, k, flag=0;

unsigned int Data;

unsigned int DisplayData;

char DisplayString[20];

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

Init(); // UART1 inition

_EINT(); // enable interrupt

while(1)

{

DisplayData = ReceiveData();

if (DisplayData == 0)

{

k = 0;

if (DisplayData != 0)

{

DisplayString[k] = 0 + DisplayData % 10;

DisplayData = DisplayData / 10;

k++;

}

Send(DisplayString, k);

}

}

}

void Init(void)

{

UCTL1 &= ~SWRST; // reset swrst and usart1 enable

UCTL1 = 0x10; // 8-bit character

UBR01 = 0x03; // 8MHz 38400

UBR11 = 0x00; // 8MHz 38400

UMCTL1 = 0x4A; // U1CLK = SMCLK=TX2

UTCTL1 = 0x10;

ME2 |= 0x30; // Enable USART1 TXD/RXD

P3SEL= 0xC0; // enable P3.6,7 USART1 TXD/RXD

P3DIR= 0x40; // P3.6 output direction

IE2 |= URXIE1; // Enable USART1 RX interrupt

}

interrupt [UART1RX_VECTOR] void UART1RX(void) // read data

{

if (flag == 0) // wait for strat char of “0xAA” or “0xDD”

{

if (RXBUF1 == 0xAA) // alter flag

{

flag = 1;

}

else if (RXBUF1 == 0xDD) // alter flag

{

flag = 2;

}

i = 0;

}

else

{

ReadData[i] = RXBUF1;

if (ReadData[i++] == 0xFF) // end char of “0xFF”

{

Data = 0;

for (j=i-1; j!=0; j–)

{

Data = Data * 10 + (ReadData[j] – 0);

}

if (flag == 1) // send address

{

SendAddress(Data);

}

else if (flag == 2) // send data

{

SendData(Data);

}

flag = 0;

}

}

}

void Send(char* Data, unsigned int Length) // send data

{

unsigned int i;

UCTL1 |= TXWAKE;

TXBUF1 = 0x01;

while ((UTCTL1&0x01) == 0);

UCTL1 &= ~TXWAKE;

for(i=0; i<=Length; i++)

{

TXBUF1 = Data[i];

while ((UTCTL1&0x01) == 0);

}

}

void SendAddress(unsigned int Address) // send address

{

// address buses

P1DIR |= 0xE0; // P1.5-1.7 address buses

P2DIR = 0xFF; // P2.0-2.7 address buses

P3DIR |= 0x1F; // P3.0-3.5 address buses

P4DIR |= 0x1F; // P4.0-4.5 address buses

P1OUT |= (Address & 0x07);

P2OUT |= (Address & 0x7F8) >> 3;

P3OUT |= (Address & 0x1F800) >> 11;

P4OUT |= (Address & 0x7E0000) >> 17;

}

void SendData(unsigned int Data) // send data

{

// data buses

P4DIR |= 0xC0; // P4.6-4.7 data buses

P5DIR |= 0x1F; // P5.0-5.5 data buses

P4OUT |= (Data & 0x03);

P5OUT |= (Data & 0xFC) >> 2;

}

unsigned int ReceiveData(void) // send data

{

unsigned int Data;

// data buses

P4DIR &= 0x3F; // P4.6-4.7 data buses

P5DIR &= 0xE0; // P5.0-5.5 data buses

Data = ((P5IN & 0x1F) << 2) | ((P4IN & 0xC0) >> 6);

return Data;

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/fabu/260202.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部