495005638

495005638

0个粉丝

22

问答

0

专栏

38

资料

495005638  发布于  2013-08-25 10:12:53
采纳率 0%
22个问答
3841

STM32 12864液晶程序 调试通过、、

 

/***************************************************
本人最近开发一个项目,用到以KS0108为控制芯片的12864点阵LCD液晶模块,
为加快开发进度,本人想到网上找该模块的STM32程序,可是找了好久,没有找到,
只能自己写,这些子程序是本人调试通过的,本程序适用于以KS0108或兼容芯片为
控制器的双屏结构的液晶模块,项目还没做完,先把子程序分享给大家,仅供参考......


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

#include "stm32f10x.h"

#define LCD_E1       GPIOC->BSRR = GPIO_Pin_12 //PC12
#define LCD_E0       GPIOC->BRR  = GPIO_Pin_12  

#define LCD_DI1      GPIOG->BSRR = GPIO_Pin_13 //PG
#define LCD_DI0      GPIOG->BRR  = GPIO_Pin_13
  
#define LCD_RW1      GPIOE->BSRR = GPIO_Pin_4 //PE4
#define LCD_RW0      GPIOE->BRR  = GPIO_Pin_4

#define LCD_RST1     GPIOG->BSRR = GPIO_Pin_12 //PG12
#define LCD_RST0     GPIOG->BRR  = GPIO_Pin_12

#define LCD_CS11     GPIOC->BSRR = GPIO_Pin_10 //PC10
#define LCD_CS10     GPIOC->BRR  = GPIO_Pin_10

#define LCD_CS21     GPIOC->BSRR = GPIO_Pin_11 //PC11
#define LCD_CS20     GPIOC->BRR  = GPIO_Pin_11

#define LCD_PORT             GPIOD
#define LCD_DISP_ON     0x3F
#define LCD_DISP_OFF    0x3E
#define LCD_DISP_ROW    0xC0
#define LCD_DISP_PAGE   0xB8
#define LCD_DISP_Y      0x40

GPIO_InitTypeDef GPIO_InitStructure;

void Delayms(uint32_t ms)
{
    //uint32_t temp;
    uint32_t  i, j;

    for( i = ms; i > 0; i-- )
    {
        for( j = 7200 ; j > 0 ; j-- )
        {}
    }
}

void LCD_Configuration(void)
{
GPIO_InitStructure.GPIO_Pin

=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7

;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LCD_PORT, &GPIO_InitStructure);      // PORTD 为开漏输出

        GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);  

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOE, &GPIO_InitStructure);  

        GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_12|GPIO_Pin_13);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOG, &GPIO_InitStructure);  
    Delayms(1);
}

void LCD_reset(void)
{
  LCD_E0;
  Delayus(10);
  LCD_RST0;
  Delayms(2);
  LCD_RST1;
  Delayms(200);
}
void LCD_CS(u8 index) //0--select none 1--left 2--right 3--all
{
        switch(index)
        {
        case 0:
        LCD_CS11;
        LCD_CS21;
        break;
        case 1:
        LCD_CS10;
        LCD_CS21;
        break;
        case 2:
        LCD_CS11;
        LCD_CS20;
        break;
        case 3:
        LCD_CS10;
        LCD_CS20;
        break;
        }        
        Delayus(100);
}

void LCD_Check_Busy(void)
{  
    //GPIO_InitTypeDef GPIO_InitStructure;
    u8 temp=0;
     
    LCD_DI0;  // DI =0 指令
    LCD_RW1;    // RW =1  读模式
     
    // 第7位读状态
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LCD_PORT, &GPIO_InitStructure);
    Delayus(1);
    do{
        LCD_E1;
                Delayus(1);
                temp = GPIO_ReadInputDataBit(LCD_PORT, GPIO_Pin_7);
                LCD_E0;
                Delayus(1);
               

                 
    }while(temp);//等待不忙
  LCD_E0;   
  //--------把D7 设为输出
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_PORT, &GPIO_InitStructure);
  Delayus(1);
  //---------------------
}



void LCD_cmd(vu8 portValue)
{  
u16 tmpData;  
LCD_Check_Busy();
LCD_RW0;
LCD_DI0;
tmpData = GPIO_ReadOutputData(LCD_PORT); // 读端口数据
tmpData &= 0xFF00;                       // 清掉低8位
GPIO_Write(LCD_PORT, (tmpData|((u16)portValue)));
Delayus(1);
LCD_E1;
Delayus(1);
LCD_E0;
Delayus(1);  
}
vu8 LCD_rd(void)//在写地址后,要进行一次空读,以后每读一次地址自动加1
{
vu8 rdata;
LCD_Check_Busy();
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //低8位输入
GPIO_InitStructure.GPIO_Pin

=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7

;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_PORT, &GPIO_InitStructure);

LCD_RW1; //READ
LCD_DI1; //DATA
Delayus(1);
LCD_E1;
Delayus(5);
rdata=GPIO_ReadInputData(LCD_PORT);  
LCD_E0;
Delayus(1);
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Pin

=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7

;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
//GPIO_InitStructure.GPIO_Pin =0x00FF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LCD_PORT, &GPIO_InitStructure);      
Delayus(1);
return rdata;
}

void LCD_wd(vu8 portValue)
{
u16 tmpData;
LCD_Check_Busy();//LEFT OR RIGHT
LCD_RW0; //WRITE
LCD_DI1; //DATA
tmpData = GPIO_ReadOutputData(LCD_PORT); // 读端口数据
tmpData &= 0xFF00;                       // 清掉低8位
GPIO_Write(LCD_PORT,(tmpData|((u16)portValue)));     // 写数据到端口

Delayus(1);
LCD_E1;
Delayus(1);  
LCD_E0;
Delayus(1);

}

void LCD_rwd(u8 row,u8 page,u8 dat,u8 mode)//读修改写模式 page 0~7 row 0~127
{
vu8 rd;
if(row<64)
        {
        LCD_CS(1);
        LCD_cmd(LCD_DISP_PAGE+page);        //定位页
        LCD_cmd(LCD_DISP_Y+row);//定位列
        rd=LCD_rd();//空读
        rd=LCD_rd();
        LCD_cmd(LCD_DISP_PAGE+page);        //定位页
        LCD_cmd(LCD_DISP_Y+row);//定位列
        if(mode==0)
        LCD_wd(dat);
        else if(mode==1)
        LCD_wd(dat|rd);//或模式
        else if(mode==2)
        LCD_wd(dat&rd);//与模式
        else
        LCD_wd(~rd);//取反
        }
else
        {
        LCD_CS(2);
        LCD_cmd(LCD_DISP_PAGE+page);        //定位页
        LCD_cmd(LCD_DISP_Y+row-64);//定位列
        rd=LCD_rd();//空读
        rd=LCD_rd();
        LCD_cmd(LCD_DISP_PAGE+page);        //定位页
        LCD_cmd(LCD_DISP_Y+row-64);//定位列
        if(mode==0)
        LCD_wd(dat);
        else if(mode==1)
        LCD_wd(dat|rd);//或模式
        else if(mode==2)
        LCD_wd(dat&rd);//与模式
        else
        LCD_wd(~rd);//取反
        }
}

void LCD_init()
{   
    LCD_CS(3);//选左屏 右屏
        LCD_cmd(LCD_DISP_PAGE);//0xb8
    Delayms(5);
        LCD_cmd(LCD_DISP_Y);  //0x40
    Delayms(5);  
        LCD_cmd(LCD_DISP_ROW);//START LINE 0xc0
        Delayms(5);
    LCD_cmd(LCD_DISP_ON); //0x3f
        Delayms(5);
}
void LCD_Clear(void)
{
u8 page,count;
for(page=0xb8;page<=0xbF;page++)//共8 页,0XB8-0XBF
{
        LCD_cmd(page);
        LCD_cmd(0x40);
        for(count=64;count>0;count--)//写第page 页的左64 列
        {
        LCD_wd(0X00);
        }
}   

}
void LCD_Pixe(u8 x,u8 y)//画点程序
{          /*
    vu8 rd;

        if(x<64)
        {
        LCD_CS(1);
        LCD_cmd(LCD_DISP_PAGE+y/8);        //定位页
        LCD_cmd(LCD_DISP_Y+x);//定位列
        rd=LCD_rd();//空读
        rd=LCD_rd();
        LCD_cmd(LCD_DISP_PAGE+y/8);        //定位页
        LCD_cmd(LCD_DISP_Y+x);//定位列
    LCD_wd((1<<(y%8))|rd);
        }
    else
        {
        LCD_CS(2);
        LCD_cmd(LCD_DISP_PAGE+y/8);        //定位页
        LCD_cmd(LCD_DISP_Y+x-64);//定位列
        rd=LCD_rd();//空读
        rd=LCD_rd();
        LCD_cmd(LCD_DISP_PAGE+y/8);        //定位页
        LCD_cmd(LCD_DISP_Y+x-64);//定位列
    LCD_wd((1<<(y%8))|rd);

        }
        */
        LCD_rwd(x,y/8,(1<<(y%8)),1);

}
//画横线程序
void LCD_H_Line(u8 x1,u8 y1, u8 len,u8 weight)  //len 0~128
{
  u8 i,p,dat,xx;
  p=y1/8;
  dat=((1<
  for(i=0;i   {
  xx=x1+i;
  if(xx>127) xx=127;//超过屏幕边沿剪断
  LCD_rwd(xx,p,dat,1);
  }
}
//画坚线程序
void LCD_V_Line(u8 x1,u8 y1,u8 len,u8 weight) //len 0~64
{
  u8 i,j,p,xx,yy,dat=0;
  for(j=0;j   {
          for(i=0;i           {
          yy=y1+i;
          if(yy>63) yy=63;//超过屏幕边沿剪断
          p=yy/8;
          dat|=(1<<(yy%8));//
          if((yy+1)%8==0||(i==len));
          {
          xx=x1+j;
          if(xx>127) xx=127;//超过屏幕边沿剪断
          LCD_rwd(xx,p,dat,1);
          dat=0;
          }
          }
  }

}
我来回答
回答1个
时间排序
认可量排序

ljc2010

0个粉丝

42

问答

0

专栏

74

资料

ljc2010 2013-08-25 10:41:33
认可0
感谢楼主  先试试了。
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区