12864液晶使用的16*16点阵、128个字符(8*16点阵)及64*256点阵显示RAM(GDRAM).与外部CPU接口採用并行或串行两种控制方式。
在12864上显示0-9的随机数 第二行显示www.csdn.blog
第三行显示“求是07的博客”
第四行显示“欢迎光临”
下面是基本的代码
#include <reg52.h> #include <intrins.h> #include <stdlib.h> #define uchar unsigned char #define uint unsigned int #define LCD_data=P0; sbit rs=P3^5; sbit wr=P3^6; sbit en=P3^4; sbit rd=P3^7; sbit wela=P2^6; sbit dula=P2^7; uchar display1[10]; uchar code display2[]={"www.csdn.blog.com"}; uchar code display3[]={"求是07的博客"}; uchar code display4[]={"欢迎光临"}; void delay_1ms(uint x) { uint i,j;for(i=0;i<x;i++)for(j=0;j<100;j++); } void write_cmd(uchar cmd) { rs=0; wr=0;en=0;P0=cmd;delay_1ms(5);en=1;delay_1ms(5);en=0; } void write_data(uchar dat) { rs=1;wr=0;en=0;P0=dat;delay_1ms(5);en=1;delay_1ms(5);en=0; } void lcd_pos(uchar X,uchar Y) { uchar pos;if(X==0){X=0x80;}if(X==1){ X=0x90;}if(X==2){ X=0x88;}if(X==3){ X=0x98;}pos=X+Y;write_cmd(pos); } void makerand() //随机函数 { uint ran;ran=rand();display1[0]=ran/10000+0x30;display1[1]=ran%10000/1000+0x30;display1[2]=ran%1000/100+0x30;display1[3]=ran%100/10+0x30;display1[4]=ran%10+0x30;ran=rand();display1[5]=ran/10000+0x30;display1[6]=ran%10000/1000+0x30;display1[7]=ran%1000/100+0x30;display1[8]=ran%100/10+0x30;display1[9]=ran%10+0x30; } void lcd_init() { rd=1; //设置 并口方式write_cmd(0x30);//这里设置基本指令动作delay_1ms(5); write_cmd(0x0C);//显示开,光光标delay_1ms(5);write_cmd(0x01);//清屏delay_1ms(5); } main() { uchar i;wela=0;dula=0;delay_1ms(5);lcd_init();lcd_pos(1,0);i=0;while(display2[i]!='\0'){ write_data(display2[i]);i++;}lcd_pos(2,0);i=0;while(display3[i]!='\0'){ write_data(display3[i]);i++;}lcd_pos(3,0);i=0;while(display4[i]!='\0'){ write_data(display4[i]);i++;}while(1){ lcd_pos(0,0);makerand();for(i=0;i<10;i++){ write_data(display1[i]);}} }