#include "REG51.h" sbit LCD_SCL=P1^0; //时钟 D0(SCLK) sbit LCD_SDA=P1^1; //D1(MOSI) 数据 sbit LCD_RST=P1^2; //复位 sbit LCD_DC =P1^3; //数据/命令控制 #define XLevelL 0x00 #define XLevelH 0x10 #define XLevel ((XLevelH&0x0F)*16+XLevelL) #define Max_Column 128 #define Max_Row 64 #define Brightness 0xCF #define X_WIDTH 128 #define Y_WIDTH 64 void LCD_DLY_ms(unsigned int ms) //LCD 延时1ms { unsigned int a; while(ms) { a=1800; while(a--); ms--; } return; } void LCD_WrDat(unsigned char dat) //**LCD写数据 { unsigned char i=8; LCD_DC=1; for(i=0;i<8;i++) //发送一个八位数据 { LCD_SCL=0; LCD_SDA=dat&0x80; LCD_SCL=1; dat<<=1; } } void LCD_WrCmd(unsigned char cmd) //****LCD写命令 { unsigned char i=8; LCD_DC=0; for(i=0;i<8;i++) //发送一个八位数据 { LCD_SCL=0; LCD_SDA=cmd&0x80; LCD_SCL=1; cmd<<=1;; } } void LCD_Setxy(unsigned char x, unsigned char y) //LCD 设置坐标 { LCD_WrCmd(0xb0+y); LCD_WrCmd(((x&0xf0)>>4)|0x10); LCD_WrCmd((x&0x0f)|0x01); } void LCD_Fill(unsigned char bmp_dat) //bmp_dat=0x00全屏灭,bmp_dat=0xff全屏亮 { unsigned char y,x; for(y=0;y<8;y++) { LCD_WrCmd(0xb0+y); LCD_WrCmd(0x01); LCD_WrCmd(0x10); for(x=0;x<X_WIDTH;x++) LCD_WrDat(bmp_dat); } } /*void LCD_CLS(void) //LCD复位 { unsigned char y,x; for(y=0;y<8;y++) { LCD_WrCmd(0xb0+y); LCD_WrCmd(0x01); LCD_WrCmd(0x10); for(x=0;x<X_WIDTH;x++) LCD_WrDat(0); } }*/ void LCD_Init(void) //LCD初始化 { LCD_SCL=1; LCD_RST=0; LCD_DLY_ms(50); LCD_RST=1; //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 LCD_WrCmd(0xae);//--关闭显示 turn off oled panel LCD_WrCmd(0x00);//---设置低列地址 set low column address LCD_WrCmd(0x10);//---高列地址 set high column address LCD_WrCmd(0x40);//--设置起始地址映射内存显示开始行(0x 00 ~ 0x3f) set start line address Set Mapping RAM Display Start Line (0x00~0x3F) LCD_WrCmd(0x81);//--设置对比度控制寄存器 set contrast control register LCD_WrCmd(0xcf); // 电流输出亮度设置赛格 Set SEG Output Current Brightness LCD_WrCmd(0xa1);//--设置赛格/列映射 0xa0左右反置0xa1正常 Set SEG/Column Mapping 0xa0左右反置 0xa1正常 LCD_WrCmd(0xc8);//设置网站/行扫描方向 0xc0上下反置 0xc8正常 Set COM/Row Scan Direction LCD_WrCmd(0xa6);//--正常显示 set normal display LCD_WrCmd(0xa8);//--集复用率(1 - 64) set multiplex ratio(1 to 64) LCD_WrCmd(0x3f);//--1/64 duty LCD_WrCmd(0xd3);//-设置显示偏移位移映射内存计数器(0x 00 ~ 0x3f) set display offset Shift Mapping RAM Counter (0x00~0x3F) LCD_WrCmd(0x00);//-不偏移 not offset LCD_WrCmd(0xd5);//--设置显示时钟的分频比/振荡器频率 set display clock divide ratio/oscillator frequency LCD_WrCmd(0x80);//--组分比,时钟设置为100帧/秒 set divide ratio, Set Clock as 100 Frames/Sec LCD_WrCmd(0xd9);//--设定充电周期 set pre-charge period LCD_WrCmd(0xf1);//15集充电放电1钟钟表 Set Pre-Charge as 15 Clocks & Discharge as 1 Clock LCD_WrCmd(0xda);//--设置组件的引脚配置硬件 set com pins hardware configuration LCD_WrCmd(0x12); LCD_WrCmd(0xdb);//--集vcomh set vcomh LCD_WrCmd(0x40);//威科姆取消水平集 Set VCOM Deselect Level LCD_WrCmd(0x20);//-设置页面寻址模式(0x 00 /将/ 0x02) Set Page Addressing Mode (0x00/0x01/0x02) LCD_WrCmd(0x02);// LCD_WrCmd(0x8d);//--充电泵启用/禁用 set Charge Pump enable/disable LCD_WrCmd(0x14);//--集(0x 10个)禁用 set(0x10) disable LCD_WrCmd(0xa4);// 使整个显示(0xa4 / 0xa5) Disable Entire Display On (0xa4/0xa5) LCD_WrCmd(0xa6);// 禁用反显示(0xa6 / 7) Disable Inverse Display On (0xa6/a7) LCD_WrCmd(0xaf);//--打开面板 turn on oled panel LCD_Fill(0x00); //初始清屏 LCD_Setxy(0,0); } void LCD_6x8(unsigned char x, y,unsigned char ch[])//显示6*8一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7 { unsigned char c=0,i=0,j=0; while (ch[j]!='\0') { c =ch[j]-32; if(x>126) {x=0;y++;} LCD_Setxy(x,y); for(i=0;i<6;i++) LCD_WrDat(F6x8[c][i]); x+=6; j++; } } void LCD_Cler_6x8(unsigned char x,y,n)//清除N个6*8字符 { unsigned int i=0; LCD_Setxy(x,y); if(x>126) {x=0;y++;} for(i=0;i<6*n;i++) LCD_WrDat(0x00); } void ready(unsigned char x,y,unsigned int num) { switch (num) { case 0: LCD_6x8(x,y,"0");break; case 1: LCD_6x8(x,y,"1");break; case 2: LCD_6x8(x,y,"2");break; case 3: LCD_6x8(x,y,"3");break; case 4: LCD_6x8(x,y,"4");break; case 5: LCD_6x8(x,y,"5");break; case 6: LCD_6x8(x,y,"6");break; case 7: LCD_6x8(x,y,"7");break; case 8: LCD_6x8(x,y,"8");break; case 9: LCD_6x8(x,y,"9");break; } } /*void LCD_8x16(unsigned char x, y,unsigned char ch[])//显示8*16一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7 { unsigned char c=0,i=0,j=0; while (ch[j]!='\0') { c =ch[j]-32; if(x>120) {x=0;y++;} LCD_Setxy(x,y); for(i=0;i<8;i++) LCD_WrDat(F8X16[c*16+i]); LCD_Setxy(x,y+1); for(i=0;i<8;i++) LCD_WrDat(F8X16[c*16+i+8]); x+=8; j++; } } void LCD_Cler_8x16(unsigned char x, y,n) //清除n个8*16字符 { unsigned char i; if(x>120) {x=0;y++;} LCD_Setxy(x,y); for(i=0;i<8*n;i++) LCD_WrDat(0x00); LCD_Setxy(x,y+1); for(i=0;i<8*n;i++) LCD_WrDat(0x00); } void LCD_16x16(unsigned char x, y, N)//显示16*16点阵 显示的坐标(x,y),y为页范围0~7 { unsigned char wm=0; unsigned int adder=32*N; // LCD_Setxy(x , y); for(wm = 0;wm < 16;wm++) // { LCD_WrDat(F16x16[adder]); adder += 1; } LCD_Setxy(x,y + 1); for(wm = 0;wm < 16;wm++) // { LCD_WrDat(F16x16[adder]); adder += 1; } } void LCD_Cler_16x16(unsigned char x,y,n)//清除n个16*16字 { unsigned char i=0; LCD_Setxy(x,y); for(i=0;i<16*n;i++) LCD_WrDat(0x00); LCD_Setxy(x,y+1); for(i=0;i<16*n;i++) LCD_WrDat(0x00); } void Draw_BMP(unsigned char x0, y0,x1, y1,unsigned char BMP[])//显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7* { unsigned int j=0; unsigned char x,y; if(y1%8==0) y=y1/8; else y=y1/8+1; for(y=y0;y<y1;y++) { LCD_Setxy(x0,y); for(x=x0;x<x1;x++) { LCD_WrDat(BMP[j++]); } } }*/
6 * 8
#include<reg51.h> const unsigned char code F6x8[][6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % 0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : 0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < 0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = 0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R 0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W 0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X 0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y 0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] 0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines };