#ifndef _LCD240128_H_
#define _LCD240128_H_
#include"sys.h"
#define WR PCout(13)
#define RD PCout(0)
#define CE PCout(1)
#define CD PCout(2)
#define RST PCout(3)
void LCD_GPIO_Init(void);
void LCD_ODATA_CMD(u8 dat,u8 comm);
void LCD_TDATA_CMD(u8 datl,u8 dath,u8 comm);
void LCD_Auto_DATA(u8 dat);
void LCD_Write_CMD(u8 comm);
void LCD_Write_DATA (u8 dat);
void LCD_CHKBusy(u8 autowr);
void LCD_Init(void);
void LCD_CLR(void) ;
#endif
#include"LCD240128.h"
void LCD_GPIO_Init(void)
{
RCC->APB2ENR |= 1<<2; //使能PORTA,PORTC
RCC->APB2ENR |= 1<<4;
GPIOA->CRL = 0x33333333; //设置所用端口为通用推挽输出方式
GPIOC->CRL &= 0xFFFF0000;
GPIOC->CRL |= 0x00003333;
GPIOC->CRH &= 0xFF0FFFFF;
GPIOC->CRH |= 0x00300000;
GPIOA->ODR |= 0x00FF; //拉高所有端口
GPIOC->ODR |= 0x200F;
}
/*------------写命令或数据到LCD--------------*/
void LCD_ODATA_CMD(u8 dat,u8 comm) //写一个数据和一个命令
{
LCD_Write_DATA;
LCD_Write_CMD(comm);
}
void LCD_TDATA_CMD(u8 datl,u8 dath,u8 comm) //写两个数据和一个命令
{
LCD_Write_DATA(datl);
LCD_Write_DATA(dath);
LCD_Write_CMD(comm);
}
void LCD_Auto_DATA(u8 dat) //自动写数据
{
LCD_CHKBusy(1);
CD=0;
RD=1;
GPIOA->BRR = 0x00FF;
GPIOA->ODR|=dat;
WR=0;
WR=1;
}
void LCD_Write_CMD(u8 comm) //写命令
{
LCD_CHKBusy(0);
GPIOA->BRR = 0x00FF;
CD=1;
RD=1;
GPIOA->ODR|=comm;
WR=0;
WR=1;
}
void LCD_Write_DATA (u8 dat) //写数据
{
LCD_CHKBusy(0);
CD=0;
RD=1;
GPIOA->BRR = 0x00FF;
GPIOA->ODR|=dat;
WR=0;
WR=1;
}
void LCD_CHKBusy(u8 autowr) //测状态
{
u8 status;
GPIOA->ODR|= 0xFF;
CD = 1;
WR = 1;
RD=0;
if(autowr)
{
do
{status = GPIOA->IDR;
}while((status&0x08)==0);
}
else
{
do
{ status = GPIOA->IDR;
}while(((status&0x01)==0)||((status&0x02)==0));
}
RD=1;
}
/*------------------初始化-----------------*/
void LCD_Init(void)
{
LCD_GPIO_Init();
CE = 0;
RST=0;
RST=1;
LCD_TDATA_CMD(0x00,0x00,0x24);
LCD_TDATA_CMD(0x00,0x00,0x42);
LCD_TDATA_CMD(30,0x00,0x43);
LCD_Write_CMD(0x88);
LCD_Write_CMD(0x9B);
}
/*--------------清RAM------------------*/
void LCD_CLR(void)
{
u8 i,j;
LCD_ODATA_CMD(0,0x24);
LCD_Write_CMD(0xB0);
for(j=0;j<8;j++)
{
for(i=0;i<30;i++)
LCD_Auto_DATA(0x00);
}
LCD_Write_CMD(0xB3);
}
int main(void)
{
u8 i;
Stm32_Clock_Init(9);//系统时钟设置
delay_init(72); //延时初始化
LCD_Init();
for(i=0;i<192;i++)
{
LCD_ODATA_CMD(sendbuf[i],0xC0);
}
while(1);
} |