12864液晶显示C语言程序设计实例
51单片机和12864液晶显示实例——C语言
#include <reg51.h>#define unchar unsigned char #define unint unsigned intsbit RS=P2^7;sbit RW=P2^6;sbit E=P2^5;void delay(unsigned int t){unsigned int i,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}void busy(){RS=0;RW=1;E=1;P0=0xff;while((P0&0X80)==0x80); }void write_com(unchar com) {busy();RS=0;RW=0;E=1;P0=com;delay(5);E=0;delay(5);}void write_date(unchar date) {busy();RS=1;RW=0;E=1;P0=date;// delay(5);E=0;// delay(5);}void init(){delay(2000);write_com(0x30); //选择基本指令,选择8位数据流delay(5);write_com(0x0c); //开显示(无游标,不反白)delay(10);write_com(0x01); //清除显示,并且设定地址指针为00H delay(500);write_com(0x06);// 设定游标移动方向}void sendaddr(unchar n,unchar m){switch(n){case 1:write_com(0x80+m);break;case 2:write_com(0x90+m);break;case 3:write_com(0x88+m);break;case 4:write_com(0x98+m);break;}}void display(unchar n,unchar m,unchar *s){sendaddr(n,m);while(*s>0){write_date(*s);s++;delay(100);}}void main(){unchar *s;init();s="甲:“我来了”";display(1,0,s);s="乙:“热烈欢迎。
12864液晶显示C语言程序设计实例
本文由g_olivebranch贡献 #include <reg51.h> #include sbit RS = P2^5; sbit RW = P2^6; sbit E = P2^7; sbit RES = P3^5; #define Lcd_Bus P0 //MCU P1<> LCM #define FIRST_ADDR 0 //定义字符/汉字显示起始位置 unsigned char code zk[]={ 0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e,0x1f, 0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f,0xc0, }; unsigned char code BMP1[]={ /*-- 调入了一幅图像:D:\3033B\3033.bmp --*/ /*-- 宽度x高度=128x64 --*/ /*--总共52行数据,每行16个数据--*/ 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, 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x0C,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x07,0xF1,0x00,0x03,0x01,0x00,0xF0,0x00,0x00,0x00, 0x18,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x03,0x81,0x08,0x98,0x00,0x00,0x00, 0x10,0x1F,0x07,0x06,0x00,0x00,0x08,0x01,0x00,0x04,0x81,0x11,0x88,0x00,0x00,0x00, 0x10,0x21,0x0D,0x83,0xE3,0xC0,0x0F,0x02,0x00,0x04,0xC1,0x31,0x30,0x00,0x00,0x00, 0x10,0x21,0x18,0x83,0x06,0x40,0x09,0x82,0x00,0x0F,0xC1,0x21,0xE0,0x00,0x00,0x00, 0x10,0x2E,0x11,0x86,0x06,0x40,0x00,0x86,0x00,0x08,0x43,0xC3,0xE0,0x00,0x00,0x00, 0x30,0x30,0x11,0x86,0x04,0x40,0x41,0x84,0x10,0x18,0x63,0x82,0x18,0x00,0x00,0x00, 0x20,0x1E,0x1F,0x84,0x04,0x60,0x7E,0x04,0x08,0x10,0x23,0x04,0x0E,0x00,0x00,0x00, 0x3F,0x83,0x00,0xE0,0x00,0x00,0x00,0x00,0x04,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,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x38,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x6C,0x3C,0x00,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x42,0x22,0x03,0xFD,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x40,0x62,0x00,0x22,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x46,0x42,0x00,0x22,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x44,0x42,0x00,0x23,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x7C,0x26,0x00,0x2D,0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x0C,0x3C,0x00,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x04,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x06,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x02,0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x03,0x18,0x08,0x0C,0x30,0xF1,0x08,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x08,0x08,0x0C,0x31,0x91,0x08,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x08,0x08,0x1A,0x71,0x01,0x08,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x08,0x13,0xD1,0x01,0x08,0x00, 0x00,0x00,0x08,0x11,0x0A,0x00,0x20,0x20,0x04,0x04,0x18,0x11,0x91,0x01,0x08,0x00, 0x00,0x00,0x04,0x11,0x12,0x31,0x22,0x20,0x04,0x04,0x10,0x11,0x13,0x01,0x08,0x00, 0x00,0x00,0x02,0x1B,0x92,0x31,0x26,0x20,0x04,0x04,0x10,0x10,0x12,0x01,0x08,0x00, 0x3F,0xFF,0xFF,0x0A,0x91,0x73,0x25,0x60,0x04,0x44,0x10,0x10,0x12,0x01,0x08,0x00, 0x00,0x00,0x02,0x0A,0xB1,0x4A,0x35,0x40,0x04,0x34,0x30,0x10,0x13,0x01,0x08,0x00, 0x00,0x00,0x04,0x0E,0x61,0xCA,0x19,0x40,0x04,0x1C,0x20,0x10,0x11,0x19,0x98,0x00, 0x00,0x00,0x08,0x04,0x60,0xCC,0x19,0xCC,0x06,0x0E,0x20,0x10,0x11,0xF0,0xFC,0xC0, 0x00,0x00,0x00,0x04,0x60,0x8C,0x18,0x8C,0x03,0xF3,0xBF,0x80,0x00,0x00,0x00,0xC0, 0x00,0x00,0x00,0x00,0x40,0x80,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,0x0F,0x83,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x06,0xC3,0xFC,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x22,0x44,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x22,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x26,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x24,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x48,0x64,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0xC4,0x44,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x03,0x84,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,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, }; unsigned char code BMP[]={ 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,0x04,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x20,0x00,0x00 0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x84,0x00,0x00,0x00,0x00, 0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0xE0,0x04,0x00,0x08,0x80,0x60,0x00,0x00, 0x00,0x1F,0xFF,0xC0,0x00,0x00,0x00,0x01,0x10,0x02,0x1F,0xC1,0x01,0xD0,0x00,0x38, 0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00,0x10,0x00,0x70,0x72,0x01,0x0C,0x00,0x68, 0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x06,0x13,0x08,0x40,0x08,0x03,0x06,0x00,0xCC, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x09,0x84,0x80,0x0C,0x1E,0x03,0x89,0x86, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0xC1,0x80,0x04,0x68,0x00,0xFF,0x02, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x41,0x00,0x00,0xC0,0x00,0x60,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x61,0x00,0x00,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x31,0x00,0x00,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x0C,0x00,0x00,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x01,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x00,0xC0,0x00,0x03,0x00,0x02,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xE8,0x00,0x00,0x01,0x80,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x1A,0x08,0x00,0x00,0x03,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x3C,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x01,0xC0,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x02,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x02,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x04,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x04,0x00,0x02,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0xF4,0x00,0x02,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x03,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x79,0xF8,0x10,0x20,0x00, 0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x09,0x08,0x10,0x20,0x00, 0x02,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x09,0x08,0x10,0x20,0x00, 0x06,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x79,0xF8,0x10,0x20,0x00, 0x04,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0xFD,0xFE,0x00, 0x04,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x43,0xFC,0x10,0x20,0x00, 0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x03,0xFF,0xF0,0x42,0x44,0x10,0x60,0x00, 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x7A,0x44,0x38,0x70,0x00, 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x0B,0xFC,0x74,0xB0,0x00, 0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x54,0xA8,0x00, 0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x08,0x48,0x91,0x28,0x00, 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x44,0x12,0x26,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x7E,0x14,0x24,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2B,0xC4,0x10,0x20,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x20,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,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, }; /*检查忙位*/ void chk_busy() { RS=0; RW=1; E=1; Lcd_Bus=0xff; while((Lcd_Bus&0x80)==0x80); E=0; } /*延时子程序*/ void delay(unsigned int t) { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<10;j++) ; } /*写命令到LCD*/ void write_com(unsigned char cmdcode) { chk_busy(); RS=0; RW=0; E=1; Lcd_Bus=cmdcode; delay(5);////////////////////在数据写入的时候加入适当的延时 E=0; delay(5); } /*写数据到LCD*/ void write_data(unsigned char Dispdata) { chk_busy(); RS=1; RW=0; E=1; Lcd_Bus=Dispdata; delay(5);///////////////////在数据写入的时候加入适当的延时 E=0; delay(5); } /*初始化LCD屏*/ void lcdreset() { delay(2000); write_com(0x30); delay(10); //选择基本指令集 write_com(0x30); //选择8bit数据流 delay(5); write_com(0x0c); //开显示(无游标、不反白) delay(10); write_com(0x01); //清除显示,并且设定地址指针为00H delay(500); write_com(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位 delay(0); } /*自定义一个字符代码(一个星星和月亮)*/ void CGRAM() { int i; write_com(0x30); write_com(0x40); for(i=0;i<16;i++) {write_data(zk[i*2]); write_data(zk[i*2+1]); } } /*显示字符串*/ void hzkdis(unsigned char code *s) { while(*s>0) { write_data(*s); s++; delay(50); } } /*首屏显示*/ void ceshi() {write_com(0x01);//清除显示,并且设定地址指针为00H delay(5); write_com(0x80);//第一行(如果是地址是:80H,即LCD的第一行的第一个位置显示) hzkdis("强林单片机"); write_com(0x90);//第二行(如果是地址是:90H,即LCD的第二行的第一个位置显示) hzkdis("--技术项目交易网"); write_com(0x88);//第三行(如果是地址是:88H,即LCD的第二行的第一个位置显示) hzkdis("LCD12864点阵液晶"); write_com(0x9A);//第四行(如果是地址是:98H,即LCD的第二行的第一个位置显示) hzkdis("测试程序"); } /*显示图片2005.11.14.21:20修改benladn911*/ void Disp_Img(unsigned char code *img) { unsigned int j=0; unsigned char x,y,i; for(i=0;i<9;i+=8) for(y=0;y<32;y++)/*原来 为 y<26 ,上下两个半屏不能正常对接显示,导致显示的图片中间有空隙*/ for(x=0;x<8;x++) { write_com(0x36);//功能设置8BIT控制界面,扩充指令集 write_com(y+0x80); //行地址 write_com(x+0x80+i); //列地址 write_com(0x30); write_data(img[j++]); write_data(img[j++]); } } /*清整个GDRAM空间*/ void clrgdram() { unsigned char x,y; for(y=0;y<64;y++) for(x=0;x<16;x++) { write_com(0x34); write_com(y+0x80); //行地址 write_com(x+0x80); //列地址 write_com(0x30); write_data(0x00); write_data(0x00); } } /*整屏写入数据:全亮,或者竖条*/ void lcdfill(unsigned char disdata) { unsigned char x,y; for(y=0;y<32;y++) for(x=0;x<16;x++) { write_com(0x36); write_com(y+0x80); //行地址 write_com(x+0x80); //列地址 write_com(0x30); write_data(disdata); write_data(disdata); } write_com(0x34); write_com(0x36); } /*显示横*/ void Disp_H_Line() { unsigned char x,y; unsigned char k=0x00; for(y=0;y<32;y++) { k= ̄k; for(x=0;x<16;x++) { write_com(0x36); write_com(y+0x80); //行地址 write_com(x+0x80); //列地址 write_com(0x30); write_data(k); write_data(k); }; } write_com(0x34); write_com(0x36); } /*显示边框*/ void Frame() {unsigned char x,y; lcdfill(0x00); for(x=0;x<9;x+=8) for(y=0;y<32;y++) { write_com(0x36); write_com(y+0x80); //行地址 write_com(x+0x80); //列地址 write_com(0x30); write_data(0x80); write_data(0x00); write_com(0x36); write_com(y+0x80); //行地址 write_com(x+0x87); //列地址 write_com(0x30); write_data(0x00); write_data(0x01); } for(y=0;y<2;y++) for(x=0;x<8;x++) {write_com(0x36); write_com(y*31+0x80); //行地址 write_com(x+0x80+8*y); //列地址 write_com(0x30); write_data(0xff); write_data(0xff); } write_com(0x34); write_com(0x36); } /*在第7列的位置加入两条竖线*/ void shuxian() { unsigned char x,y; for(x=0;x<9;x+=8) for(y=0;y<32;y++) { write_com(0x36); write_com(y+0x80); //行地址 write_com(x+0x86); //列地址 write_com(0x30); write_data(0x00); write_data(0x14); }; } /*清屏命令*/ void clrscreen() { write_com(0x01); delay(10); } /*唐诗《静夜思》*/ void gushi_display() { write_com(0x30); clrscreen(); write_com(0x80+FIRST_ADDR); hzkdis("床前明月光,"); write_com(0x90+FIRST_ADDR); hzkdis("疑是地上霜。
单片机制作的12864液晶万年历_C语言程序
#include<reg52.H>#include<intrins.h>#include<math.h>////////////////////////////////////////DS18B20#define uchar unsigned char#define uint unsigned intsbit DQ = P1 ^ 0; // 定义DS18B20的单总线#define Lcd_Bus P0sbit LCD_RS=P2^7; //数据/命令选择sbit LCD_RW=P2^6; //读写控制sbit LCD_EN=P2^5; //片选信号#define LCD_DA TA P0 //8 bit数据线#define LOW 0#define HIGH 1//初始化指令#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#define FUN_MODEK 0x36 //扩展指令集,8位指令#define X1address 0x80 //上半屏X轴起始地址#define X2address 0x88 //下半屏X轴起始地址#define Y address 0x80 //Y轴起始地址#define Set_Column 0x40#define Set_Page 0xB8uchar code shu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code xingqi[]="星期";uchar code hanzishu[]="一二三四五六日";unsigned char TempData = 0;double DS18B20Data;uint jiemian=0;//////////////////////////////////////////DS1302sbit DS1302_RST = P1^4;sbit DS1302_IO = P1^3;sbit DS1302_SCK = P1^2;unsigned char table[]={0X00,0X18,0X0c,0X15,0X06,0X01,0X0a};//0s 24min 12hour 14ri 5yue 5zhou 2010nianunsigned char data table1[7];//uchar code table2[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code shuzi[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,};unsigned char aa,bb;uchar miaoge,miaoshi,fenge,fenshi,shige,shishi,rige,rishi,yuege,yueshi,zhou,niange,nianshi;uchar shezhinum=0;//unsigned char shi,ge;////////////////////////////////////////////////键盘扫描sbit key_mnue = P3^7;sbit key_jia = P2^0;sbit key_jian = P2^1;sbit key_enter= P2^2;uchar key_number=0;//int nian,yue,ri,shi,fen;/////////////////////////////////////////////////红外sbit HW_IRQ = P3 ^ 2; // 定义38KHz一体化红外接收头与CPU的连接unsigned char DT;static unsigned char data IRCode[3],IRCON,IRCON2;//////////////////////////////////////////////////蜂鸣器sbit BEEP =P1^1;/****************************************************************************** *************** 函数名称:DS18B20_Delay()* 功能:DS18B20软件延时专用* 入口参数:count 延时参数,值越大,延时越长* 出口参数:无******************************************************************************* **************/void DS18B20_Delay(uint count) //延时函数{while(count--);}/****************************************************************************** *************** 函数名称:DS18B20_Init()* 功能:DS18B20初始化* 入口参数:无* 出口参数:返回值为1则初始化成功* 返回值为0则初始化失败******************************************************************************* **************/uchar DS18B20_Init(void){uchar x = 0;DQ = 1; // DQ复位DS18B20_Delay(8); // 稍做延时DQ = 0; // 单片机将DQ拉低DS18B20_Delay(80); // 精确延时,大于480usDQ = 1; // 拉高总线DS18B20_Delay(14); // 稍做延时后x = DQ; // 若x=0则初始化成功,若x=1则初始化失败DS18B20_Delay(20);return (~x);}/****************************************************************************** *************** 函数名称:DS18B20_Read1Byte()* 功能:从DS18B20读一个字节* 入口参数:无* 出口参数:从DS18B20读出的一个字节******************************************************************************* **************/uchar DS18B20_Read1Byte(void){uchar i = 0;uchar dat = 0;for(i=8;i>0;i--){DQ = 0; // 给脉冲信号dat >>= 1;DQ = 1; // 给脉冲信号if(DQ) dat |= 0x80;DS18B20_Delay(4);}return (dat);}/****************************************************************************** *************** 函数名称:DS18B20_Write1Byte()* 功能:向DS18B20写一个字节* 入口参数:dat 要写入DS18B20的一字节数据* 出口参数:无******************************************************************************* **************/void DS18B20_Write1Byte(uchar dat){uchar i = 0;for(i=8;i>0;i--){DQ = 0;DQ = dat&0x01;DS18B20_Delay(5);DQ = 1;dat>>=1;}}/****************************************************************************** *************** 函数名称:Read_Disp_Temperature()* 功能:读取并显示温度* 入口参数:无* 出口参数:无******************************************************************************* **************/double Read_Disp_Temperature(void){uint a = 0, b = 0, c = 0,d = 0,e = 0, t = 0;double tt = 0;DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0x44); // 启动温度转换DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0xBE); // 读取温度寄存器a = DS18B20_Read1Byte();b = DS18B20_Read1Byte();t = b;t <<= 8;t = t | a;//tt = t * 0.0625;return t;}//***************************************************************** //函数名称:delay(uint t)延时函数。
12864图形液晶显示器c程序
lcd12864图形液晶显示器c程序#define _LCD12864_E//#include"lcd12864.h"#include"dtype.h"#include<reg52.h>sbit lcd_rw=P2^0;sbit lcd_rs=P2^1;sbit lcd_cs2=P2^2;sbit lcd_cs1=P2^3;sbit lcd_e=P3^0;sbit lcd_busy=P0^7;INT8U lcd_page_grobal,lcd_line_grobal; /** 函数名称:lcd_LScreen()* 函数功能:选择显示屏的左半屏*/ void lcd_LScreen(){lcd_cs2=0;lcd_cs1=1;}/** 函数名称:lcd_RScreen()* 函数功能:选择显示屏的右半屏*/ void lcd_RScreen(){lcd_cs1=0;lcd_cs2=1;}/** 函数名称:lcd_ChkBusy()* 函数功能:查询忙状态*/void lcd_ChkBusy(){while(lcd_busy){lcd_e=0;lcd_rs=0;lcd_rw=1;P0=0xff;lcd_e=1;lcd_e=0;}}/* 函数名称:lcd_WriteCmd()* 函数功能:写命令cmd--待写命令*/void lcd_WriteCmd(const INT8U cmd){lcd_ChkBusy();lcd_rs=0;lcd_rw=0;P0=cmd;lcd_e=1;lcd_e=0;}/* 函数名称:lcd_WriteData()* 函数功能:写数据dat--待写数据*/void lcd_WriteData(const INT8U dat){lcd_ChkBusy();lcd_rs=1;lcd_rw=0;P0=dat;lcd_e=1;lcd_e=0;}/* 函数名称:lcd_StartLine()* 函数功能:设定起始行line--列号* 说明:用户需自己保证行号的有效性*/ void lcd_StartLine(INT8U line){INT8U tmp;tmp=line;tmp=tmp|0x40;lcd_WriteCmd(tmp);}/* 函数名称:lcd_StartPage()* 函数功能:设定起始页* 入口参数:page--页号* 说明:用户需自己保证页号的有效性*/ void lcd_StartPage(INT8U page){INT8U tmp;tmp=page;tmp|=0xb8;lcd_WriteCmd(tmp);}/* 函数名称:lcd_Ready()* 函数功能:显示屏初始化*/void lcd_Ready(){INT8U i,j;lcd_LScreen();lcd_WriteCmd(0x3f); //开显示lcd_RScreen();lcd_WriteCmd(0x3f); //开显示lcd_LScreen();for(i=0;i<8;i++){lcd_StartPage(i);lcd_StartLine(0);for(j=0;j<64;j++){lcd_WriteData(0);}}lcd_RScreen();for(i=0;i<8;i++){lcd_StartPage(i);lcd_StartLine(0);for(j=0;j<64;j++){lcd_WriteData(0);}}}/** 函数名称:lcd_Display(INT8U *ptr) * 函数功能:16*16显示* 入口参数:*ptr--图片数据指针lcd_page_grobal--页地址lcd_line_grobal--列地址调用方法:lcd_page_grobal=xx;lcd_line_grobal=xx;ptr=&picture;lcd_Ready();lcd_Display(ptr);*/void lcd_Display(INT8U *ptr){INT8U i,j;lcd_StartPage(lcd_page_grobal);lcd_StartLine(lcd_line_grobal);for(i=0;i<16;i++){lcd_WriteData(*ptr);ptr++;}lcd_StartPage(lcd_page_grobal+1);lcd_StartLine(lcd_line_grobal);for(j=0;j<16;j++){lcd_WriteData(*ptr);ptr++;}}void main( void ){lcd_page_grobal=xx;lcd_line_grobal=xx;ptr=&picture;lcd_Ready();lcd_Display(ptr);}。
LCD12864显示中文及图片C程序
/****************************************屏幕显示驱动*****************************************/#include "GT23L24T3Y.h"#include "print.h"#include <stdio.h>#include <string.h>#include "bmp_picture.h"#include "lcd_12864.h"#include "..\user\rtc.h"u8 comTable[]={4,5,6,7,3,2,1,0};extern void Setlcd_Addr ( u8 row,u8 column );//外部函数调用声明extern u8 Num_Code[];//字库获得函数extern u8 Big_Num_Code[];//字库获得函数extern u8 Picture_Code[];//字库获得函数extern u8 arrow1[];extern u8 arrow2[];u8 testlcd[]="测试数据";/************************************************************************//显示中文输出//函数名:print_16//功能:显示16x16点阵字符串。
// 函数名:print_16// 功能:显示16点阵字符串// 形参:// row:x轴// column:y轴// *lcd:显示字符串// logic:显示取反// wei.显示位值// len长度*************************************************************************/void _print_15 ( u8 row,u8 column,const char *lcd,u8 logic ,u8 wei,u8 len){u8 w=0,x=0,y=0,l=0,read_data=0;u8 Length=0;GT_cs1;//字库片选至高for ( l=len; l>0; l=l-2 ) //总字节{w=*lcd;if ( w&0x80 ) //为1则为汉字,为0则为ASCII码{GT_cs0; //字库片选选定GT23_Write ( GT23_write_15 ( lcd ) ); //写入字库指令以及文字地址for ( x=0; x<2; x++ ){Setlcd_Addr (row,column);for(y=0;y<16;y++){read_data=GT23_Read();if(logic == true){// read_data = ~read_data;}WriteData(read_data );}row++;}GT_cs1;//字库片选至高row-=2;column+=16;if(column>=128){row+=2;column=0;}lcd=lcd+2;}}}/************************************************************************//描述:显示中文输出//使用:顶层函数调用参数:row 行column 列*lcd 字符串logic 反白*************************************************************************/ void print_15 ( u8 row,u8 column,const char *lcd,u8 logic ){u8 c=strlen ( lcd );_print_15(row,column,lcd,logic,0,c);}/************************************************************************ //描述:显示图片输出//使用:顶层函数调用参数:row 行column 列*lcd 字符串logic 反白*************************************************************************/ void print_array(u16 row,u16 column,u16 size_x,u16 size_y,const u8 *ptr, u8 logic){u8 w=0,x=0,y=0,l=0,read_data=0;u8 Length=0;for( x=0;x<size_x/8;x++){Setlcd_Addr (row,column);for(y=0;y<size_y;y++){read_data=*( ptr + (y+x*size_y) );if(logic == true){read_data = ~read_data;}WriteData1(read_data);// WriteData1(0XFF);}row++;}}u8 OpMgsCode[][10] ={"病人信息","循环播放","房号与床号","从机音量","对比度","广播""恢复","音乐","主机音量","时间"};u8 DayCode[][7]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};void PrintMainFace(time mytime,u8 PeopleNum){//待机界面函数u8 Hrd,Ten,One;Lcd_Clr();//清屏print_15 ( 0,16, "月",false );print_15 ( 0,48, "日",false );print_15 ( 0,70, &DayCode[mytime.day][0],false );//显示星期//日期显示Ten=mytime.month/10;One=mytime.month%10;print_array(0 , 0, 16 , 7 , &Num_Code[Ten*14], false);print_array(0 , 8, 16 , 7 , &Num_Code[One*14], false);Ten=mytime.date/10;One=mytime.date%10;print_array(0 , 32, 16 , 7 , &Num_Code[Ten*14], false);print_array(0 , 40, 16 , 7 , &Num_Code[One*14], false);//时间显示Ten=mytime.hour/10;One=mytime.hour%10;print_array(2 , 20, 32 , 21 , &Big_Num_Code[Ten*84], false);print_array(2 , 42, 32 , 21 , &Big_Num_Code[One*84], false);Ten=mytime.minute/10;One=mytime.minute%10;print_array(2 , 68, 32 , 21 , &Big_Num_Code[Ten*84], false);print_array(2 , 90, 32 , 21 , &Big_Num_Code[One*84], false);//住院人数显示print_15 ( 6,32, "住院人数",false );Hrd=PeopleNum/100;PeopleNum=PeopleNum%100;Ten=PeopleNum/10;One=PeopleNum%10;if(Hrd ){print_array(6 , 96, 16 , 7 , &Num_Code[Hrd*14], false);}print_array(6 , 102, 16 , 7 , &Num_Code[Ten*14], false);print_array(6 , 110, 16 , 7 , &Num_Code[One*14], false);}void PrintPictureFace(u8 Index){time mytime;Lcd_Clr();//清屏mytime.month = 10;mytime.date = 16;mytime.hour = 12;mytime.minute = 15;mytime.day =3;PrintMainFace(mytime,96);//print_array(0 , 10, 48 , 8 , arrow1, false);//左箭头显示// print_array(0,38 ,48 ,48 , &Picture_Code[288*Index], false);//图片显示// print_array(0,108, 48 , 8 , arrow2, false); //右箭头显示//print_15 ( 6,33, &OpMgsCode[0][Index],false );//提示信息显示}。
12864液晶显示源程序(方法2)
main函数:*****12864显示********//***作者:曹江*****//*****时间:2008 8 25 ********/#include<Lcd.h>#include<absacc.h>#include "AT89X51.h"//函数名:main() 主函数//函数参数:无//返回值:无void main(){reset(); //调用复位函数dison_off(1); //开lcd显示set_startline(0); // 从第0行开始从上至下滑动显示clear(); //清屏while(1){display();}}lcd.c子函数:#include "AT89X51.h"#include "Lcd.h"#include "data.h"#define uint unsigned int//函数名:delay() 延时函数//函数参数:uint v//返回值:无void delay(uint v){ uint i;while(v!=0){v--;for(i=125;i>0;i--);}}//函数名:busy_check() 检测忙状态左//函数参数:无//返回值:无void busy_check(void){unsigned char busy;while(busy&0x80){busy=0xff;}}//函数名:reset()复位函数//函数参数:无//返回值:无void reset(){P3_2=0; //接lcd复位端口RSTdelay(1);P3_2=1;delay(1);}//函数名:wcode(c,cs1,cs2)写指令函数//函数参数:uchar c, uchar cs1,uchar cs2//返回值:无void wcode(ucharc,uchar cs1,uchar cs2){busy_check();P3_4=cs1;P3_3=cs2;P3_7=0; //接lcd的rs端P3_6=0; //接lcd的rw端P1=c; //lcd数据端d0-d7P3_5=0; //接lcd的e端delay(5);P3_5=1;delay(5);P3_5=0;}//函数名:wdata(c,cs1,cs2)写数据函数//函数参数:uchar c, uchar cs1,uchar cs2//返回值:无void wdata(ucharc,uchar cs1,uchar cs2){busy_check();P3_4=cs1;P3_3=cs2;P3_7=1;P3_6=0;P1=c;P3_5=0;delay(1);P3_5=1;delay(1);P3_5=0;}//函数名:set_startline(i)设置起始行函数//函数参数:uchar i//返回值:无void set_startline(uchar i)//每次加一使其从第0行开始从上至下滑动显示{i=0xc0+i;wcode(i,0,0); //调用写指令函数}//函数名:set_adr(x,y)设置页值,起始列值函数//函数参数:uchar x,uchar y//返回值:无void set_adr(uchar x ,uchar y){x=x+0xb8; //X位址即页page起始0xb8y=y+0x40; //Y位址即列起始0x40wcode(x,0,0);//调用写函数wcode(y,0,0);}//函数名:dison_off(uint o)开关显示函数//函数参数:uint o//返回值:无void dison_off(uchar o){o=o+0x3e;wcode(o,0,0);}//函数名:clear() 清屏函数//函数参数:无//返回值:无void clear(){uchari,loop;for(i=0;i<8;i++){set_adr(i,0);for(loop=0;loop<64;loop++)wdata(0x00,0,0); //左右半屏同时写0}}//函数名:chinese(x,y,n,cs1,cs2) 汉字函数//函数参数:x,y,n,cs1,cs2 注:x,y为页和列号;n为字号;cs1,cs2为左右屏显示//返回值:无void chinese(ucharx,uchary,ucharn,uchar cs1,uchar cs2){ uchari,loop;for(i=0;i<2;i++){set_adr(x+i,y);//一字分上下两页写for(loop=0;loop<16;loop++){wdata(Chinese_Charcter[n][16*i+loop],cs1,cs2);}}}//函数名:display() 显示函数//函数参数:无//返回值:无void display(){uchar i;for(i=0;i<0xff;i++) //汉字上下滚屏显示{set_startline(i);chinese(0,32,0,1,0); //第0行第1个字“长”,屏左边显示chinese(0,48,1,1,0); //第0行第2个字“江”,屏左边显示chinese(0,0,2,0,1); //第0行第3个字“大”,屏右边显示chinese(0,16,3,0,1); //第0行第4个字“学”,屏右边显示chinese(2,16,4,1,0); //第1行第5个字“电”,屏左边显示chinese(2,32,5,1,0); //第1行第5个字“子”,屏左边显示chinese(2,48,6,1,0); //第1行第6个字“信”,屏左边显示chinese(2,0,7,0,1); //第1行第5个字“息”,屏右边显示chinese(2,16,8,0,1); //第1行第7个字“学”,屏右边显示chinese(2,32,9,0,1); //第1行第8个字“院”,屏右边显示chinese(4,32,10,1,0); //第2行第9个字“电”,屏左边显示chinese(4,48,11,1,0); //第2行第10个字“气”,屏左边显示chinese(4,0,12,0,1); //第2行第11个字“工”,屏右边显示chinese(4,16,13,0,1); //第2行第12个字“程”,屏右边显示chinese(4,32,14,0,1); //第2行第13个字“系”,屏右边显示chinese(6,48,15,1,0); //第6行第21个字“曹”,屏左边显示chinese(6,0,16,0,1); //第6行第22个字“江”,屏右边显示delay(10);i+=5;}}data.h:#ifndef _DATA_H_#define _DATA_H_//**********显示文字部分*********////左右分屏写,同页同行内按左到右顺序写extern uchar code Chinese_Charcter[25][32]={{/*-- 文字: 长--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x80,0x80,0x80,0xFF,0xA0,0xA0,0x90,0x90,0x88,0x84,0x82,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x00,0xFF,0x40,0x21,0x12,0x04,0x08,0x10,0x30,0x60,0x20,0x00,0x00, },{/*-- 文字: 江--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x60,0x01,0xC6,0x30,0x00,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,0x00, 0x04,0x04,0x7E,0x01,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00, },{/*-- 文字: 大--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00, 0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00, },{/*-- 文字: 学--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00, 0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00, },{/*-- 文字: 电--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00, },{/*-- 文字: 子--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00, 0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, },{/*-- 文字: 信--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x40,0x30,0xFC,0x07,0x0A,0xA8,0xA8,0xA9,0xAE,0xAA,0xA8,0xA8,0x08,0x08,0x00, 0x00,0x00,0x00,0x7F,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00, },{/*-- 文字: 息--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00, 0x00,0x20,0x38,0x01,0x3D,0x41,0x41,0x45,0x59,0x41,0x41,0x71,0x00,0x08,0x30,0x00, },{/*-- 文字: 学--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00, 0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00, },{/*-- 文字: 院--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0xFE,0x02,0x32,0x4A,0x86,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x0C,0x04,0x00, 0xFF,0x00,0x02,0x04,0x83,0x41,0x31,0x0F,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00, },{/*-- 文字: 电--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00, },{/*-- 文字: 气--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x20,0x10,0x8C,0xA7,0xA4,0xA4,0xA4,0xA4,0xA4,0xA4,0xA4,0x24,0x04,0x04,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00, },{/*-- 文字: 工--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00, },{/*-- 文字: 程--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x12,0xD2,0xFE,0x91,0x11,0x80,0xBF,0xA1,0xA1,0xA1,0xA1,0xBF,0x80,0x00,0x00, 0x04,0x03,0x00,0xFF,0x00,0x41,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x40,0x00, },{/*-- 文字: 系--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x02,0x22,0xB2,0xAA,0x66,0x62,0x22,0x11,0x4D,0x81,0x01,0x01,0x00,0x00, 0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00, },{/*-- 文字: 曹--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x02,0x02,0xFA,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xFA,0x02,0x00, 0x00,0x00,0x00,0x7E,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00, },{/*-- 文字: 江--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x60,0x01,0xC6,0x30,0x00,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,0x00, 0x04,0x04,0x7E,0x01,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00, },};#endif仿真效果图:。
51单片机 c语言 12864 st7920 完美液晶示波器
void lcd_init()
{
delayms(3);
lcd_wcmd(0x30);
delayms(1); //选择基本指令集
lcd_wcmd(0x30); //选择8bit数据流
show_str(" ");
lcd_wcmd(0x98);
show_str(" ");
}
/*------------------清整个GDRAM空间----------------------------*/
void clr_gdram()
{ unsigned char x,y; //1.5s
}
for (i=0;i<8;i++)
{
AD_OUT=1;
AD_CLK=1;
al<<=1;
if (AD_OUT) al|=0x01;
AD_CLK=0;
}
AD_CS=1;
ad=(unsigned int)ah;ad<<=8;ad|=al;
return (ad);
a++;
}
if(a==0)
new_lie[t]=lie[t];
}
}
a=0;
}
void sure_lie() //p=temp
{
uchar a=0;
if(t<8)
{
sure_newlie();
return (0x80+y);
51单片机带字库12864液晶动态汉字显示C语言源程序
51单片机带字库12864液晶动态汉字显示C语言源程序2009-10-17 19:36实验芯片为:AT89S52,带字库液晶屏:12864,实现的目的:动态一个汉字一个汉字显示。
其实和显示汉字的程序一样,只是稍做一下修改即可。
C语言源程序如下:#include <stdio.h>#include <math.h>#include <reg52.h>#include <string.h>sbit RS=P2^4;sbit WRD=P2^5;sbit E=P2^6;sbit PSB=P2^1;sbit RES=P2^3;void TransferData(char data1,bit DI);void delayms(unsigned int n);void delay(unsigned int m);void lcd_mesg003(unsigned char code *addr1);unsigned char code IC_DAT[]={"我是一个中国人啊"};void initinal(void){delay(40);PSB=1; //并口工作模式delay(1);RES=0; //复位delay(1);RES=1; //复位置高delay(10);TransferData(0x30,0);delay(100);TransferData(0x30,0);delay(37);TransferData(0x08,0);delay(100);TransferData(0x10,0);delay(100);TransferData(0x0C,0);delay(100);TransferData(0x01,0);delay(10);TransferData(0x06,0);delay(100);}void main(void){while(1){initinal();//调用LCD字库初始化程序delay(100);lcd_mesg003(IC_DAT);}}void lcd_mesg003(unsigned char code *addr1){unsigned char i;//第一行TransferData(0x80,0);delay(100);for(i=0;i<16;i++){TransferData(*addr1,1);addr1++;delayms(50);}}void TransferData(char data1,bit DI) //传送数据或是命令,当DI=0时,传送命令,当DI=1时,传送数据{WRD=0;RS=DI;delay(1);P0=data1;E=1;delay(1);E=0;}void delayms(unsigned int n){unsigned int i,j;for(i=0;i<n;i++)for(j=0;j<2000;j++);}void delay(unsigned int m){unsigned int i,j;for(i=0;i<m;i++)for(j=0;j<10;j++);}原理就是在显示每个汉字的时候加了一个延时程序,当然可以用定时器来实现,这样的话,不占用CPU处理时间。
lcd12864c语言编程详解
12864系列点阵型液晶显示模块使用说明书一、OCM12864液晶显示模块概述1.OCM12864液晶显示模块是128×64点阵型液晶显示模块,可显示各种字符及图形,可与CPU直接接口,具有8位标准数据总线、6条控制线及电源线。
采用KS0107控制IC。
2.外观尺寸:113×65×11mm(ocm12864-1), 93×70×10mm(ocm12864-2)78×70×10mm(ocm12864-3),3.视域尺寸:73.4×38.8mm(ocm12864-1) 70.7×38mm(ocm12864-2),64×44mm(ocm12864-3)4.重量:大约g补充说明:外观尺寸可根据用户的要求进行适度调整。
二、最大工作范围1、逻辑工作电压(Vcc):4.5~5.5V2、电源地(GND):0V3、LCD驱动电压(Vee):0~-10V4、输入电压:Vee~Vdd5、工作温度(Ta):0~55℃(常温) / -20~70℃(宽温)6、保存温度(Tstg):-10~65℃三、电气特性(测试条件 Ta=25,Vdd=5.0+/-0.25V)1、输入高电平(Vih):3.5Vmin2、输入低电平(Vil):0.55Vmax3、输出高电平(Voh):3.75Vmin4、输出低电平(Vol):1.0Vmax5、工作电流:2.0mAmax四、接口说明12864-3A接口说明表五、指令描述1、显示开/关设置CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:设置屏幕显示开/关。
DB0=H,开显示;DB0=L,关显示。
不影响显示RAM(DD RAM)中的内容。
2、设置显示起始行CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:执行该命令后,所设置的行将显示在屏幕的第一行。
12864LCD液晶显示屏程序(南京航空航天大学金城学院)
附:实验箱程序#include<reg52.h>#include<ABSACC.H>typedef unsigned char uchar;typedef unsigned int uint;#define LLCD_CMD_WR XBYTE[0xfe04] //地址需根据实际情况计算改变(下同)#define LLCD_CMD_RD XBYTE[0xfe06]#define LLCD_DATA_WR XBYTE[0xfe05]#define LLCD_DATA_RD XBYTE[0xfe07]#define RLCD_CMD_WR XBYTE[0xfe00]#define RLCD_CMD_RD XBYTE[0xfe02]#define RLCD_DATA_WR XBYTE[0xfe01]#define RLCD_DATA_RD XBYTE[0xfe03]sbit busy=P0^7;code uchar hanzil[]={0x08,0x64,0x23,0xA6,0xAA,0xA2,0xAA,0xB4,0xA3,0xA2,0xA6,0x2A,0x22,0x62,0x20,0x00,0x00,0x00,0x00,0xFF,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4B,0xF8,0x00,0x00,0x00,0x00,/*"管",0*/0x42,0x42,0xFE,0x42,0x42,0x00,0x40,0x5E,0x50,0xD0,0x5F,0x50,0x50,0x5E,0x40,0x00,0x10,0x10,0x0F,0x08,0x04,0x00,0xFF,0x01,0x01,0x7F,0x01,0x3F,0x41,0x81,0x7F,0x00,/*"瑞",1*/0x00,0x00,0x60,0x50,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x98,0xF0,0x70,0x00,0x00,0x00,0x00,0x20,0x30,0x28,0x28,0x24,0x24,0x22,0x22,0x21,0x20,0x30,0x18,0x00,0x00,/*"2",0*/0x00,0x00,0x00,0x60,0x90,0x08,0x08,0x10,0x20,0x10,0x08,0x08,0x90,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,/*"心",0*/0x00,0x00,0x00,0x60,0x90,0x08,0x08,0x10,0x20,0x10,0x08,0x08,0x90,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,/*"心",0*/0x00,0xE0,0xF0,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x18,0x10,0xF0,0xC0,0x00,0x00,0x00,0x00,0x11,0x33,0x22,0x22,0x22,0x22,0x22,0x32,0x11,0x1D,0x0F,0x03,0x00,0x00,/*"9",3*/0x00,0x00,0x00,0x60,0x90,0x08,0x08,0x10,0x20,0x10,0x08,0x08,0x90,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,/*"心",0*/0x00,0x00,0x30,0x30,0x08,0x08,0x88,0x88,0x88,0x88,0x58,0x70,0x30,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x20,0x20,0x20,0x20,0x20,0x20,0x31,0x11,0x1F,0x0E,0x00,0x00,/*"3",5*/0x00,0x00,0x30,0x30,0x08,0x08,0x88,0x88,0x88,0x88,0x58,0x70,0x30,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x20,0x20,0x20,0x20,0x20,0x20,0x31,0x11,0x1F,0x0E,0x00,0x00,/*"3",6*/0x00,0x00,0x60,0x50,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x98,0xF0,0x70,0x00,0x00,0x00,0x00,0x20,0x30,0x28,0x28,0x24,0x24,0x22,0x22,0x21,0x20,0x30,0x18,0x00,0x00,/*"2",7*/0x00,0x00,0x60,0x50,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x98,0xF0,0x70,0x00,0x00,0x00,0x00,0x20,0x30,0x28,0x28,0x24,0x24,0x22,0x22,0x21,0x20,0x30,0x18,0x00,0x00,/*"2",8*/0x00,0x00,0x30,0x30,0x08,0x08,0x88,0x88,0x88,0x88,0x58,0x70,0x30,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x20,0x20,0x20,0x20,0x20,0x20,0x31,0x11,0x1F,0x0E,0x00,0x00,/*"3",9*/0x00,0x00,0x20,0x10,0x08,0x10,0x20,0x00,0x00,0x20,0x10,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x08,0x08,0x04,0x02,0x00,0x00,0x00,0x00,0x00,/*"未命名文件",0*/};void lcd_cmd_wr(uchar cmdcode,uchar right);void lcd_data_wr(uchar ldata,uchar right);void lcd_busy_rd(uchar right);void lcd_hanzi_wr(uchar posx,uchar posy,uchar *hanzi);void lcd_str_wr(uchar row,uchar col,uchar n,uchar *str);void lcd_rol();void lcd_init();void delay(uint nms);void main(){lcd_init();lcd_str_wr(1,1,13,hanzil); //起始行、列、汉字长度delay(100);while(1){lcd_rol();delay(1000);}}void lcd_cmd_wr(uchar cmdcode,uchar right) {lcd_busy_rd(right);if(right==1){ RLCD_CMD_WR=cmdcode; }else{ LLCD_CMD_WR=cmdcode; }}void lcd_data_wr(uchar ldata,uchar right) {lcd_busy_rd(right);if(right==1){RLCD_DATA_WR=ldata;}else{LLCD_DATA_WR=ldata;}}void lcd_busy_rd(uchar right){if(right==0)RLCD_CMD_RD;elseLLCD_CMD_RD;}void delay(uint nms){uint i;for(;nms>0;nms--)for(i=0;i<500;i++);}void lcd_init(void) //LCD初始化子程序{uint k,m;lcd_cmd_wr(0x3e+1,0);lcd_cmd_wr(0xc0+0,0);lcd_cmd_wr(0xb8+0,0);lcd_cmd_wr(0x40+0,0);lcd_cmd_wr(0x3e+1,1);lcd_cmd_wr(0xc0+0,1);lcd_cmd_wr(0x40+0,1);lcd_cmd_wr(0xb8+0,1);for(k=0;k<8;k++) //页循环{for(m=0;m<64;m++) //列循环{lcd_data_wr(0x00,0);lcd_data_wr(0x00,1);}lcd_cmd_wr(0xb8+k+1,0);lcd_cmd_wr(0x40+0,0);lcd_cmd_wr(0xb8+k+1,1);lcd_cmd_wr(0x40+0,1);}}void lcd_hanzi_wr(uchar posx,uchar posy,uchar*hanzi) //显示汉字子程序{uchar i;if(posy<4) //左半屏{lcd_cmd_wr(0xb8+2*posx,0);lcd_cmd_wr(0x40+16*posy,0);for(i=0;i<16;i++){lcd_data_wr(hanzi[i],0);}lcd_cmd_wr(0xb8+2*posx+1,0);lcd_cmd_wr(0x40+16*posy,0);for(i=16;i<32;i++){lcd_data_wr(hanzi[i],0);}}else //右半屏{lcd_cmd_wr(0xb8+posx*2,1);lcd_cmd_wr(0x40+16*(posy-4),1);for(i=0;i<16;i++){lcd_data_wr(hanzi[i],1);}lcd_cmd_wr(0xb8+2*posx+1,1);lcd_cmd_wr(0x40+16*(posy-4),1);for(i=16;i<32;i++){lcd_data_wr(hanzi[i],1);}}}void lcd_str_wr(uchar row,uchar col,uchar n,uchar*str) {uchar i;for(i=0;i<n;i++){if(col>7){row++;col=col-8;}lcd_hanzi_wr(row,col,str+i*32);col++;}}void lcd_rol(void) //滚动上移子程序{uchar i;for(i=0;i<64;i++){lcd_cmd_wr(0xc0+i,0);lcd_cmd_wr(0xc0+i,1);delay(10);}}PROTEUS仿真实验现象。
tlc0832的C语言程序(用12864显示)
tlc0832程序(C语言)这是调试好的tlc0832程序,用12864液晶显示,输入电压为0~5V,数字量为0~255。
模拟量显示的不是实际电压,只是为了说明问题而取数字量的0.02倍送到液晶显示。
#include <reg51.h>#include"12864.h"#include"0832.h"#define uchar unsigned char#define uint unsigned intuchar code asc[]="0123456789";uchar code str1[]="双通道AD转换实验";uchar code str2[]="通道CH0 CH1";uchar code str3[]="数字";uchar code str4[]="模拟";void show_string(uchar add,uchar *p){lcd_drive(0,add);while(*p!='\0')lcd_drive(1,*p++);}void static_show() //显示静态{show_string(0x80,str1);show_string(0x90,str2);show_string(0x88,str3);show_string(0x98,str4);}void show_ad() //显示两个通道的结果{float t;uint m;lcd_drive(0,0x8b);lcd_drive(1,asc[ch0.date/100]);lcd_drive(1,asc[ch0.date%100/10]);lcd_drive(1,asc[ch0.date%10]);lcd_drive(1,' ');lcd_drive(1,' ');lcd_drive(1,' ');lcd_drive(1,asc[ch1.date/100]);lcd_drive(1,asc[ch1.date%100/10]);lcd_drive(1,asc[ch1.date%10]);t=ch0.date*0.02;//电压,这个不是实际电压!m=(uint)(t*100);//取2位小数lcd_drive(0,0x9b);lcd_drive(1,asc[m/100]);lcd_drive(1,'.');lcd_drive(1,asc[m%100/10]);lcd_drive(1,asc[m%10]);t=ch1.date*0.02;m=(uint)(t*100);//取2位小数lcd_drive(1,' ');lcd_drive(1,asc[m/100]);lcd_drive(1,'.');lcd_drive(1,asc[m%100/10]);lcd_drive(1,asc[m%10]);}void main(){lcd_init();static_show();while(1){get_ch0_ch1();show_ad();}}以下为12864液晶头文件#ifndef _12864_h_#define _12864_h_#include<reg51.h>#define uchar unsigned char #define uint unsigned intsbit rs=P2^5;//LCD 4sbit rw=P2^6;//5sbit e=P2^7;//6void delay_lcd(uchar x) {uchar y;for(;x>0;x--){for(y=200;y>0;y--);}}void lcd_drive(bit x,uchar d) {e=0;rw=0;//writers=x;e=1;delay_lcd(1);P0=d;delay_lcd(2);e=0;delay_lcd(2);}void lcd_init()lcd_drive(0,0x0c);//start 12864 open lcd_drive(0,0x01);//clear lcddelay_lcd(50);}#endif以下为0832头文件#ifndef _0832_h_#define _0832_h_#include<reg51.h>#define uchar unsigned char#define uint unsigned int#define a (0x06<<5)//0通道命令字#define b (0x07<<5)//1通道命令字sbit cs=P3^4; //1pinsbit dout=P3^5; //6pinsbit clk=P3^7; //7pinsbit di=P3^6; //5pinstruct ad_0832uchar date;//对应通道的数字量}ch0,ch1;void send_cmd(uchar cmd)//向0832发送4位命令字{uchar i;for(i=0;i<4;i++){clk=1;if(cmd&0x80)di=1;elsedi=0;cmd<<=1;clk=0;}}uchar recive_8bit()//收0832的8bit{uchar d,i;clk=0;clk=1;for(i=0;i<8;i++){d<<=1;clk=0;d|=dout;clk=1;}return d;}void get_ch0_ch1() {clk=0;cs=0;send_cmd(a);ch0.date=recive_8bit(); cs=1;clk=0;cs=0;send_cmd(b);ch1.date=recive_8bit(); cs=1;}#endif。
12864显示程序
{
Wan=temp_data/10000+0x30 ;
temp_data=temp_data%10000;
Qian=temp_data/1000+0x30 ;
temp_data=temp_data%1000;
Delay5us();
ADXL345_SCL = 0;
Delay5us();
}
ADXL345_RecvACK();
}
/**************************************
{
ADXL345_SDA = 1;
ADXL345_SCL = 1;
Delay5us();
ADXL345_SDA = 0;
Delay5us();
}
void ADXL345_SendACK(bit ack)
{
ADXL345_SDA = ack;
ADXL345_SCL = 1;
Delay5us();
void ADXL345_Single_Write(uchar REG_Address,uchar REG_data)
{
ADXL345_Start();
ADXL345_SendByte(SlaveAddress);
ADXL345_SendByte(REG_Address);
#include<reg52.h>
#include<intrins.h>
#include<math.h>
#include<stdio.h>
12864显示程序实例
/* 合肥工业大学HFUT邮编:2330011地址:屯溪路193号*/#include<reg52.h>#define uint unsigned int#define uchar unsigned charsbit rs=P0^4;sbit e=P0^5;sbit rw=P0^6;sbit psb=P0^7;uchar num[]="合肥工业大学";uchar num1[]="邮编";uchar num2[]="地址屯溪路0193号";void delay(uint x)//延时x毫秒{uchar i;while(x--)for(i=0;i<110;i++);}void com(uchar com)//写指令{rs=0;//rs=0:MPU进行读模块操作时,指向地址寄存器;当MPU进行写模块操作时,指向指令寄存器rw=0;//写操作P2=com;delay(5);e=1;//使能信号,高电平有效delay(5);e=0;//把数据锁存}void dat(uchar dat)//写数据{rs=1;//rs=1:无论MPU读/写操作,均指向数据寄存器rw=0;P2=dat;delay(5);e=1;delay(5);e=0;//把数据锁存}void init()//初始化液晶{com(0x01); //清屏com(0x30); //功能设置。
8字节界面,基本指令集。
(0011 x0xx)com(0x0c); //显示设置。
整体显示,光标不显示,光标不反向。
(0000 1110)com(0x06); //输入方式设置。
光标右移,地址位加1;整体右移。
(0000 0110)com(0x14); //光标右移。
}void disp(){uchar i;com(0x81);for(i=0;i<12;i++){dat(num[i]);delay(4);}}void disp1(){com(0x93);dat(0x48);dat(0x46);dat(0x55);dat(0x54);}void disp2(){uchar i;com(0x88);for(i=0;i<4;i++){dat(num1[i]);}com(0x8A);dat(0x32);dat(0x33);dat(0x30);dat(0x30);dat(0x31);dat(0x31);}void disp3(){uchar i;com(0x98);for(i=0;i<16;i++){dat(num2[i]);}}void main(){init();disp();disp1();disp2();disp3(); while(1); }。
12864程序实例三篇
12864程序实例三篇篇一:不带字库12864程序实例/******************************************************************* **************************///程序部分开始///******************************************************************* **************************//头文件定义///******************************************************************* **************************/#include<reg52.h>//包含头文件#include<string.h>//用于指针/******************************************************************* **************************//接口定义///******************************************************************* **************************/#defineLCM12864_DB7_DB0P0//定义LCM12864的数据总线sbitLCM12864_RS=P2^3;//定义LCM12864的RS控制线sbitLCM12864_RW=P2^4;//定义LCM12864的RW控制线sbitLCM12864_E=P2^2;//定义LCM12864的E控制线sbitLCM12864_CS1=P2^7;//定义LCM12864的CS1控制线sbitLCM12864_CS2=P2^6;//定义LCM12864的CS2控制线sbitLCM12864_RESET=P2^5;//定义LCM12864的RESET控制线sbitLCM12864_LEDK=P2^0;//定义LCM12864的LEDK(BLK)控制线/******************************************************************* **************************//数据定义//定义LCM12864的命令字/******************************************************************* **************************/#defineLCM12864_DISP_ON0x3f//打开LCM12864显示#defineLCM12864_DISP_OFF0x3e//关闭LCM12864显示#defineLCM12864_START_ROW0xc0//显示起始行0,可以用LCM12864_START_ROW+x设置起始行。
12864显示程序
if(u0 < 16) u0 = 16; // 输出值应不小于1(扩大16倍)
u1 = u0; // 更新u1、e1和e2
e2 = e1;
e1 = e0;
++j;
i++;
break;
case 0xde:num=2;
DisplayOneChar(i,3,f[num]);
hc[j]=num;
++j;
i++;
break;
case 0xbe:num=3;
while(temp!=0xf0)
{
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xe7:num=0;
if(back==1)
{
gone=0;
back=0;
}
}
}
}
void keyscan()
{
P2=0xfe;
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xee:num=1;
lcd12864c语言编程详解
12864系列点阵型液晶显示模块使用说明书一、OCM12864液晶显示模块概述1.OCM12864液晶显示模块是128×64点阵型液晶显示模块,可显示各种字符及图形,可与CPU直接接口,具有8位标准数据总线、6条控制线及电源线。
采用KS0107控制IC。
2.外观尺寸:113×65×11mm(ocm12864-1), 93×70×10mm(ocm12864-2)78×70×10mm(ocm12864-3),3.视域尺寸:73.4×38.8mm(ocm12864-1) 70.7×38mm(ocm12864-2),64×44mm(ocm12864-3)4.重量:大约g补充说明:外观尺寸可根据用户的要求进行适度调整。
二、最大工作范围1、逻辑工作电压(Vcc):4.5~5.5V2、电源地(GND):0V3、LCD驱动电压(Vee):0~-10V4、输入电压:Vee~Vdd5、工作温度(Ta):0~55℃(常温) / -20~70℃(宽温)6、保存温度(Tstg):-10~65℃三、电气特性(测试条件 Ta=25,Vdd=5.0+/-0.25V)1、输入高电平(Vih):3.5Vmin2、输入低电平(Vil):0.55Vmax3、输出高电平(Voh):3.75Vmin4、输出低电平(Vol):1.0Vmax5、工作电流:2.0mAmax四、接口说明12864-3A接口说明表五、指令描述1、显示开/关设置CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:设置屏幕显示开/关。
DB0=H,开显示;DB0=L,关显示。
不影响显示RAM(DD RAM)中的内容。
2、设置显示起始行CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:执行该命令后,所设置的行将显示在屏幕的第一行。
12864液晶显示汉字程序
/*=============================程序说明=============================== 项目名称: 显示汉字作者:创建日期:修改说明:程序说明:(1)CPU 型号:(2)时钟频率:(3)实现功能:(4)程序概述:===================================================================*/ //==========================头文件加载=============================== #include <mega16.h>#include <delay.h>#include "music.h"//===========================端口声明================================ #define LcdRS PORTB.0 //#define LcdRSDDR DDRB.0 //#define LcdRW PORTB.1 //#define LcdRWDDR DDRB.1 //#define LcdEN PORTB.4 //#define LcdENDDR DDRB.4 //#define LcdRST PORTB.6 //#define LcdRSTDDR DDRB.6 //#define LcdIoIn PORTA //#define LcdIoOut PINA //#define LcdIoDDR DDRA //#define LcdIn() LcdIoDDR = 0xff //调整输入输出#define LcdOut() LcdIoDDR = 0x00//=========================全局常量声明============================== //=========================全局变量声明==============================//===========================函数声明================================ void Lcd_init(void);void Lcd_CheckBusy(void);void Lcd_WriteCommand(uint8 com);void Lcd_WriteDat(uint8 Dat);void Lcd_writeStringRom(uint8 Add, uint8 flash String[]);//============================主函数================================= void main()//主函数{//---------------------------系统初始化--------------------------Lcd_init();music_init();Lcd_writeStringRom(0x80, "梁成颂");while(1){}}//===========================功能子函数================================ void Lcd_init(void){LcdRS = 1;LcdRSDDR = 1;LcdRW = 1;LcdRWDDR = 1;LcdEN = 1;LcdENDDR = 1;LcdRST = 1; //LcdRSTDDR = 1;LcdIoIn = 1; //LcdIoDDR = 1;LcdIoIn = 0xff; //LcdIn(); //LcdRST = 0;delay_ms(20);LcdRST = 1;delay_ms(50);Lcd_WriteCommand(0x38); //系统设置delay_ms(1);Lcd_WriteCommand(0x38); //系统设置Lcd_WriteCommand(0x08); //开显示Lcd_WriteCommand(0x01); //清屏Lcd_WriteCommand(0x06); //光标设置Lcd_WriteCommand(0x0c); //开显示Lcd_WriteCommand(0x01); //清屏}void Lcd_CheckBusy(void) //怕忙检测{LcdOut();LcdRS = 0;LcdRW = 1;LcdEN = 1;while((LcdIoOut & 0x80) == 0x80);LcdEN = 0;}void Lcd_WriteCommand(uint8 com) //写指令{Lcd_CheckBusy();LcdIn();LcdRS = 0;LcdRW = 0;LcdEN = 1;LcdIoIn = com;LcdEN = 0;}void Lcd_WriteDat(uint8 Dat) //写指令{Lcd_CheckBusy();LcdIn();LcdRS = 1;LcdRW = 0;LcdEN = 1;LcdIoIn = Dat;LcdEN = 0;}void Lcd_writeStringRom(uint8 Add, uint8 flash String[]) {uint16 i = 0;Lcd_WriteCommand(Add);while(String[i] != '\0'){Lcd_WriteDat(String[i]);i++;}}。
12864-液晶显示-c语言程序
TransferData(0x36,0); //Extended Function Set:RE=1: extended instruction set
delay(37); ////大于37uS的延时程序
TransferData(0x3E,0); //EXFUNCTION(DL=8BITS,RE=1,G=1)
uchar code IC_DAT[]={
" HOT-51 "
" "
"单片机开发板"
"东流电子"
};
uchar code IC_DAT2[]={
"白日依山尽,"//0x80
"欲穷千里目,"//0x90
"黄河入海流。"//0x88
"更上一层楼。"//0x98
};
/********************************************************************
delay(37); ////大于37uS的延时程序
TransferData(0x08,0); //Display on Control
delay(100); //大于100uS的延时程序
TransferData(0x10,0); //Cursor Display Control光标设置
delay(100); //大于100uS的延时程序
void display_grapic(void);
void delayms(uint n);
void DisplayLine(uchar line1,uchar line2);
12864液晶显示C程序
#include <reg51.h>#include <intrins.h>//_nop_();延时函数用#define unchar unsigned char#define unint unsigned intsbit E=P3^0;sbit RW=P3^1;sbit RS=P3^2;sbit CS1=P3^6;sbit CS2=P3^7;char code tablenum[][16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, // 0 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, //1 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, //2 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, //3 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, //4 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, //5 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, //6 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, //7 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, //8 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, //9 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, //: 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20, //R 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00, //S 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, //.};char code tablesnum[][4]={0x00,0x7c,0x44,0x7c,//小00x00,0x00,0x7c,0x00,//小10x00,0x74,0x54,0x5c,//小20x00,0x54,0x54,0x7c,//小30x00,0x3c,0x20,0x7c,//小40x00,0x5c,0x54,0x74,//小50x00,0x7c,0x54,0x74,//小60x00,0x04,0x04,0x7c,//小70x00,0x7c,0x54,0x7c,//小80x00,0x5c,0x54,0x7c,//小90x08,0x08,0x08,0x08,};//void delay(unint i)//{//while(--i);//}void readbusy()//是否忙碌{P0=0x00;RS=0;RW=1;E=1;while(P0&0x80);E=0;}void writecommand(unchar command) //写命令{readbusy();RS=0;RW=0;P0=command;E=1;_nop_();_nop_();E=0;}void writedate(unchar date) //写数据{readbusy();RS=1;RW=0;P0=date;E=1;_nop_();_nop_();E=0;}void setpage(unchar page)//设置页{page=0xb8|page;writecommand(page);}void setline(unchar line)//设置行{line=0xc0|line;writecommand(line);}void setcolumn(unchar column)//设置列{column=column&0x3f;column=0x40|column; writecommand(column);}void setonoff(unchar onoff){onoff=0x3e|onoff;writecommand(onoff);}void selectscreen(unchar screen)//选屏{switch(screen){case 0:CS1=0;CS2=0;break;case 1:CS1=0;CS2=1;break;case 2:CS1=1;CS2=0;break; default: break;}}void clearscreen(unchar screen)//清屏{unchar i,j;selectscreen(screen);for(i=0;i<8;i++){setpage(i);setcolumn(0);for(j=0;j<64;j++){writedate(0x00);}}}void InitLCD()//初始化readbusy();selectscreen(0);setonoff(0);selectscreen(0);setonoff(1);selectscreen(0);clearscreen(0);setline(0);}void display(unchar ss,unchar page,unchar column,unchar j)//显示数据{unchar i;selectscreen(ss);setpage(page);setcolumn(column);for(i=0;i<8;i++){writedate(tablenum[j][i]);}setpage(page+1);setcolumn(column);for(i=0;i<8;i++){writedate(tablenum[j][i+8]);}}void displays(unchar ss,unchar page,unchar column,unchar j)//显示小数据{unchar i;selectscreen(ss);setpage(page);setcolumn(column);for(i=0;i<4;i++){writedate(tablesnum[j][i]);}}void disnum()//显示数据{display(1,0,1*8,11);display(1,0,2*8,10);display(1,0,3*8,1);display(1,0,4*8,1);display(1,0,5*8,13);display(1,0,6*8,1);display(2,0,1*8,12);display(2,0,2*8,10);display(2,0,3*8,1);display(2,0,4*8,1);display(2,0,5*8,13);display(2,0,6*8,1);}void dissnum()//显示坐标数据{//displays(1,2,0*4,9);//displays(1,2,1*4,0); displays(1,3,0*4,7); displays(1,3,1*4,5);//displays(1,4,0*4,6);//displays(1,4,1*4,0); displays(1,5,0*4,4); displays(1,5,1*4,5);//displays(1,6,0*4,3);//displays(1,6,1*4,0); displays(1,7,0*4,1); displays(1,7,1*4,5);}void diszhou()//坐标轴{unchar i,j,a,b; selectscreen(1);for(i=2;i<7;i++){setcolumn(11);setpage(i);writedate(0xff);}setcolumn(11);setpage(7);writedate(0x0f);for(j=3;j<16;j++){displays(1,7,j*4,10); }for(b=2;b<7;b++){setcolumn(12);setpage(b);writedate(0x08);}setcolumn(12);setpage(7);writedate(0x08); for(a=0;a<16;a++) {displays(2,7,a*4,10); }}void main(){InitLCD(); clearscreen(0); writecommand(0xc0); disnum();dissnum();diszhou();while(1); }。
lcd12864c语言显示任意位置
#include<pic.h>#define uint unsigned int#define uchar unsigned char#include<pic.h>#define RS RD2#define CS2 RD1#define CS1 RD0#define E RD4#define RW RD3#define BUSY RB7uchar (*p)[32];uchar tab3[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x 20,/*"a",0*/0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x 00/*"b",1*/};uchar tab0[]={0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x 00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x 00,/*"电",0*/0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x 00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00/*"子",1*/};uchar tab1[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x 00,/*"0",0*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x 00,/*"1",1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x 00,/*"2",2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x 00,/*"3",3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x 00/*"4",4*/};/*"4",3*/uchar tab2[]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x 00,/*"5",0*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x 00,/*"6",1*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x 00,/*"7",2*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x 00,/*"8",3*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x 00/*"9",4*/};//写指令代码(左)void l_w_code(char l_code){//check_busy();PORTD=0x12;PORTB=l_code;E=1;E=0;asm("nop");}//写显示数据(左)void l_w_data(char l_data){//check_busy();PORTD=0x16;PORTB=l_data;E=1;E=0;asm("nop");}//写指令代码(右)void r_w_code(charr_code) {//check_busy();PORTD=0x11;PORTB=r_code;E=1;E=0;//asm("nop");}//写显示数据(右)void r_w_data(char r_data) {//check_busy();PORTD=0x15;PORTB=r_data;E=1;E=0;asm("nop");}void initializeLCD(void){l_w_code(0x3f);l_w_code(0xc0);l_w_code(0xb8);l_w_code(0x40);r_w_code(0x3f);r_w_code(0xc0);r_w_code(0xb8);r_w_code(0x80);}void c_display(uintq,uintw,uint e) {ucharm,n;uchari,x,y=0x40;uint k=0,j=1;if(w>8){w=w-8;j=0;}for(i=1;i<w;i++){y=y+0x08;}switch(q){case 1:x=0xb8;break;case 2:x=0xba;break;case 3:x=0xbc;break;case 4:x=0xfe;break; default:break;}switch(e){case 0:k=0;break;case 1:k=16;break;case 2:k=32;break;case 3:k=48;break;case 4:k=64;break;case 5:k=0;break;case 6:k=16;break;case 7:k=32;break;case 8:k=48;break;case 9:k=64;break; default:k=0;break;}if(j){for (m=0;m<2;m++){for(n=0;n<8;n++){l_w_code(x); //写入页地址l_w_code(y);if((e<10)&&(e>4)){ l_w_data(tab2[k++]);}else if(e<5){ l_w_data(tab1[k++]);}else{ l_w_data((*p)[k++]);}y=y+0x01;}y=y-0x08;x+=0x01;}}else{for (m=0;m<2;m++){for(n=0;n<8;n++){r_w_code(x); //写入页地址r_w_code(y);if((e<10)&&(e>4)){ r_w_data(tab2[k++]);}else if(e<5){ r_w_data(tab1[k++]);}else{ r_w_data((*p)[k++]);}y=y+0x01;}y=y-0x08;x+=0x01;}}}void l_display(uintq,uint w){ucharm,n;uchari,x,y=0x40;uint k=0,j=1;if(w>8){w=w-8;j=0;}for(i=1;i<w;i++){y=y+0x08;}switch(q){case 1:x=0xb8;break;case 2:x=0xba;break;case 3:x=0xbc;break;case 4:x=0xbe;break; default:break;}if(j){for (m=0;m<2;m++){for(n=0;n<16;n++){l_w_code(x); //写入页地址l_w_code(y);l_w_data((*p)[k++]);y=y+0x01;}y=y-0x10;x+=0x01;}}else{for (m=0;m<2;m++){for(n=0;n<16;n++){r_w_code(x); //写入页地址r_w_code(y);r_w_data((*p)[k++]);y=y+0x01;}y=y-0x10;x+=0x01;}}}void delaycnt(unsigned intcnt) {while(--cnt);}void main(void){TRISD=0X00;TRISB=0X00; initializeLCD();while(1){p=&tab0[0]; //显示电子l_display(3,3);p=&tab0[32];l_display(3,5);c_display(3,7,1); //显示1202 c_display(3,8,2);c_display(3,9,0);c_display(3,10,2);p=&tab3[0]; //显示abc_display(2,11,10);p=&tab3[16];c_display(2,12,10);}}/*x=4,0<y<16c_display(x,y,z);表示在第x行,第Y列,显示z(数字1-9).如果要显示其他字符,z=10,每个字母16个字符,p=&tab3[0];表示显示第一个字母,p=&tab3[16];表示显示第二个字母P=&tab0[0];l_display(x,y);这里y不能为8和16,表示在第X行,第Y列和Y+1列显示tab0[]的第一个汉子,每个汉子32个字符,显示tab0[]里面的第二个就是从p=&tab2[32]开始*/。