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

2010-8-10 10:41 3142 12 12 分类: MCU/ 嵌入式

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


ARM单片机的功能要大大优于51单片机,而其价格已经很低了,生产厂家不论是出于广告宣传的需要,还是出于利润的角度考虑(嵌入ARM单片机将会卖更高的价格),他们更希望在自己的产品中嵌入ARM单片机。


本人使用的是周立功公司推出的Easy ARM1138开发板,它除了具有32位ARM Cortex-M3内核的LM3S1138单片机之外,还内嵌有USB接口的仿真调试器,开发调试非常方便,不愧为广大师生和工程师的首选。如下图所示。


4bfe0e72-0db2-4693-a6e0-cb6cd027172c.jpg



⒈    硬件设计


128x64LCD模块简称128x64LCM,它有的内含汉字库,有的无汉字库,有的有背光,有的无背光,本人使用的是有背光含汉字库的128x64LCM。有关该模块在本人的博文“基于51单片机的内含汉字库的LCM(一)”中进行了详述。


采用Easy ARM1138开发板与128x64LCM的硬件设计很简单,它们之间只需用13根杜邦线连接即可,如下图所示。


1f0ec6ee-5e0c-4458-9dd2-b8f5e86ac91b.jpg



由上图可以看出,本设计与“基于51单片机的内含汉字库的LCM(一)”中的设计很相似,只是将51单片机换成了ARM开发板。


 


⒉    软件设计


本设计的要求与“基于51单片机的内含汉字库的LCM(一)”相同,循环显示一首唐诗和一副电脑桌面的图形;因此其流程图也与它基本相同,如下所示。



 435e5b3b-abf5-43c6-94d5-b090cea67320.jpg


由于上述流程图与使用51单片机的流程图差不多,因此他们的程序也比较相近,如下所示。你可以把它们比较一下,这样你就可以很快进入ARM世界了。


 


//  基于《Stellaris外设驱动库》的例程


/*****************************************


**LCD128*64实验程序 ,一首唐诗和电脑桌面


**A口--数据,F0--RS,F1--RW,F2--E


******************************************/


//  包含必要的头文件


#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 uint unsigned int


#define uchar unsigned char


 


//  定义全局的系统时钟变量


unsigned long  TheSysClock  =  12000000UL;


 


//  延时


void  Delay(unsigned long  ulVal)


{


    while ( --ulVal  !=  0 );


}


 


//LCD复位


void reset(void)


{


  int i;


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


  {


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x01<<2) ;  //E1


    GPIOPinWrite(GPIO_PORTA_BASE,0xFF,0x30) ;  //送30H


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x01<<1) ;  //RW1


   }


}   


    


//LCD命令写


void comm(uchar a)


{


  Delay(2 * (TheSysClock / 4000));   //2ms


  //GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x01<<2) ;  //E1


  GPIOPinWrite(GPIO_PORTA_BASE,0xFF,a);  //GPIOA口出a


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x02) ;  //RW1


}


 


//LCD数据写


void dataa(uchar a)


{


  Delay(2* (TheSysClock / 4000));    //2ms


  //GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x04) ;  //E1


  GPIOPinWrite(GPIO_PORTA_BASE,0xFF,a);  //GPIOA口出a


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x02) ;  //RW1


}


 


//  系统初始化


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


}


 


uint tab1[]=


{   //朝辞白帝彩云间,


0xb3,0xaf,0xb4,0xc7,0xb0,0xd7,0xb5,0xdb,


0xb2,0xca,0xd4,0xc6,0xbc,0xe4,0xa3,0xac


};


uint tab2[]=


{     //千里江陵一日还,


0xc7,0xa7,0xc0,0xef,0xbd,0xad,0xc1,0xea,


0xd2,0xbb,0xc8,0xd5,0xbb,0xb9,0xa3,0xac


};


uint tab3[]=


{     //两岸猿声啼不住,


0xc1,0xbd,0xb0,0xb6,0xd4,0xb3,0xc9,0xf9,


0xcc,0xe4,0xb2,0xbb,0xd7,0xa1,0xa3,0xac


};


uint tab4[]=


{     //轻舟已过万重山。


0xc7,0xe1,0xd6,0xdb,0xd2,0xd1,0xb9,0xfd,


0xcd,0xf2,0xd6,0xd8,0xc9,0xbd,0xa1,0xa3


};


 


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


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,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF0,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x18,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xDC,0x00,0x01,


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


0x80,0x00,0x00,0x18,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xEF,0x00,0x00,0x01,


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


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


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


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


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


0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0xFF,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x01,


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


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


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


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


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


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


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


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


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


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


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


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


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


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


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


};


 


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


void display_photo()


{


  uchar i,j,k=0x80;


  comm(0x3c);       //功能设置--8BIT控制,绘图OFF


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


  {


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


    k=k+1;


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


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


    {


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


    }


  }


  k=0x80;


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


  {


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


    k=k+1;


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


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


    {


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


    }


  }


  comm(0x38);       //8位


  comm(0x01);       //清屏


  comm(0x3e);       //功能设置--8BIT控制,绘图ON(显示图形)


}


 


//  主函数(程序入口)


int  main(void)


{


  SystemInit();                             //  系统初始化


  SysCtlPeriEnable(SYSCTL_PERIPH_GPIOA);    //使能GPIOA口外设


  GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  SysCtlPeriEnable(SYSCTL_PERIPH_GPIOF);    //使能GPIOF口外设


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


  while(1)


  {


    reset();                              //LCD复位


    comm(0x01);                    //清除显示


    comm(0x38);                    //功能设置,8位四行


    comm(0x0c);                    //显示开关设置,开显示


    comm(0x80);                    //DDRAM第一行的首地址


    int i;


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


    {


      dataa(tab1);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x90);                    //DDRAM第二行的首地址 


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


    {


      dataa(tab2);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x88);                    //DDRAM三行的首地址 


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


    {


      dataa(tab3);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x98);                    //DDRAM第四行的首地址 


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


    {


      dataa(tab4);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    Delay(1000 * (TheSysClock / 4000));      //  延时约1s


    display_photo();


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


  }


}


 


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


 


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


ARM单片机的功能要大大优于51单片机,而其价格已经很低了,生产厂家不论是出于广告宣传的需要,还是出于利润的角度考虑(嵌入ARM单片机将会卖更高的价格),他们更希望在自己的产品中嵌入ARM单片机。


本人使用的是周立功公司推出的Easy ARM1138开发板,它除了具有32位ARM Cortex-M3内核的LM3S1138单片机之外,还内嵌有USB接口的仿真调试器,开发调试非常方便,不愧为广大师生和工程师的首选。如下图所示。



⒈    硬件设计


128x64LCD模块简称128x64LCM,它有的内含汉字库,有的无汉字库,有的有背光,有的无背光,本人使用的是有背光含汉字库的128x64LCM。有关该模块在本人的博文“基于51单片机的内含汉字库的LCM(一)”中进行了详述。


采用Easy ARM1138开发板与128x64LCM的硬件设计很简单,它们之间只需用13根杜邦线连接即可,如下图所示。



由上图可以看出,本设计与“基于51单片机的内含汉字库的LCM(一)”中的设计很相似,只是将51单片机换成了ARM开发板。


 


⒉    软件设计


本设计的要求与“基于51单片机的内含汉字库的LCM(一)”相同,循环显示一首唐诗和一副电脑桌面的图形;因此其流程图也与它基本相同,如下所示。



 


由于上述流程图与使用51单片机的流程图差不多,因此他们的程序也比较相近,如下所示。你可以把它们比较一下,这样你就可以很快进入ARM世界了。


 


//  基于《Stellaris外设驱动库》的例程


/*****************************************


**LCD128*64实验程序 ,一首唐诗和电脑桌面


**A口--数据,F0--RS,F1--RW,F2--E


******************************************/


//  包含必要的头文件


#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 uint unsigned int


#define uchar unsigned char


 


//  定义全局的系统时钟变量


unsigned long  TheSysClock  =  12000000UL;


 


//  延时


void  Delay(unsigned long  ulVal)


{


    while ( --ulVal  !=  0 );


}


 


//LCD复位


void reset(void)


{


  int i;


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


  {


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x01<<2) ;  //E1


    GPIOPinWrite(GPIO_PORTA_BASE,0xFF,0x30) ;  //送30H


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x01<<1) ;  //RW1


   }


}   


    


//LCD命令写


void comm(uchar a)


{


  Delay(2 * (TheSysClock / 4000));   //2ms


  //GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x01<<2) ;  //E1


  GPIOPinWrite(GPIO_PORTA_BASE,0xFF,a);  //GPIOA口出a


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x02) ;  //RW1


}


 


//LCD数据写


void dataa(uchar a)


{


  Delay(2* (TheSysClock / 4000));    //2ms


  //GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x01) ;  //RS1


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x00) ;  //RW0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x04) ;  //E1


  GPIOPinWrite(GPIO_PORTA_BASE,0xFF,a);  //GPIOA口出a


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x00) ;  //E0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0,0x00) ;  //RS0


  GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0x02) ;  //RW1


}


 


//  系统初始化


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


}


 


uint tab1[]=


{   //朝辞白帝彩云间,


0xb3,0xaf,0xb4,0xc7,0xb0,0xd7,0xb5,0xdb,


0xb2,0xca,0xd4,0xc6,0xbc,0xe4,0xa3,0xac


};


uint tab2[]=


{     //千里江陵一日还,


0xc7,0xa7,0xc0,0xef,0xbd,0xad,0xc1,0xea,


0xd2,0xbb,0xc8,0xd5,0xbb,0xb9,0xa3,0xac


};


uint tab3[]=


{     //两岸猿声啼不住,


0xc1,0xbd,0xb0,0xb6,0xd4,0xb3,0xc9,0xf9,


0xcc,0xe4,0xb2,0xbb,0xd7,0xa1,0xa3,0xac


};


uint tab4[]=


{     //轻舟已过万重山。


0xc7,0xe1,0xd6,0xdb,0xd2,0xd1,0xb9,0xfd,


0xcd,0xf2,0xd6,0xd8,0xc9,0xbd,0xa1,0xa3


};


 


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


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,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF0,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x18,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xDC,0x00,0x01,


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


0x80,0x00,0x00,0x18,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xEF,0x00,0x00,0x01,


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


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


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


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


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


0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0xFF,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x01,


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


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


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


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


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


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


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


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


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


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


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


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


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


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,


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


};


 


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


void display_photo()


{


  uchar i,j,k=0x80;


  comm(0x3c);       //功能设置--8BIT控制,绘图OFF


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


  {


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


    k=k+1;


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


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


    {


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


    }


  }


  k=0x80;


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


  {


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


    k=k+1;


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


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


    {


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


    }


  }


  comm(0x38);       //8位


  comm(0x01);       //清屏


  comm(0x3e);       //功能设置--8BIT控制,绘图ON(显示图形)


}


 


//  主函数(程序入口)


int  main(void)


{


  SystemInit();                             //  系统初始化


  SysCtlPeriEnable(SYSCTL_PERIPH_GPIOA);    //使能GPIOA口外设


  GPIOPinTypeOut(GPIO_PORTA_BASE ,0xFF);    //GPIOA为输出


  SysCtlPeriEnable(SYSCTL_PERIPH_GPIOF);    //使能GPIOF口外设


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


  while(1)


  {


    reset();                              //LCD复位


    comm(0x01);                    //清除显示


    comm(0x38);                    //功能设置,8位四行


    comm(0x0c);                    //显示开关设置,开显示


    comm(0x80);                    //DDRAM第一行的首地址


    int i;


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


    {


      dataa(tab1);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x90);                    //DDRAM第二行的首地址 


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


    {


      dataa(tab2);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x88);                    //DDRAM三行的首地址 


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


    {


      dataa(tab3);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    comm(0x98);                    //DDRAM第四行的首地址 


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


    {


      dataa(tab4);


      Delay(150 * (TheSysClock / 4000));      //  延时约0.15s


    }


    Delay(1000 * (TheSysClock / 4000));      //  延时约1s


    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)。实物图片如下所示。



3  软件调试


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


add423c9-68ab-45c9-887b-2ba1d435c641.JPG


ca0e85c5-c254-41f6-834d-d7aecede13eb.JPG


PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
12
关闭 站长推荐上一条 /3 下一条