RS/CS--片选,高电平有效
RW/SID--串行数据输入端
E/SCLK-- 串行同步信号,上升沿时读取SID信号
PSB--数据传输方式选择,高电平为并行方式,低电平时为串行方式
RST--复位端,低电平有效
#ifndef __LCD12864_H
#define __LCD12864_H
//重要的也就是这4个函数了,其他的就不要管了
void lcd_init(void);
void lcd_clear(void);
void lcd_wstr(uint8_t y_add, uint8_t x_add, char *str);
void write_figer(uint8_t y_add, uint8_t x_add, uint32_t figer);
#endif
#include <SC32F5832.h>
#include <DevInit.h>
#include "LCD12864.h"
/**
* @brief LCD12864接线说明
* @param SC32F5832 -> LCD12864
* PC6 -> RS
* PC4 -> RW
* PC3 -> E
* PC7 -> PSB
* PC15 -> RST
*/
/**
* @brief Initialize the LCD12864.
* @param None
* @retval None
*/
void Delay(__IO uint32_t nCount) {
for (; nCount != 0; nCount--);
}
/**
* @brief Clear the screen.
* @param None
* @retval None
*/
void send_dat(uint8_t dat) {
uint8_t i;
for (i=0;i<8;i++) {
if((dat&0x80)==0x80)
SID_1;
if((dat&0x80)==0x00)
SID_0;
CLK_0;
Delay(350);
CLK_1;
dat<<=1;
}
}
/**
* @brief LCD12864 display words.
* @param x: row(0~3) y: line(0~7) str: the pointer to words
* @retval None
*/
void send_cmd(uint8_t cmd) {
send_dat(0xf8);
//
send_dat(cmd&0xf0);
//
send_dat((cmd&0x0f)<<4);
//
}
/**
* @brief LCD12864 display picture.
* @param pic: The pointer to the picture array.
* @retval None
*/
void write_char(uint8_t dat) {
send_dat(0xfa);
//rw=0;rs=1
send_dat(dat&0xf0);
send_dat((dat&0x0f)<<4);
}
/**
* @brief LCD12864 display picture.
* @param pic: The pointer to the picture array.
* @retval None
*/
void lcd_clear(void) //清除显示 {
send_cmd(0x01);
}
/**
* @brief LCD12864 display picture.
* @param pic: The pointer to the picture array.
* @retval None
*/
void lcd_pos(uint8_t y_add , uint8_t x_add) {
switch(y_add) {
case 1:
send_cmd(0X80|x_add);
break;
case 2:
send_cmd(0X90|x_add);
break;
case 3:
send_cmd(0X88|x_add);
break;
case 4:
send_cmd(0X98|x_add);
break;
default:break;
}
}
/**
* @brief LCD12864 display picture.
* @param pic: The pointer to the picture array.
* @retval None
*/
void lcd_wstr(uint8_t y_add , uint8_t x_add , char *str) {
uint8_t i;
lcd_pos(y_add , x_add);
for (i=0;str[i]!='\0';i++) {
write_char(str[i]);
}
}
/**
* @brief LCD12864 display picture.
* @param pic: The pointer to the picture array.
* @retval None
*/
void lcd_init(void) {
RST_0;
//液晶复位
Delay(100);
RST_1;
Delay(100);
send_cmd(0x30);
Delay(10);
send_cmd(0x0C);
//0000,1100 整体显示,游标off,游标位置off
Delay(10);
send_cmd(0x01);
//0000,0001 清DDRAM
Delay(10);
send_cmd(0x02);
//0000,0010 DDRAM地址归位
Delay(10);
send_cmd(0x80);
//1000,0000 设定DDRAM 7位地址000,0000到地址计数器A
}
/**
* @brief LCD12864 display //在任何位置写数字-数组
* @param pic: The pointer to the picture array.
* @retval None
*/
void write_figer(uint8_t y_add, uint8_t x_add, uint32_t figer){
uint8_t d[5],i,j;
lcd_pos(y_add , x_add);
d[4]=figer%10;
d[3]=figer%100/10;
d[2]=figer%1000/100;
d[1]=figer%10000/1000;
d[0]=figer/10000;
for (i=0;i<5;i++) {
if(d[i]!=0)break;
}
if(i==5)i--;
if(i==4)send_dat(0x30);
//数据装完,准备发送
for (j=i;j<5;j++) {
send_dat(d[j]|0x30);
//取得的数字加上0x30也即得到该数字的ASCII码,再将该数字发送去显示
}
}
/* Includes ------------------------------------------------------------------*/
#include <SC32F5832.h>
#include <DevInit.h>
#include "LCD12864.h"
int main(void){
Device_Init();
//液晶端口使能
PC_OUT_ENABLE(3); //E 时钟信号
PC_OUT_ENABLE(4); //RW_SID 串行数据输入
PC_OUT_ENABLE(6); //CS 片选
PC_OUT_ENABLE(7); //PSB 产品选择
PC_OUT_ENABLE(15); //RST 复位
//LED1初始化
PB_OUT_ENABLE(0);
delay_ms(100);
PSB_0; //采用串行通讯
CS_1; //片选
lcd_init();//LCD12864初始化
delay_ms(100);
lcd_clear();//清屏
delay_ms(100);
lcd_wstr(1, 1, "科技");//字符显示
lcd_wstr(2, 0, "LCD12864液晶例程");//字符显示
lcd_wstr(4, 2, "@@@@@");//字符显示
while(1);
}
Device_Init()中相关代码
//配置LCD12864
GPIO_AF_SEL(DIGITAL, PC, 3, 0);
GPIO_AF_SEL(DIGITAL, PC, 4, 0);
GPIO_AF_SEL(DIGITAL, PC, 6, 0);
GPIO_AF_SEL(DIGITAL, PC, 7, 0);
GPIO_AF_SEL(DIGITAL, PC, 13, 0);
/****************************************/
很遗憾,有很多的东西我没有办法一一给大家回复,所以我建立了一个群,供大家一起交流!