本帖最后由 芯圣电子官方QQ 于 2023-7-24 14:58 编辑
使员工HC89S001P芯片驱动LCD显示屏,刷屏显示
一、电路图
P04 -- SCLK
P03 -- SDA
P00 -- RES
P02 -- RS
二、程序
#include "config.h"
#include "lcd.h"
#include "oledfont.h"
//#include "delay.h"
//延时函数 1MS
void delay_ms(uchar dt)
{
uchar di,dj,dk;
for(dk=0;dk<dt;dk++)
{
for(dj=0;dj<16;dj++)
{
for(di=0;di<196;di++);
}
}
}
u16 BACK_COLOR, POINT_COLOR; //背景色,画笔色
void LCD_Writ_Bus(char dat) //串行数据写入
{
u8 i;
for(i=0;i<8;i++)
{
OLED_SCLK_Clr();
if(dat&0x80)
OLED_SDIN_Set();
else
OLED_SDIN_Clr();
OLED_SCLK_Set();
dat<<=1;
}
}
void LCD_WR_DATA8(char da) //发送数据-8位参数
{
OLED_DC_Set();
LCD_Writ_Bus(da);
}
void LCD_WR_DATA(int da)
{
OLED_DC_Set();
LCD_Writ_Bus(da>>8);
LCD_Writ_Bus(da);
}
void LCD_WR_REG(char da)
{
OLED_DC_Clr();
LCD_Writ_Bus(da);
// OLED_CS_Set();
}
void LCD_WR_REG_DATA(int reg,int da)
{
LCD_WR_REG(reg);
LCD_WR_DATA(da);
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
LCD_WR_REG(0x2a);
LCD_WR_DATA8(x1>>8);
LCD_WR_DATA8(x1);
LCD_WR_DATA8(x2>>8);
LCD_WR_DATA8(x2);
LCD_WR_REG(0x2b);
LCD_WR_DATA8(y1>>8);
LCD_WR_DATA8(y1);
LCD_WR_DATA8(y2>>8);
LCD_WR_DATA8(y2);
LCD_WR_REG(0x2C);
}
void lcd_port_init(void)
{
P0M0 = P0M1&0xF0|0x08; //P00设置为推挽输出
P0M1 = P0M1&0xF0|0x08; //P02设置为推挽输出
P0M1 = P0M1&0x0F|0x80; //P03设置为推挽输出
P0M2 = P0M2&0xF0|0x08; //P04设置为推挽输出
}
void Lcd_Init(void)
{
uint32_t i;
lcd_port_init();
OLED_RST_Clr();
delay_ms(5);
OLED_RST_Set();
delay_ms(5);
LCD_WR_REG(0x11);
OLED_RST_Clr();
delay_ms(5);
OLED_RST_Set();
delay_ms(5);
//************* Start Initial Sequence **********//
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x70);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x19);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x54);
LCD_WR_DATA8(0x4C);
LCD_WR_DATA8(0x18);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x44);
LCD_WR_DATA8(0x51);
LCD_WR_DATA8(0x2F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x20);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
LCD_WR_REG(0x29);
}
//清屏函数
//Color:要清屏的填充色
void LCD_Clear(u16 Color)
{
u16 i,j;
Address_set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA(Color);
}
}
}
//main.c
//main.c
#define ALLOCATE_EXTERN
#include "config.h"
#include "lcd.h"
//系统初始化
void SystemInit(void)
{
/************************************系统初始化****************************************/
WDTCCR = 0x00; //关闭看门狗
while((CLKCON&0x20)!=0x20); //等待内部高频RC起振
CLKSWR = 0x51; //选择内部高频时钟为主时钟,内部高频RC2分频,Fosc=16MHz
while((CLKSWR&0xC0)!=0x40); //等待内部高频切换完成
CLKDIV = 0x01; //Fosc1分频得到Fcpu,Fcpu=16MHz
}
void main(void)
{
uint i;
uchar j=0x01;
uchar k=0;
SystemInit(); //系统初始化
Lcd_Init();
LCD_Clear(BRRED);
while(1)
{
LCD_Clear(BRRED);
for(i=0;i<50000;i++);
LCD_Clear(WHITE);
for(i=0;i<50000;i++);
LCD_Clear(BLUE);
for(i=0;i<50000;i++);
LCD_Clear(BRED);
for(i=0;i<50000;i++);
LCD_Clear(GRED);
for(i=0;i<50000;i++);
LCD_Clear(GBLUE);
for(i=0;i<50000;i++);
LCD_Clear(RED );
for(i=0;i<50000;i++);
LCD_Clear(MAGENTA);
for(i=0;i<50000;i++);
}
}
三、执行结果
|