首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

基于ARM单片机的128x64LCM应用(串行接口)

基于ARM单片机的128x64LCM应用(串行接口)

基于ARM单片机的128x64LCM应用(串行接口)

ARM单片机是32位的,而51单片机是8位的,功能上ARM单片机要大大优于51单片机,而其价格已经很低了,从发展的眼光看,ARM单片机将会占据单片机应用的大部分份额。
本人使用的是周立功公司推出的Easy ARM1138开发板,它除了具有32位ARM Cortex-M3内核的LM3S1138单片机之外,还内嵌有USB接口的仿真调试器,开发调试非常方便。
关于128x64LCM的串行接口,在我的博文“基于51单片机的内含汉字库的LCM(二)”中已有详述,串行数据传输的时序图如下所示。


⒈    硬件设计
128x64LCM工作于串行模式时只需3根线(若LCD的CS固定接VCC,则只需2根线),包括电源共5根杜邦线与开发板相连,如下图所示。


⒉    软件设计
为了进行比较,同样要求在LCD屏上循环显示一首唐诗和电脑桌面图形,因此其流程图与“基于51单片机的内含汉字库的LCM(二)”中的基本相同,如下所示。需要注意的是,ARM单片机为了减少功耗,对于未使用的I/O口及其功能都是关闭的。


由于流程图很相近,故程序也相差不大,如下所示。可以把这两个程序放在一起进行比较,对于学习掌握ARM单片机会大有好处。

//  串行12864模块,CS-PF0,SID-PF1,SCLK-PF2
//  包含必要的头文件
#include  <hw_types.h>
#include  <hw_memmap.h>
#include  <hw_sysctl.h>
#include  <hw_gpio.h>
#include  <sysctl.h>
#include  <gpio.h>

//  将较长的标识符定义成较短的形式
#define  SysCtlPeriEnable       SysCtlPeripheralEnable
#define  SysCtlPeriDisable      SysCtlPeripheralDisable
#define  GPIOPinTypeIn          GPIOPinTypeGPIOInput
#define  GPIOPinTypeOut         GPIOPinTypeGPIOOutput

#define uchar unsigned char

//定义LCD
#define CS                GPIO_PORTF_BASE,GPIO_PIN_0
#define SID               GPIO_PORTF_BASE,GPIO_PIN_1
#define SCLK              GPIO_PORTF_BASE,GPIO_PIN_2

//  定义全局的系统时钟变量
unsigned long  TheSysClock  =  12000000UL;

//  延时
void  Delay(unsigned long  ulVal)
{
    while ( --ulVal  !=  0 );
}

//  系统初始化
void  SystemInit(void)
{
    SysCtlLDOSet(SYSCTL_LDO_2_50V);          //  设置LDO输出电压

    SysCtlClockSet(SYSCTL_USE_OSC |         //系统时钟设置,采用主振荡器
                   SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ |
                   SYSCTL_SYSDIV_1);

    TheSysClock  =  SysCtlClockGet();       //获取系统时钟,单位:Hz
}

/************************************************************
*朝辞白帝彩云间,千里江陵一日还,两岸猿声啼不住,轻舟已过万重山.
*************************************************************/
unsigned char ts[4][16]=
{
    {
0xb3,0xaf,0xb4,0xc7,0xb0,0xd7,0xb5,0xdb,0xb2,0xca,0xd4,0xc6,0xbc,0xe4,0xa3,0xac
    },

    {
0xc7,0xa7,0xc0,0xef,0xbd,0xad,0xc1,0xea,0xd2,0xbb,0xc8,0xd5,0xbb,0xb9,0xa3,0xac
    },

{
0xc1,0xbd,0xb0,0xb6,0xd4,0xb3,0xc9,0xf9,0xcc,0xe4,0xb2,0xbb,0xd7,0xa1,0xa3,0xac
    },

    {

0xc7,0xe1,0xd6,0xdb,0xd2,0xd1,0xb9,0xfd,0xcd,0xf2,0xd6,0xd8,0xc9,0xbd,0xa1,0xa3
    }
};

void send_command(uchar command_data)
{
  uchar i,i_data=0xf8;
  Delay(10 * (TheSysClock / 4000));                 //  延时约10ms
  GPIOPinWrite(CS,1);
  GPIOPinWrite(SCLK,0);
  for(i=0;i<8;i++)
  {
    if(i_data&0x80)
      GPIOPinWrite(SID,1<<1);
    else
      GPIOPinWrite(SID,0);
    GPIOPinWrite(SCLK,0);   
    GPIOPinWrite(SCLK,1<<2);  
    i_data=i_data<<1;
    }
  i_data=command_data;
  i_data&=0xf0;
  for(i=0;i<8;i++)
  {
    if(i_data&0x80)
      GPIOPinWrite(SID,1<<1);
    else
      GPIOPinWrite(SID,0);
    GPIOPinWrite(SCLK,0);   
    GPIOPinWrite(SCLK,1<<2);
    i_data=i_data<<1;
  }
  i_data=command_data;
  i_data=i_data<<4;
  for(i=0;i<8;i++)
  {
    if(i_data&0x80)
      GPIOPinWrite(SID,1<<1);
    else
      GPIOPinWrite(SID,0);
    GPIOPinWrite(SCLK,0);   
    GPIOPinWrite(SCLK,1<<2);
    i_data=i_data<<1;
  }
  GPIOPinWrite(CS,0);  
}
void send_data(uchar command_data)

{

  uchar i,i_data=0xfa;

  Delay(10 * (TheSysClock / 4000));                //  延时约10ms

  GPIOPinWrite(CS,1);

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

  {

    if(i_data&0x80)

      GPIOPinWrite(SID,1<<1);

    else

      GPIOPinWrite(SID,0);

    GPIOPinWrite(SCLK,0);   

    GPIOPinWrite(SCLK,1<<2);

    i_data=i_data<<1;

  }  

  i_data=command_data;

  i_data&=0xf0;

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

  {

    if(i_data&0x80)

      GPIOPinWrite(SID,1<<1);

    else

      GPIOPinWrite(SID,0);

    GPIOPinWrite(SCLK,0);   

    GPIOPinWrite(SCLK,1<<2);

    i_data=i_data<<1;

  }

  i_data=command_data;

  i_data=i_data<<4;

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

  {

    if(i_data&0x80)

      GPIOPinWrite(SID,1<<1);

    else

      GPIOPinWrite(SID,0);

    GPIOPinWrite(SCLK,0);   

    GPIOPinWrite(SCLK,1<<2);

    i_data=i_data<<1;

  }

  //GPIOPinWrite(CS,0);

}



void display_cpubbs()

{

  uchar command_data=0x01,m,n;

  send_command(command_data); /*清DDRAM*/

  for(m=0;m<4;m++)

  {

    switch(m)

    {

      case 0:command_data=0x80; break;

      case 1:command_data=0x90; break;

      case 2:command_data=0x88; break;

      case 3:command_data=0x98; break;

    }

    send_command(command_data);  

    for(n=0;n<16;n++)

    {

      command_data=ts[m][n];

      send_data(command_data);

    }

  }

}



/********电脑桌面数据********************/

uchar dnzm[]=

{

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF0,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x18,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xDC,0x00,0x02,

0x80,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xBC,0x00,0x02,

0x80,0x00,0x30,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0xB8,0x00,0x02,

0x80,0x00,0x30,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0x78,0x00,0x02,

0x80,0x00,0x19,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x02,0xFF,0xFF,0x70,0x00,0x02,

0x80,0x00,0x18,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xFF,0xFE,0xF0,0x00,0x02,

0x80,0x00,0x0C,0x01,0xFF,0x60,0x00,0x00,0x00,0x00,0x05,0xFF,0xFE,0xE0,0x00,0x02,

0x80,0x00,0x0C,0x7F,0xD0,0x20,0x00,0x00,0x00,0x00,0x05,0xFF,0xFD,0xE0,0x00,0x02,

0x80,0x00,0x06,0x00,0x0F,0xB0,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFD,0xC0,0x00,0x02,

0x80,0x00,0x06,0x03,0xFC,0x10,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFB,0xC0,0x00,0x02,

0x80,0x00,0x03,0x1F,0x00,0x18,0x00,0x00,0x00,0x00,0x17,0xFF,0xFB,0x80,0x00,0x02,

0x80,0x00,0x03,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x80,0x00,0x02,

0x80,0x00,0x01,0x80,0x00,0x0C,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x00,0x00,0x02,

0x80,0x00,0x01,0x80,0x00,0x04,0x00,0x00,0x00,0x00,0x09,0xFF,0xEF,0x00,0x00,0x02,

0x80,0x00,0x00,0xC0,0x00,0xF6,0x00,0x00,0x00,0x00,0x06,0x7F,0xEF,0x00,0x00,0x02,

0x80,0x00,0x00,0xC0,0x03,0xC2,0x00,0x00,0x00,0x00,0x01,0x9F,0xDE,0x00,0x00,0x02,

0x80,0x00,0x00,0x60,0x00,0x3B,0x00,0x00,0x00,0x00,0x00,0x67,0xDF,0x00,0x00,0x02,

0x80,0x00,0x00,0x60,0x00,0xE3,0x00,0x00,0x00,0x00,0x00,0x19,0xBF,0x00,0x00,0x02,

0x80,0x00,0x00,0x30,0x03,0x8E,0x00,0x00,0x00,0x00,0x00,0x06,0x3F,0x00,0x00,0x02,

0x80,0x00,0x00,0x30,0x06,0x3C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC0,0x00,0x02,

0x80,0x00,0x00,0x18,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xEF,0x00,0x00,0x02,

0x80,0x00,0x00,0x18,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x80,0x00,0x02,

0x80,0x00,0x00,0x0C,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x1F,0xC0,0x00,0x02,

0x80,0x00,0x00,0x0C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x07,0xE0,0x00,0x02,

0x80,0x00,0x00,0x06,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1F,0xE0,0x00,0x02,

0x80,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x3F,0xC0,0x00,0x02,

0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0xFF,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x05,0x40,0x88,0x04,0x01,0x08,0x00,0x00,0x0A,0x81,0x10,0x04,0x00,0x20,0x02,

0x80,0x79,0x21,0x08,0x02,0x21,0x49,0x00,0x00,0xF2,0x42,0x10,0x04,0x47,0x10,0x02,

0x80,0x09,0x07,0xDF,0x7F,0xF7,0xAA,0x00,0x00,0x12,0x0F,0xBE,0x7F,0xE5,0xFE,0x02,

0x80,0x7F,0xF4,0x51,0x08,0x81,0x2C,0x00,0x00,0xFF,0xE8,0xA2,0x44,0x47,0x00,0x02,

0x80,0x09,0x04,0x61,0x08,0x81,0x7F,0x00,0x00,0x12,0x08,0xC2,0x7F,0xC5,0x4A,0x02,

0x80,0x0B,0x24,0x51,0x08,0x83,0x81,0x00,0x00,0x16,0x48,0xA2,0x44,0x45,0x6A,0x02,

0x80,0x1D,0x47,0xC9,0x05,0x05,0x01,0x00,0x00,0x3A,0x8F,0x92,0x44,0x47,0x52,0x02,

0x80,0x68,0x84,0x49,0x05,0x05,0x7F,0x00,0x00,0xD1,0x08,0x92,0x7F,0xC5,0x6A,0x02,

0x80,0x09,0x94,0x41,0x02,0x01,0x01,0x00,0x00,0x13,0x28,0x82,0x44,0x05,0x4A,0x02,

0x80,0x0E,0x57,0xC1,0x0D,0x81,0x01,0x00,0x00,0x1C,0xAF,0x82,0x04,0x29,0x42,0x02,

0x80,0x38,0x34,0x4E,0x70,0x71,0x7F,0x00,0x00,0x70,0x68,0x9C,0x03,0xEB,0x7E,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE

};



/*********显示图形子函数**********/

void display_photo()

{

    uchar i,j,k=0x80;

    send_command(0x3c);     //设置8BIT控制,绘图OFF

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

    {

        send_command(k);        //设置绘图区的Y地址坐标

        k=k+1;

        send_command(0x80);     //设置绘图区的X地址坐标

        for(j=0;j<16;j++)

            send_data(dnzm[i*16+j]);

        }

    k=0x80;

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

    {

        send_command(k);        //设置绘图区的Y地址坐标

        k=k+1;

        send_command(0x88);     //设置绘图区的X地址坐标

        for(j=0;j<16;j++)

            send_data(dnzm[512+i*16+j]);

        }

    send_command(0x30);

    send_command(0x01);

    send_command(0x3e); //设置8BIT控制,绘图ON(显示图形)

}





//  主函数(程序入口)

int  main(void)

{

  SystemInit();                              //  系统初始化

  SysCtlPeriEnable(SYSCTL_PERIPH_GPIOF);    //使能GPIO F口外设

  GPIOPinTypeOut(GPIO_PORTF_BASE ,0xFF);    //GPIO F为输出

  Delay(100 * (TheSysClock / 4000));        //  延时约100ms

  for (;;)

  {

    send_command(0x30); /*功能设置:一次送8位数据,基本指令集*/

    send_command(0x0C); /*显示设定:开显示*/

    send_command(0x01); /*清DDRAM*/

    display_cpubbs();

    display_photo();

    Delay(3000 * (TheSysClock / 4000));        //  延时约3s

  }

}



本人使用的是IAR EWARM(IAR Embedded Workbench for ARM)集成开发环境,利用周立功公司提供的工程模板,输入以上的源程序,点击菜单“Project”→“Mark”进行编译,或按F7键,根据提示修改错误,再进行编译直至无错误为止 。



3  软件调试

编译无误后即可点击菜单“Project”→“Dbuge”下载源程序的机器码至开发板(或按Ctrl+D),同时在桌面上出现了几个调试用的快捷按钮——运行(go)、运行到光标处(Run to Cursor)、步出(Step Out)、步入(Step Into)、步越(Step Over)、停止(Break)、复位(Reset)等。通过选择上述不同的快捷按钮,以及观察变量的值(点击菜单“View”→“Watch”在Expression中输入变量名,即可在Value中看到该变量的值;或将光标悬停在某变量上,即可看到该变量的值),来调试程序,直至一切无误后即可全速运行了(点击快捷按钮go)。
返回列表