请问你有51单片机接12864的电路跟c程序吗?能不能给分享一下,初学者,谢谢

2024-12-21 16:33:50
推荐回答(2个)
回答1:

你给点分吧

回答2:

/*************************************************
名 称:LCD12864_ST7920并行测试程序
试验功能:测试基于ST7920控制芯片的LCD12864的显示
并行方式连接;晶振11.0592M
编 写:JiangX.net
*************************************************/

#include
#include
#include
#define uchar unsigned char
#define uint unsigned int //宏定义

/*
sbit CS="P2^0; //RS=CS
sbit SID="P2^2; //RW=SID
sbit SCLK="P2^1; //E=SCLK
*/

/*****LCD接口定义*****/
sbit LCD_RS = P2^0; //1:输入数据 ;0:输入命令
sbit LCD_RW = P2^2; //1:读数据 0:写数据
sbit LCD_EN = P2^1; //LCM使能端
sbit LCD_PSB = P2^3; //串并口选择 1:并口模式; 0:串口模式;
#define LCD_DATA P1 //LCD总线端口

/*****LCD功能初始化指令*****/
#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H
#define AC_INIT 0x02 //将AC设置为00H。且游标移到原点位置
#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)
#define FUN_MODE 0x30 //工作模式:8位基本指令集
#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白
#define DISPLAY_OFF 0x08 //显示关
#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1
#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH
#define SET_DD_AC 0x80

/*****汉字地址表*****/
uchar code addr_tab[]={ //便于根据汉字坐标求出地址
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,//第四行汉字位置
};

/*****n(ms)延时子程序*****/
void delayms(uint t) //约延时n(ms)
{
uint i;
while(t--)
{
for(i=0;i<125;i++);
}
}

/*****等待LCD忙*****/
void WaitBusy(void) //延时一小段时间,等待LCD空闲
{
uchar i=5;
while(i--);
}

/*****写指令代码*****/
void Lcd_WriteCmd(uchar cmdcode)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
WaitBusy();
LCD_DATA = cmdcode;
LCD_EN = 0;
}

/*****写数据*****/
void Lcd_WriteData(uchar dispdata)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 1;
WaitBusy();
LCD_DATA = dispdata;
LCD_EN = 0;
}

/*****初始化LCD*****/
void Lcd_Init()
{
LCD_PSB = 1;
delayms(50);
Lcd_WriteCmd(0x30); //选择基本指令集
delayms(1);
Lcd_WriteCmd(0x30); //选择8bit数据流
delayms(1);
Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)
delayms(1);
Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H
delayms(20);
}

/*****显示汉字*****/
void hanzi_Disp(uchar x,uchar y,uchar code *s)
{ //x、y为汉字坐标
Lcd_WriteCmd(addr_tab[8*x+y]); //写地址
while(*s>0)
{
Lcd_WriteData(*s); //写数据
s++;
}
}

/*****显示图片(显示Gdram内容)*****/

/*绘图显示的步骤
1 关闭绘图显示功能
2 先将垂直的坐标(Y)写入绘图RAM地址
3 再将水平的位元组坐标(X)写入绘图RAM地址
4 将D15-D8写入RAM中
5 将D7-D0写入到RAM中
6 打开绘图显示功能*/

//图片取模方式:横向取模,字节正序
void pic_Disp(uchar *pic) //显示Gdram内容(显示图片)
{
uchar x,y,i;
for(i=0;i<9;i=i+8)
for(y=0;y<32;y++)
{
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //扩充指令,开绘图显示
Lcd_WriteCmd(0x80+y); //行地址
Lcd_WriteCmd(0x80+x+i); //列地址
Lcd_WriteData(*pic++); //写数据 D15-D8
Lcd_WriteData(*pic++); //写数据 D7-D0
Lcd_WriteCmd(0x30);
}
}
}

/*****整屏显示竖条*****/
//当i=0时显示上面128×32,当i=8时显示下面128×32
//当i=0时显示上面128×32,当i=8时显示下面128×32
void LcdFill_Vertical()
{
uchar x,y,i;
for(i=0;i<9;i=i+8)
for(y=0;y<0x20;y++)
{
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //扩充指令 绘图显示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+i); //列地址
Lcd_WriteData(0x55); //写数据 D15-D8
Lcd_WriteData(0x55); //写数据 D7-D0
Lcd_WriteCmd(0x30);
}
}
}

/*****整屏显示横条*****/
void LcdFill_Level()
{
uchar x,y,i;
uchar k;
for(i=0;i<9;i+=8)
for(y=0;y<0x20;y++)
{
if((y%2)==1) k=0xff;
else k=0;
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //扩充指令 绘图显示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+i); //列地址
Lcd_WriteData(k);
Lcd_WriteData(k);
Lcd_WriteCmd(0x30);
}
}
}

/*****整屏充满亮点或暗点*****/
//当i=0时显示上面128×32,当i=8时显示下面128×32
//当i=0时显示上面128×32,当i=8时显示下面128×32
void Lcd_Fill(uchar test)
{
uchar x,y,i;
for(i=0;i<9;i=i+8)
for(y=0;y<0x20;y++)
{
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //扩充指令 绘图显示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+i); //列地址
Lcd_WriteData(test); //写数据 D15-D8
Lcd_WriteData(test); //写数据 D7-D0
Lcd_WriteCmd(0x30);
}
}
}

/*****主函数*****/
void main(void)
{
Lcd_Init();
while(1)
{
Lcd_Init();
hanzi_Disp(0,0,"ST7920型液晶模块");
hanzi_Disp(1,1,"并行测试程序");
hanzi_Disp(2,0,"www.JiangX.net");
hanzi_Disp(3,3,"");
delayms(2000);

Lcd_Init();
// Lcd_Fill(0xff);
hanzi_Disp(1,2,"坏点检测");
delayms(500);

Lcd_Init();
Lcd_Fill(0xff);
delayms(1500);

Lcd_Init();
LcdFill_Vertical();
delayms(750);

Lcd_Init();
LcdFill_Level();
delayms(750);

Lcd_Init();
hanzi_Disp(1,2,"显示汉字");
delayms(500);

Lcd_Init();
hanzi_Disp(0,0,tangshi);
delayms(1500);

Lcd_Init();
hanzi_Disp(1,2,"显示图片");
delayms(500);

Lcd_Init();
pic_Disp(LCDsheji);
delayms(1000);

Lcd_Init();
pic_Disp(rmb);
delayms(1000);

Lcd_Init();
pic_Disp(qiche);
delayms(1000);

Lcd_Init();
pic_Disp(gongji);
delayms(1000);

Lcd_Fill(0x00); //清显示RAM
delayms(500);
}
}

#include
#include
#include
#define uint unsigned int
#define uchar unsigned char
#define D_PORT P0
sbit RS =P2^0;
sbit RW =P2^2;
sbit E =P2^1;
#define LCD_BUS P1

uchar code hztab[16*64]={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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x88,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xA8,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x88,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,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x8C,0x45,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x04,0xE4,0x75,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x94,0x55,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0x7C,0x72,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x07,0x30,0x01,0xFE,0x00,0x00,0x00,0x00,
0x02,0xFC,0x00,0x02,0x00,0x00,0x00,0x00,0x02,0x10,0x01,0xFE,0x00,0x00,0x00,0x00,
0x0D,0x50,0x00,0x02,0x00,0x00,0x00,0x00,0x01,0x10,0x01,0xFE,0x00,0x00,0x00,0x00,
0x05,0x50,0x00,0x02,0x00,0x00,0x00,0x00,0x01,0x10,0x01,0xFE,0x00,0x00,0x00,0x00,
0x02,0xFC,0x00,0x02,0x00,0x00,0x00,0x00,0x07,0x38,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x3B,0x80,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x12,0x02,0x2A,0x80,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x35,0x02,0x11,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,
0x04,0x80,0x55,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,
0x02,0x80,0x35,0x02,0x3B,0x80,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x00,
0x02,0x80,0x12,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x00,0x62,0x00,0x00,
0x03,0x80,0x00,0x02,0x00,0x00,0x06,0x60,0x00,0x00,0x01,0xFE,0x00,0x26,0x00,0x00,
0x0C,0x80,0x00,0x02,0x00,0x00,0x02,0x20,0x03,0xF8,0x01,0xFE,0x00,0x2A,0x00,0x00,
0x03,0x80,0x00,0x02,0x00,0x00,0x02,0x20,0x03,0xF8,0x01,0xFE,0x00,0x26,0x00,0x00,
0x02,0x80,0x00,0x02,0x00,0x00,0x02,0x20,0x03,0xF8,0x01,0xFE,0x00,0x72,0x00,0x00,
0x02,0x80,0x00,0x02,0x00,0x00,0x07,0x70,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x78,0x72,0x02,0x00,0x00,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x04,0x55,0x02,0x1F,0xC0,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x25,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,
0x00,0x00,0x45,0x02,0x1F,0xC0,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x72,0x02,0x1F,0xC0,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x00,0x00,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x0F,0xF0,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x0F,0xF0,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x0F,0xF0,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x00,0x02,0x1F,0xC0,0x0F,0xF0,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x02,0x02,0x1F,0xC0,0x0F,0xF0,0x03,0xF8,0x01,0xFE,0x00,0x7F,0x00,0x00,
0x00,0x00,0x05,0x02,0x1F,0xC1,0x0F,0xF0,0x43,0xF8,0x21,0xFE,0x08,0x7F,0x04,0x00,
0x00,0x00,0x05,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,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,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x81,0x50,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x82,0x50,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x82,0x88,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x87,0x06,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x8A,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x82,0x48,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x82,0x48,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x82,0x90,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x03,0x10,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

};
/*void ddram_clear()
{
/*set basic instruction;*/
/*write_comm(0x30,0);
/*clear ddram=20h*/
/* write_comm(0x1,0);
/*set AC=0, D=1 C=1
//write_comm(0x26,0);
//write_comm(0x30,0);
}*/

void wait_free()
{
unsigned char retb;

do{

D_PORT=0xff;

RS=0;

RW=1;

E=1;

retb=D_PORT;

E=0;
}while((retb&0x80)!=0);

}

void write_comm(unsigned char cmd_dat,bit cd)
{
wait_free();

if(cd)RS=1;
else RS=0;

RW=0;

E=1;

D_PORT=cmd_dat;

E=0;
}

void delay()
{
unsigned int i,j,k;
for(i=0;i<100;i++)
for(j=0;j<100;j++)
for(k=0;k<100;k++);
}

void main()
{
unsigned int i,j,k;

delay();
delay();
delay();

write_comm(0x30,0);
delay();
write_comm(0x30,0);
delay();
write_comm(0x30,0);
delay();
write_comm(0x30,0);
delay();
write_comm(0x0c,0);
delay();
write_comm(0x06,0);
delay();
write_comm(0x01,0);

write_comm(0x92,0);

write_comm(0xc7,1);
write_comm(0xe0,1);
write_comm(0xD4,1);
write_comm(0xC6,1);
write_comm(0xB4,1);
write_comm(0xB4,1);
write_comm(0xD0,1);
write_comm(0xC2,1);

delay();
delay();
delay();
write_comm(0x92,0);

write_comm(0xb0,1);
write_comm(0xa0,1);
write_comm(0xb0,1);
write_comm(0xa0,1);
write_comm(0xb0,1);
write_comm(0xa0,1);
write_comm(0xb0,1);
write_comm(0xa0,1);

write_comm(0x36,0);

k=0;
for(j=0;j<32;j++)
{
write_comm((0x80+j),0);
write_comm(0x80,0);
for(i=0;i<16;i++)
{
write_comm(hztab[k],1);
k++;
}
}
for(j=0;j<32;j++)
{
write_comm((0x80+j),0);
write_comm(0x88,0);
for(i=0;i<16;i++)
{

write_comm(hztab[k],1);
k++;
}

}
while(1);
}