本帖最后由 nwx8899 于 2011-11-18 11:58 编辑
11.12接到21IC的EK-LM3S811 EVALUATION BOARD,非常开心,。非常感谢TI,感谢21IC,感谢这次活动的举办者。本人目前大三,在次之前只用51单片机做过东西,对于ARM来说,我是初学者,对于LM3S811来说那就更陌生了。当我打开光盘的时候我有点不知所措,但出于对ARM兴趣,对LM3S811的好奇,自己还是硬着头皮看下去,慢慢来吧!自己的硬件及编程基础薄弱,所以对于TI M3 – Stellaris的学习只能慢慢来,一步一个脚印吧,希望大家见谅,同时对于自己的错误部分,希望大家能够指正、交流学习!
第一步:从第一个例子开始吧!
首先安装驱动,安装光盘里的下载软件,顺承51的KEIL以及光盘中的LM Flash Programmer。然后找到MDK安装文件下(D:\Keil\ARM\Boards\Luminary\ek-lm3s811\blinky)自带的测试程序,把其中的2000改成20000后LED的闪烁变慢了。这一刻证明EK_LM3S811 BOARD 与我的电脑连起来了,第一步已经成功了。
第二步:找关于LM3S系列的资料,下载LM3S的中文资料,以及API函数的用法。论坛里有很多有用的资料,但个人觉得在电脑上看时间长了就不行了,还是推荐一本从图书馆借的书吧。
第三步:自己的第一个简单程序(关于12864液晶的串行显示)。
//包含头文件
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "cpu.h"
#include "interrupt.h"
#include "hw_timer.h"
#include "debug.h"
#ifndef uchar
#define uint unsigned int
#define uchar unsigned char
#endif
//定义接口
#define CS GPIO_PIN_3 //PD0 PWMO PD1 PWM1
#define SID GPIO_PIN_2
#define SCLK GPIO_PIN_4
uchar image[]={
0x02,0x08,0x00,0x08,0x00,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xD0,0x06,0x04,0x08,0x03,0x02,0x00,0x38,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x41,0x00,0x09,0x43,0x00,0x04,0xA1,0x80,0x41,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x42,0x00,0x29,0x00,0x00,0x14,0x80,0x00,0x8E,0x00,0xE7,0x00,0x00,0x00,0x00,0x00,
0x32,0x88,0x29,0x30,0x04,0x14,0x98,0x00,0x70,0x00,0x1C,0x80,0x00,0x00,0x00,0x00,
0x0C,0x00,0x16,0x48,0x00,0x0B,0x24,0x00,0x20,0x00,0x08,0x60,0x00,0x00,0x00,0x00,
0x00,0x20,0x4D,0x80,0x00,0x26,0xC0,0x00,0x40,0x00,0x08,0x10,0x00,0x00,0x00,0x00,
0x40,0x20,0x00,0x10,0x00,0x00,0x08,0x00,0x4C,0x00,0x08,0x10,0x00,0x00,0x00,0x00,
0x04,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x08,0x20,0x00,0x00,0x00,0x00,
0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x08,0x09,0xC0,0x00,0x00,0x00,0x00,
0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x40,0x00,0x00,0x00,0x00,
0x25,0x3F,0xC3,0xFE,0x3F,0xE0,0x00,0x01,0x10,0x04,0x00,0x40,0x00,0x00,0x00,0x00,
0xA4,0x08,0x40,0x20,0x00,0x41,0x80,0x01,0x10,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
0xA4,0xC8,0x47,0xFF,0x00,0x83,0xC0,0x01,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,
0x59,0x28,0x40,0x20,0x03,0x03,0xC0,0x02,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,
0x36,0x08,0x81,0xFC,0x02,0x03,0xC0,0x02,0xF0,0x40,0x10,0x20,0x00,0x00,0x00,0x00,
0x00,0x44,0x81,0x24,0x02,0x01,0x80,0x05,0x0C,0x04,0x10,0x20,0x00,0x00,0x00,0x00,
0x00,0x05,0x01,0xFC,0x02,0x01,0x80,0x05,0x42,0x00,0x14,0x40,0x00,0x00,0x00,0x00,
0x00,0x02,0x01,0x24,0x02,0x00,0x00,0x05,0x51,0x00,0x1C,0x40,0x00,0x00,0x00,0x00,
0x00,0x05,0x03,0xFE,0x02,0x01,0x80,0x04,0x91,0x03,0xC0,0x40,0x00,0x00,0x00,0x00,
0x00,0x18,0xC0,0x20,0x02,0x01,0x80,0x04,0x61,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x02,0x60,0x37,0xFF,0x0E,0x00,0x00,0x04,0x1E,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x40,0x7F,0xF4,0x0A,0x3B,0xF3,0xFE,0x01,0x01,0xF0,0x01,0x00,0x00,0x00,0x00,0x00,
0x38,0x05,0x02,0x0A,0x2A,0x90,0x04,0x00,0xC7,0xF8,0x02,0x00,0x00,0x00,0x00,0x00,
0x04,0x3F,0xE2,0xFF,0x2A,0x90,0x08,0x00,0x70,0xF8,0x04,0x00,0x00,0x00,0x00,0x00,
0x20,0x25,0x20,0x88,0x3A,0x90,0x30,0x00,0xC7,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x3F,0xE2,0xF9,0x2B,0xF0,0x20,0x01,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x02,0x89,0x2A,0x00,0x20,0x02,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
0x41,0x7F,0xF4,0xFA,0x3A,0x00,0x20,0x04,0x48,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x18,0x08,0x84,0xD4,0x2A,0x00,0x20,0x08,0x80,0x08,0x00,0x80,0x00,0x00,0x00,0x00,
0x20,0x1D,0x05,0x75,0x2A,0x10,0x20,0x09,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
0x40,0x03,0x85,0x4B,0x4A,0x10,0x20,0x12,0x30,0x00,0x80,0x40,0x00,0x00,0x00,0x00,
0x50,0x7C,0x62,0x11,0x5B,0xF0,0xE0,0x13,0x8F,0xC0,0x80,0x20,0x00,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x78,0x3F,0x00,0x20,0x00,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x03,0xC0,0x80,0x20,0x00,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x0F,0x80,0x20,0x00,0x00,0x00,0x00,
0x84,0x80,0x00,0x1C,0x08,0x0E,0x04,0x28,0x00,0x00,0x40,0x20,0x00,0x00,0x00,0x00,
0x04,0x1C,0x08,0x22,0x00,0x11,0x00,0x18,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00,
0x02,0x22,0x00,0x21,0x00,0x10,0x80,0x08,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00,
0xA1,0xA1,0x00,0x24,0xE0,0x12,0x70,0x10,0x00,0x00,0x30,0x20,0x00,0x00,0x00,0x00,
0x80,0x24,0xE0,0x18,0x10,0x0C,0x08,0x10,0x00,0x00,0x28,0x20,0x00,0x00,0x00,0x00,
0x98,0x18,0x10,0x00,0x80,0x80,0x40,0x10,0x08,0x00,0x25,0xE0,0x00,0x00,0x00,0x00,
0x24,0x00,0x81,0x00,0x00,0x80,0x00,0x1A,0x08,0x00,0x22,0x20,0x00,0x00,0x00,0x00,
0xC1,0x00,0x00,0x00,0x00,0x00,0x00,0x1D,0x46,0x00,0x22,0xA0,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x01,0x04,0x00,0x82,0x0F,0x93,0x40,0x21,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
void delay(uint t)
{
uint i,j;
for(i=0; i<t; i++)
for(j=0; j<10; j++);
}
//发送一个字节
/********************************************************************
* 名称 : sendbyte()
* 功能 : 按照液晶的串口通信协议,发送数据
* 输入 : zdata
* 输出 : 无
***********************************************************************/
void sendbyte(uchar zdata)
{
uint i;
for(i=0;i<8;i++)
{
if((zdata<<=i)&0x80)
{
GPIOPinWrite(GPIO_PORTD_BASE,SID,SID);
}
else
{
GPIOPinWrite(GPIO_PORTD_BASE,SID,~SID);
}
delay(1);
GPIOPinWrite(GPIO_PORTD_BASE,SCLK,SCLK);
GPIOPinWrite(GPIO_PORTD_BASE,SCLK,~SCLK);
delay(1);
}
}
//写数据或命令
void write(uchar dat,uchar cmd)
{
uchar temp,com;
GPIOPinWrite(GPIO_PORTD_BASE,CS,CS)
;
delay(2);
if(cmd==0)
com=0xF8;
else
com=0xFA;
sendbyte(com);
temp=dat&0xf0;
sendbyte(temp);
temp=((dat&0XF0)<<4)&0xf0;
sendbyte(temp);
delay(20);
GPIOPinWrite(GPIO_PORTD_BASE,CS,~CS) ;
}
//设置坐标
void setxy(uchar x,uchar y)
{
switch(y)
{
case 0:write(0x80+x,0);break;
case 1:write(0x88+x,0);break;
case 2:write(0x90+x,0);break;
case 3:write(0x98+x,0);break;
default: break;
}
}
//写字串
void writestr(uchar x,uchar y,uchar *str)
{
uchar lcdtemp;
setxy(x,y);
lcdtemp=*str;
while(lcdtemp!= 0)
{
write(lcdtemp,1);
lcdtemp=*(++str);
}
}
//画图
void photodisplay(uchar *bmp)
{
uchar i,j;
write(0x34,0); //写数据时,关闭图形显示
for(i=0;i<32;i++)
{
write(0x80+i,0); //先写入水平坐标值
write(0x80,0); //写入垂直坐标值
for(j=0;j<16;j++) //再写入两个8位元的数据
write(*bmp++,1);
delay(1);
}
for(i=0;i<32;i++)
{
write(0x80+i,0);
write(0x88,0);
for(j=0;j<16;j++)
write(*bmp++,1);
delay(1);
}
write(0x36,0); //写完数据,开图形显示
}
//初始化液晶
/********************************************************************
* 名称 : lcdinit()
* 功能 : 初始化函数
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void lcdinit()
{
GPIOPinWrite(GPIO_PORTD_BASE,CS,CS)
;
delay(100);
write(0x30,0);
delay(50);
write(0x0c,0);
delay(50);
write(0x06,0);
delay(50);
write(0x01,0);
delay(50);
}
//主函数
int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN
|
SYSCTL_XTAL_6MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIODirModeSet(GPIO_PORTD_BASE,CS|SID|SCLK,GPIO_DIR_MODE_OUT);
delay(100);
lcdinit();
delay(100);
photodisplay(image) ;//显示图片
writestr(0,3,"感谢21 IC ! !");
while(1);
}
最后的效果:
小结:以上就是本人对LM3S811入门的一些心得,望大家指点。谢谢。对于进一步的琢磨,只能随着时间慢慢来了。再次感谢二姨给我这次学习的机会。谢谢!!! |