📄 ks0108.h
字号:
#ifndef KS0108_H
#define KS0108_H
/***************************常量定义**********************************/
#ifndef FALSE
#define FALSE 0
#define TRUE (~FALSE)
#endif
#define LCD12864_ON 0x3f
/**********************LCD12864引脚定义*******************************/
#define LCDPORT (uint32)0xff<<8
#define LCD_DI (1<<20)
#define LCD_RW (1<<24)
#define LCD_EN (1<<25)
#define CS1 (1<<21)
#define CS2 (1<<23)
uint8 LCDExist;
////////////////////////////////////////////////////////
/////延时
///////////////////////////////////////////////////////
void Delay(uint8 D_time)
{
uint8 i,j;
for(j=0;j<D_time;j++)
for(i=0;i<124;i++);
}
void Delaym(uint32 D_time)
{
uint32 i,j;
for(j=0;j<D_time;j++)
for(i=0;i<0xfff;i++);
}
//////////////////////////////////////////////////////
/////////延时判忙
//////////////////////////////////////////////////////
uint8 LCD12864_Delay(void)
{
uint8 LCD_status=0x90,i;
IOSET=LCD_RW; //读状态
IOCLR=LCD_DI;
if(LCDExist)
{
while(LCD_status&0x90)//判忙以及复位情况
{
if(i<1000)
{
IODIR &=~(LCDPORT);
for (i=0;i<2 ;i++ );
IOSET=LCD_EN ;
Delay(1);
LCD_status =(IO0PIN&LCDPORT)>>8;
IODIR |=LCDPORT;
IOCLR=LCD_EN;
i++;
}
else
{
LCDExist = FALSE;
return FALSE;
}
}
}
return TRUE;
}
//////////////////////////////////////////////////////////
////// 写数据或命令
////// D_type:0->写入的是命令,1->写入的是数据
////// D_code:要写入的数据
////////////////////////////////////////////////////////
void LCD12864_Write_code(uint32 type,uint8 D_code)
{
LCD12864_Delay();
IOCLR=LCD_RW;
if(type)
IOSET=LCD_DI;
else
IOCLR=LCD_DI;
IO0PIN=(IO0PIN&(~(LCDPORT)))|(D_code<<8);
IOSET=LCD_EN;
Delay(1);
IOCLR=LCD_EN;
}
/////////////////////////////////////////////////////////
/// 设置显示地址:
/// L_X:竖直方向(0<=L_X<=7) L_Y:水平方向(0<=L_Y<=127)
/////////////////////////////////////////////////////////
void LCD_Set_XY(uint8 L_X,uint8 L_Y)
{
L_Y &= 0x3f; // 0=<L_Y<=63 数据保护
L_Y |= 0x40; //01xx xxxx
LCD12864_Write_code(0,L_Y);//写横向地址
L_X &= 0x07; //0<=L_X<=7 数据保护
L_X |= 0xb8; //1011 1xxx
LCD12864_Write_code(0,L_X); //写纵向地址
}
///////////////////////////////////////////////////////////
//////////清屏
////////////////////////////////////////////////////////
void LCD12864_Clr(void)
{
uint8 i,j;
IOSET=CS1;
IOSET=CS2;
Delay(1);
for (i=0;i<8;i++ )
{
LCD_Set_XY(i, 0);
for(j=0 ;j<64 ;j++)
LCD12864_Write_code(1, 0x00);
}
IOCLR=CS1;
IOCLR=CS2;
}
/////////////////////////////////////////////
///////////初始化端口及打开显示
/////////////////////////////////////////////
void LCD12864_Init(void)
{
IODIR|=(LCDPORT|LCD_DI|LCD_RW|LCD_EN|CS1|CS2);
IOSET=CS1;
IOSET=CS2;
LCD12864_Write_code(0,LCD12864_ON); //开显示
IOCLR=CS1;
IOCLR=CS2;
}
//////////////////////////////////////////////////////////
///////////数字半角显示点阵
////////////////////////////////////////////////////////////
uint8 BMP_NUM[][16] = {
{0x00,0xF0,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00}, /*0*/
{0x00,0x00,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00}, /*1*/
{0x00,0x30,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x20,0x30,0x28,0x24,0x23,0x20,0x00}, /*2*/
{0x00,0x30,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x18,0x20,0x21,0x21,0x21,0x1E,0x00}, /*3*/
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x3F,0x04,0x00}, /*4*/
{0x00,0xC0,0xB8,0x88,0x88,0x88,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x30,0x0F,0x00}, /*5*/
{0x00,0xF0,0x08,0x88,0x88,0x88,0x30,0x00,0x00,0x1F,0x21,0x20,0x20,0x20,0x1F,0x00}, /*6*/
{0x00,0x08,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3C,0x03,0x00,0x00,0x00}, /*7*/
{0x00,0xF0,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x1E,0x21,0x21,0x21,0x21,0x1E,0x00}, /*8*/
{0x00,0xF0,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x19,0x22,0x22,0x22,0x21,0x1F,0x00}, /*9*/
{0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00},
};
////////////////////////////////////////////////////////
void LCD12864_Darw_bmp_NUM(uint32 position, uint8 c, uint8 Start_x, uint8 Start_y)
{
uint8 a;
if(!position)
{
IOSET=CS1;
IOCLR=CS2;
}
else
{
IOCLR=CS1;
IOSET=CS2;
}
LCD_Set_XY(Start_x++, Start_y);//设置显示地址
for(a=0 ;a<8 ;a++)
LCD12864_Write_code(1, BMP_NUM[c][a]);
LCD_Set_XY(Start_x, Start_y);
for(a=8 ;a<16 ;a++)
LCD12864_Write_code(1, BMP_NUM[c][a]);
}
///////////////////////////////////////////////
//////////收尾工作
///////////////////////////////////////////////
void shouwei(void)
{
IOCLR=CS1;
IOCLR=CS2;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -