找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2227|回复: 1
打印 上一主题 下一主题
收起左侧

stm32_19264液晶LCD驱动程序

[复制链接]
跳转到指定楼层
楼主
ID:629252 发表于 2019-10-24 09:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#ifndef__LCD_H
#define __LCD_H  
#include "sys.h"
#define LCD_RS  PFout(0)// PF.0
#define LCD_E   PFout(1)// PF.1
#define LCD_CS1 PFout(2)// PF.2
#define LCD_RST PFout(3)// PF.3
#define LCD_CS2 PFout(4)// PF.4
#define LCD_CS3 PFout(5)// PF.5
#define LCD_DATA(x)  GPIOE->ODR=(GPIOB->ODR&0x807F)|((x &0x00FF)<<7) //PE7~14,
作为数据线
#define LCD_PAGE_ADDR 0xb8
#define LCD_COL_ADDR  0x40   
void LCDPortSet(void); //LCD IO口配置
void LcdInit(void);   //初始化程序
void LcdClear(void); //清屏程序
void WriteChr16x16(u8 pag,u8 col, u8  *chr); //写一个汉字   
#endif

/******************************************************lcd.c************************************************/
#include <stm32f10x_lib.h>   
#include "lcd.h"
#include "delay.h"
//LCD IO口配置
void LCDPortSet(void)
{

RCC->APB2ENR|=1<<6;      //使能PORTE时钟
RCC->APB2ENR|=1<<7;      //使能PORTF时钟
GPIOE->CRH&=0XF0000000;//PE8-14数据口
GPIOE->CRH|=0X03333333;
GPIOE->CRL&=0X0FFFFFFF;//PE7数据口
GPIOE->CRL|=0X30000000;  
GPIOE->ODR|=0X7F80;      //上拉
GPIOF->CRL&=0XF0000000;
GPIOF->CRL|=0X03333333;  //PF.0 1 2 3 4 5 6推挽输出
GPIOF->ODR|=1<<0;      //PF.0 输出高
GPIOF->ODR|=1<<1;      //PF.1 输出高
GPIOF->ODR|=1<<2;      //PF.2 输出高
GPIOF->ODR|=1<<3;      //PF.3 输出高
GPIOF->ODR|=1<<4;      //PF.4 输出高
GPIOF->ODR|=1<<5;      //PF.5 输出高
GPIOF->ODR|=1<<6;      //PF.6 输出高
}

void SelectChip1(void) //选择第1屏
{
LCD_CS1=0;
LCD_CS2=1;
LCD_CS3=1;
}

void SelectChip2(void) //选择第2屏
{
LCD_CS1=1;
LCD_CS2=0;
LCD_CS3=1;
}
void SelectChip3(void) //选择第3屏
{
LCD_CS1=1;
LCD_CS2=1;
LCD_CS3=0;
}
void WriteCommand(u8 cmd)   //写命令
{     
LCD_RS=0;   //写命令
//RW=0;
LCD_DATA(cmd);
LCD_E=1;
delay_us(10);
LCD_E=0;
}
void WriteData(u8  dat)  //写数据
{  
        LCD_RS=1;//写数据
//RW=0;
LCD_DATA(dat);//数据输出到数据口
   LCD_E=1; //写入到LCD
   delay_us(10);
   LCD_E=0;
}

void LcdClear(void) //清屏
{
u16  j = 0;
u16  k = 0;
LCD_CS1 = 0;
LCD_CS2 = 0;
LCD_CS3 = 0;
WriteCommand(LCD_PAGE_ADDR + 0);
WriteCommand(LCD_COL_ADDR  + 0);
for(k=0;k<8;k++)
{
WriteCommand(LCD_PAGE_ADDR+k);
for(j=0;j<64;j++)  
{
WriteData(0x00);
}
}
LCD_CS1 = 1;
LCD_CS2 = 1;
LCD_CS3 = 1;
}

void LcdInit(void) //初始化程序
{
LCD_RST = 0;
delay_us(20);
LCD_RST = 1;
delay_us(5);
LCD_CS1=0;
LCD_CS2=0;
LCD_CS3=0;
WriteCommand(0x3f);  //设置开显示命令
WriteCommand(0xc0);//设置起始位置
LCD_CS1 = 1;
LCD_CS2 = 1;
LCD_CS3 = 1;
LcdClear();   //清屏
}
void WriteChr16x16(u8 pag,u8 col,u8 *chr) //写一个汉字
{
u8 i = 0;
u8 j = 0;
u8 col_t = 0;
WriteCommand(0xc0);
col_t = col;
for(i=0;i<2;i++)
{
  for(j=0;j<16;j++)
  {
switch(col_t&0xc0)
{
case 0:
SelectChip1();
WriteCommand(LCD_PAGE_ADDR + pag + i);
WriteCommand(LCD_COL_ADDR  + col_t - 0 );
WriteData(chr[16*i + j]);
col_t++;
break;
case 0x40:
SelectChip2();
WriteCommand(LCD_PAGE_ADDR + pag + i);
WriteCommand(LCD_COL_ADDR  + col_t - 64);
WriteData(chr[16*i + j]);
col_t++;
break;
case 0x80:
SelectChip3();
WriteCommand(LCD_PAGE_ADDR + pag + i);
WriteCommand(LCD_COL_ADDR  + col_t - 128);
WriteData(chr[16*i + j]);
col_t++;
break;
default:  break;
}
   
}
col_t=col_t-16;
}
}
/***************************************************main.c******************************************************/
/**
@说明:JBG19264 LCD测试程序
*/
#include <stm32f10x_lib.h>
#include "sys.h"
#include "delay.h"
#include "lcd.h"
u8 table[][32]={
/*--  文字:  我 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00,
0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00,
/*--  文字:  们 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x80,0x60,0xF8,0x07,0x00,0xF8,0x01,0x06,0x00,0x04,0x04,0x04,0xFC,0x00,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,
/*--  文字:  都 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x24,0x24,0xA4,0x7F,0x24,0x34,0x28,0x26,0x20,0xFE,0x02,0x22,0xDA,0x06,0x00,
0x04,0x02,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,
/*--  文字:  是 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,
0x81,0x41,0x21,0x1D,0x21,0x41,0x81,0xFF,0x89,0x89,0x89,0x89,0x89,0x81,0x81,0x00,
/*--  文字:  好 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x10,0xF0,0x1F,0x10,0xF0,0x00,0x80,0x82,0x82,0xE2,0x92,0x8A,0x86,0x80,0x00,
0x40,0x22,0x15,0x08,0x16,0x61,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  孩 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x02,0x02,0x02,0xF2,0x8A,0x46,0x08,0x88,0xC8,0xA8,0x99,0x8E,0x88,0x48,0x28,0x00,
0x02,0x42,0x81,0x7F,0x00,0x00,0x88,0x88,0x44,0x44,0x22,0x11,0x28,0x44,0x82,0x00,
/*--  文字:  子 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  我 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00,
0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00,
/*--  文字:  们 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x80,0x60,0xF8,0x07,0x00,0xF8,0x01,0x06,0x00,0x04,0x04,0x04,0xFC,0x00,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,
/*--  文字:  都 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x24,0x24,0xA4,0x7F,0x24,0x34,0x28,0x26,0x20,0xFE,0x02,0x22,0xDA,0x06,0x00,
0x04,0x02,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,
/*--  文字:  是 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,
0x81,0x41,0x21,0x1D,0x21,0x41,0x81,0xFF,0x89,0x89,0x89,0x89,0x89,0x81,0x81,0x00,
/*--  文字:  好 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x10,0xF0,0x1F,0x10,0xF0,0x00,0x80,0x82,0x82,0xE2,0x92,0x8A,0x86,0x80,0x00,
0x40,0x22,0x15,0x08,0x16,0x61,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00
};
int main(void)
{  
u8 i = 0;
Stm32_Clock_Init(9); //系统时钟设置8MHz * 9 = 72MHz
delay_init(72);    //延时初始化
LCDPortSet();    //LCD口设置
LcdInit(); //LCM初始化程序
delay_ms(100);
while(1)
{
LCD_DATA(0x55);
delay_us(10);
LCD_DATA(0xf0);
while(1)
{         
delay_ms(1000);
for(i=0;i<12;i++)
WriteChr16x16(0,i*16,table[ i]);
for(i=0;i<12;i++)
WriteChr16x16(2,i*16,table[ i]);
for(i=0;i<12;i++)
WriteChr16x16(4,i*16,table[ i]);
for(i=0;i<12;i++)
WriteChr16x16(6,i*16,table[ i]);
delay_ms(500);
}   
}  

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2019-10-25 03:48 | 只看该作者
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表