stm32驱动12864液晶显示程序
#include "stm32f10x_lib.h"
#define uint unsigned int
#define uchar unsigned char
#define RSH GPIO_SetBits(GPIOA,GPIO_Pin_0)
#define RSL GPIO_ResetBits(GPIOA,GPIO_Pin_0)
#define RWH GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define RWL GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define ENH GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define ENL GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define CS1H GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define CS1L GPIO_ResetBits(GPIOA,GPIO_Pin_3)
#define CS2H GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define CS2L GPIO_ResetBits(GPIOA,GPIO_Pin_4)
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void Delay();
uchar table[][16]={
/*-- 文字: 我 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20,0x20,0x00,
0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40,0xF0,0x00,/*-- 文字: 爸 --*/
/*-- 文字: 一 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 天 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,
0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00,
/*-- 文字: 的 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,
0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00,
/*-- 文字: 成 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00,
0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00,
/*-- 文字: 果 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x3E,0x2A,0x2A,0x2A,0xFE,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x09,0x11,0x31,0x11,0x00,
};
void Write_cmd_left(uchar cmd)
{
RSL;
RWL;
CS1H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS1L;
}
void Write_cmd_right(uchar cmd)
{
RSL;
RWL;
CS2H;
GPIO_Write(GPIOF,cmd);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS2L;
}
void Write_data_left(uchar data)
{
RSH;
RWL;
CS2L;
CS1H;
GPIO_Write(GPIOF,data);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS1L;
}
void Write_data_right(uchar data)
{
RSH;
RWL;
CS1L;
CS2H;
GPIO_Write(GPIOF,data);
ENL;
Delay(50);
ENH;
Delay(50);
ENL;
Delay(50);
CS2L;
}
void led_disp(uchar *p,uchar lr)
{
uchar i,cl,cr;
if(lr==L)
{
for(i=0;i<16;i++)
{
cl=*p;
p++;
Write_data_left(cl);
}
}
if(lr==R)
{
for(i=0;i<16;i++)
{
cr=*p;
p++;
Write_data_right(cr);
}
}
}
void clear()
{
uchar i,j,disp_page;
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_left(disp_page);
Write_cmd_left(0x40);
for(j=0;j<64;j++)
Write_data_left(0x00);
}
for(i=0;i<8;i++)
{
disp_page=0xb8+i;
Write_cmd_right(disp_page);
Write_cmd_right(0x40);
for(j=0;j<64;j++)
Write_data_right(0x00);
}
}
void init()
{
Write_cmd_left(0x30);
Delay(10);
Write_cmd_right(0x30);
Delay(10);
Write_cmd_left(0x3f);
Delay(10);
Write_cmd_right(0x3f);
Delay(10);
Write_cmd_left(0xc0);
Delay(10);
Write_cmd_right(0xc0);
}
int main(void)
{
/* Infinite loop */
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
clear();
Delay(10);
init();
Delay(10);
uchar i;
while(1)
{
Write_cmd_left(0xb8);
Write_cmd_left(0x40);
for(i=0;i<4;i++)
led_disp(table[2*i],L);
Write_cmd_left(0xb8+1);
Write_cmd_left(0x40);
for(i=0;i<4;i++)
led_disp(table[2*i+1],L);
Write_cmd_right(0xb8);
Write_cmd_right(0x40);
for(i=0;i<2;i++)
led_disp(table[2*i+8],R);
Write_cmd_right(0xb8+1);
Write_cmd_right(0x40);
for(i=0;i<2;i++)
led_disp(table[2*i+9],R);
stm3212864液晶显示程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)