📄 12864_7920.c
字号:
/********************************************
12864(控制器为st7920)驱动 ,采用串行方式,
********************************************/
#include"reg52.h"
#include "intrins.h"
sbit SCLK =P3^4 ; //E
sbit SID =P3^3; //RW
sbit RST =P3^2; //CS
sbit PSB =P3^5;
#define ROW1 0x80
#define ROW2 0x90
#define ROW3 0x88
#define ROW4 0x98
#define uint unsigned int
#define uchar unsigned char
uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行汉字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行汉字位置
};
uchar code Hz_0[]={"汉字数字字母 演示"};
uchar code Hz_1[]={"打点演示"};
uchar code Hz_2[]={"图像演示"};
uchar code dsp[]={"欢迎使用KP-51PRO实验板 E_mail: cany_999@163.com"};
/*****************************************
Fucntion: delay10US(char x)
Description: delay for 10 us
Parameter: x
*****************************************/
void delay10US(uchar x)
{
uchar k;
for(k=0;k<x;k++);
}
/*****************************************
Fucntion: delay1MS(char x)
Description: delay for 10 us
Parameter: x delay for 1MS
*****************************************/
void delay1MS(uchar x)
{
uchar k,j;
x=x<<1;
for(k=0;k<x;k++)
for(j=0;j<255;j++)_nop_();
}
/********************************************************************/
void SendByteLCD(uchar WLCDData)
{
uchar i;
for(i=0;i<8;i++)
{
if((WLCDData<<i)&0x80)SID=1;
else SID=0;
SCLK=0;
_nop_();
_nop_();
_nop_();
_nop_();
SCLK=1;
}
}
/**********************************************************************/
void SPIWR(uchar Wdata,uchar RS)
{
SendByteLCD(0xf8+(RS<<1));
SendByteLCD(Wdata&0xf0);
SendByteLCD((Wdata<<4)&0xf0);
}
/********************************************************************/
void SendCMD(uchar CMD)
{
SPIWR(CMD,0);
delay10US(90);
}
/********************************************************************/
void SendData(uchar Data)
{
SPIWR(Data,1);
}
/********************************************************************/
void LCDInit(void)
{
RST=0;
delay1MS(50);
RST=1;
SendCMD(0x30); //功能设置,一次送8位数据,基本指令集
SendCMD(0x0C); //0000,1100 整体显示,游标off,游标位置off
SendCMD(0x01); //0000,0001 清DDRAM
SendCMD(0x02); //0000,0010 DDRAM地址归位
SendCMD(0x80); //1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC//
SendCMD(0x04); //点设定,显示字符/光标从左到右移位,DDRAM地址加 一//
SendCMD(0x0C); //显示设定,开显示,显示光标,当前显示位反白闪动
}
/***************************************************************************************
发送字符串
***************************************************************************************/
void PutStr(uchar row,uchar col,uchar *puts)
{
SendCMD(0x30); //8BitMCU,基本指令集合
SendCMD(AC_TABLE[8*row+col]); //起始位置
while(*puts != '\0') //判断字符串是否显示完毕
{
if(col==8) //判断换行
{ //若不判断,则自动从第一行到第三行
col=0;
row++;
}
if(row==4) row=0; //一屏显示完,回到屏左上角
SendCMD(AC_TABLE[8*row+col]);
SendData(*puts); //一个汉字要写两次
puts++;
SendData(*puts);
puts++;
col++;
}
}
/*******************************************************************************/
void ClearScreen(void)
{
uchar i,j,x,y;
LCDInit();
SendCMD(0x3e); // ;RE=1 扩展指令选择 G=1 开图形显示
x=0x80;
y=0x80;
for(j=0;j<64;j++)
{
y=0x80;
SendCMD(x);
SendCMD(y);
for(i=0;i<32;i++){SendData(0x00);}
x=x+1;
}
}
/********************************************************************************/
void Sendint(uint dd)
{
SendData(dd>>8);
SendData(dd);
}
/*******************************************************************************
打点 x=0:128; y=0:64;
********************************************************************************/
void Gra(uchar x,uchar y)
{
uchar xx,yy;
SendCMD(0x34);
SendCMD(0x36);
xx=x/16;
yy=63-y;
if(yy>=32){xx=xx+8;yy-=32;}
SendCMD(0x80+yy);
SendCMD(0x80+xx);
Sendint(0x8000>>(x%16));
}
/********************************************************************************/
uchar code IBM[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xF0,0x00,0x1F,0xFF,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xF8,0x00,0x3F,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFE,0x01,0xFF,0xFF,0x00,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -