简介:本文为关于12位AD_DS1621与12864液晶的程序代码的文本格式,如需要源文件点击链接:http://www.eeskill.com/file/id/42247 下载资料就可以使用了。
//EDM12864B DRIVE//
/**************************************
PAGEADD为页地址起使
TIERADD为行地址起使
DIS_STARTADD为开始命令
CTABLE为汉字字库数组
ETABLE为英文字库数组
***************************************/
#include #define uchar unsigned char #define uint unsigned int #define High 1 #define Low 0 #define _nop {} #define PAGEADD 0xb8 #define TIERADD 0x40 #define DIS_STARADD 0xc0 uint key_value; sbit DI=P1^4; sbit E=P1^2; sbit CS1=P1^1; sbit CS2=P1^0; sbit RW=P1^3; sbit cs=P1^7; sbit sclk=P1^6; sbit dout=P1^5; sbit I2C_SCL = P3^7; sbit I2C_SDA = P3^6; //uchar ntable[]={61,49,57,60,19,49,62,49,60,63,55,2,0,0,6,22,56, //63,68,61,49,57,60,17,51,63,61};//email:analog2006@hotmail.com uchar data voltage_display[8]; /***************************** 字符表 显示"Welcome Use" ******************************/ uchar code table1[]={ 0x00,0x3e,0x51,0x49,0x45,0x3e,0x00,0x00,//0(0) 0x00,0x00,0x42,0x7f,0x40,0x00,0x00,0x00,//1 0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,//2 0x00,0x21,0x41,0x45,0x4b,0x31,0x00,0x00,//3 0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00,//4 0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,//5 0x00,0x3c,0x4a,0x49,0x49,0x30,0x00,0x00,//6 0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,//7 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,//8 0x00,0x06,0x49,0x49,0x29,0x1e,0x00,0x00,//9 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// (10) 0x00,0x00,0x00,0x47,0x00,0x00,0x00,0x00,//! 0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00,//% 0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00,//& 0x00,0x14,0x08,0x3e,0x08,0x14,0x00,0x00,//* 0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00,//+ 0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,//- 0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,//. 0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00,/// 0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,//:(19) 0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00,//= 0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00,//? 0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00,//@(22) 0x00,0x7e,0x11,0x11,0x11,0x7f,0x00,0x00,//A 0x00,0x41,0x7f,0x49,0x49,0x36,0x00,0x00,//B 0x00,0x3e,0x41,0x41,0x41,0x22,0x00,0x00,//C 0x00,0x41,0x7f,0x41,0x41,0x3e,0x00,0x00,//D 0x00,0x7f,0x49,0x49,0x49,0x49,0x00,0x00,//E 0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F 0x00,0x3e,0x41,0x41,0x49,0x7a,0x00,0x00,//G(29) 0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H 0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x00,//I 0x20,0x40,0x41,0x3f,0x01,0x01,0x00,0x00,//J 0x00,0x7f,0x08,0x14,0x22,0x41,0x00,0x00,//K 0x00,0x7f,0x40,0x40,0x40,0x40,0x00,0x00,//L 0x00,0x7f,0x02,0x0c,0x02,0x7f,0x00,0x00,//M 0x00,0x7f,0x06,0x08,0x30,0x7f,0x00,0x00,//N 0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,//O 0x00,0x7f,0x09,0x09,0x09,0x06,0x00,0x00,//P 0x00,0x3e,0x41,0x51,0x21,0x5e,0x00,0x00,//Q(39) 0x00,0x7f,0x09,0x19,0x29,0x46,0x00,0x00,//R 0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,//S 0x00,0x01,0x01,0x7f,0x01,0x01,0x00,0x00,//T 0x00,0x3f,0x40,0x40,0x40,0x3f,0x00,0x00,//U 0x00,0x1f,0x20,0x41,0x20,0x1f,0x00,0x00,//V 0x00,0x7f,0x20,0x80,0x20,0x7f,0x00,0x00,//W 0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00,//X 0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00,//Y 0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00,//Z 0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//a(49) 0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00,//b 0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00,//c 0x00,0x38,0x44,0x44,0x48,0x7f,0x00,0x00,//d 0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00,//e 0x00,0x00,0x08,0x7e,0x09,0x02,0x00,0x00,//f 0x00,0x0c,0x52,0x52,0x4c,0x3e,0x00,0x00,//g 0x00,0x7f,0x08,0x04,0x04,0x78,0x00,0x00,//h 0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00,//i 0x00,0x20,0x40,0x44,0x3d,0x00,0x00,0x00,//j 0x00,0x00,0x7f,0x10,0x28,0x44,0x00,0x00,//k(59) 0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00,//l 0x00,0x7c,0x04,0x78,0x04,0x78,0x00,0x00,//m 0x00,0x7c,0x08,0x04,0x04,0x78,0x00,0x00,//n 0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,//o 0x00,0x7e,0x0c,0x12,0x12,0x0c,0x00,0x00,//p 0x00,0x0c,0x12,0x12,0x0c,0x7e,0x00,0x00,//q 0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00,//r 0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00,//s 0x00,0x04,0x3f,0x44,0x40,0x20,0x00,0x00,//t 0x00,0x3c,0x40,0x40,0x3c,0x40,0x00,0x00,//u(69) 0x00,0x1c,0x20,0x40,0x20,0x1c,0x00,0x00,//v 0x00,0x3c,0x40,0x30,0x40,0x3c,0x00,0x00,//w 0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,//x 0x00,0x1c,0xa0,0xa0,0x90,0x7c,0x00,0x00,//y 0x00,0x44,0x64,0x54,0x4c,0x44,0x00,0x00,//z(74) }; /**************************** 中文字符表 显示"欢迎使用液晶模块" *****************************/ uchar code table2[]={ 0x14,0x24,0x44,0x84,0x64,0x1c,0x20,0x18, 0x0f,0xe8,0x08,0x08,0x28,0x18,0x08,0x00, 0x20,0x10,0x4c,0x43,0x43,0x2c,0x20,0x10, 0x0c,0x03,0x06,0x18,0x30,0x60,0x20,0x00,//欢(0) 0x40,0x41,0xce,0x04,0x00,0xfc,0x04,0x02, 0x02,0xfc,0x04,0x04,0x04,0xfc,0x00,0x00, 0x40,0x20,0x1f,0x20,0x40,0x47,0x42,0x41, 0x40,0x5f,0x40,0x42,0x44,0x43,0x40,0x00,//迎(1) 0x40,0x20,0xf0,0x1c,0x07,0xf2,0x94,0x94, 0x94,0xff,0x94,0x94,0x94,0xf4,0x04,0x00, 0x00,0x00,0x7f,0x00,0x40,0x41,0x22,0x14, 0x0c,0x13,0x10,0x30,0x20,0x61,0x20,0x00,//使(2) 0x00,0x00,0x00,0xfe,0x22,0x22,0x22,0x22, 0xfe,0x22,0x22,0x22,0x22,0xfe,0x00,0x00, 0x80,0x40,0x30,0x0f,0x02,0x02,0x02,0x02, 0xff,0x02,0x02,0x42,0x82,0x7f,0x00,0x00,//用(3) 0x10,0x61,0x06,0xe0,0x18,0x84,0xe4,0x1c, 0x84,0x65,0xbe,0x24,0xa4,0x64,0x04,0x00, 0x04,0x04,0xff,0x00,0x01,0x00,0xff,0x41, 0x21,0x12,0x0c,0x1b,0x61,0xc0,0x40,0x00,//液(4) 0x00,0x00,0x00,0x00,0x7e,0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,0x7e,0x00,0x00,0x00,0x00, 0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00, 0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,//晶(5) 0x10,0xd0,0xff,0x50,0x90,0x04,0xf4,0x54, 0x5f,0x54,0x54,0x5f,0xf4,0x04,0x00,0x00, 0x03,0x00,0xff,0x00,0x00,0x84,0x85,0x45, 0x35,0x0f,0x15,0x25,0x65,0xc4,0x44,0x00,//模(6) 0x10,0x10,0xff,0x10,0x10,0x00,0x08,0x08, 0xff,0x08,0x08,0x08,0xf8,0x00,0x00,0x00, 0x08,0x18,0x0f,0x04,0x85,0x41,0x31,0x0d, 0x03,0x05,0x09,0x11,0x31,0x61,0x21,0x00,//块(7) 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,//电(8) 0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42, 0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00, 0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20, 0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00,//压(9) 0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A, 0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F, 0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,//温(10) 0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5, 0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A, 0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,//度(11) 0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2, 0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00, 0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F, 0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,//测(12) 0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5, 0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00, 0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F, 0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,//量(13) }; /******************************** 显示用的延时函数 延时长度有参数 n 决定 *********************************/ Delay_nms(uchar n) { uchar a; for(;n>0;n--) { for(a=0;a<100;a++) { _nop; _nop; _nop; _nop; }; }; } /***************************************** DEM12864B状态检测,从EDM12864B读出数 据检测标志位BF ******************************************/ void LCD_Busy() { uchar busy; E=Low; DI=Low; RW=High; while(1) { E=High; _nop; _nop; busy=P2;//读状态标志寄存器 _nop; E=Low; if((busy&0x90)==0)//检测BF和RES位,两者都为零时表示可进行写入 break; }; } /********************************* 写指令 **********************************/ void WRCommand_L(uchar command) { CS1=High; CS2=Low; LCD_Busy(); DI=Low; _nop; RW=Low; _nop; E=High; _nop; P2=command; _nop; E=Low; _nop; } void WRCommand_R(uchar command) { CS1=Low; CS2=High; LCD_Busy(); DI=Low; _nop; RW=Low; _nop; E=High; _nop; P2=command; _nop; E=Low; _nop; } /*********************************** 写一个字节的显示数据 ************************************/ void WRdata_L(uchar ucdata) { CS1=High; CS2=Low; LCD_Busy(); DI=High; _nop; RW=Low; _nop; E=High; _nop; P2=ucdata; _nop; E=Low; _nop; } void WRdata_R(uchar ucdata) { CS1=Low; CS2=High; LCD_Busy(); DI=High; _nop; RW=Low; _nop; E=High; _nop; P2=ucdata; _nop; E=Low; _nop; } /************************************ 读显示数据 *************************************/ /******************************************** RDdata_L() { uchar receiver; CS1=High; CS2=Low; LCD_Busy(); DI=High; _nop; WR=High; _nop; E=High; _nop; receiver=P0; E=Low; return(receiver); } RDdata_R() { uchar receiver; CS1=Low; CS2=High; LCD_Busy(); DI=High; _nop; WR=High; _nop; E=High; _nop; receiver=P0; E=Low; return(receiver); } /***************************************** /************************************** I2C时钟时序要求的数据建立时间, nop_可以用其它短延时替代,比如喂狗 ***************************************/ I2C_delay() { uchar n=5; while(n--) { _nop; _nop; } } /********************************************* I2C的时钟信号可发送和接收. 接收时通过判断sample对寄存器的值加. 发送的时候只调用程序产生时序. **********************************************/ bit I2C_clock(void) { bit sample; I2C_delay(); I2C_SCL=High; I2C_delay(); sample=I2C_SDA; I2C_SCL=Low; I2C_delay(); return(sample); } /******************************************** I2C确定接收有效的应答信号Acknowledge *********************************************/ I2C_ACK() { I2C_SDA=Low; I2C_clock(); I2C_SDA=High; } /***************************************** I2C的非应答信号 ******************************************/ I2C_NACK() { I2C_SDA=High; I2C_clock(); I2C_SDA=High; } /************************************************* I2C的开始信号.发送和接受数据时,必须先调用. *************************************************/ I2C_start() { I2C_SDA=High; I2C_delay(); I2C_SCL=High; I2C_delay(); I2C_SDA=Low; I2C_delay(); I2C_SCL=Low; I2C_delay(); } /*************************************************** I2C停止信号.发送和接受数据时结束时,需要调用. ****************************************************/ I2C_stop() { I2C_SDA=Low; I2C_delay(); I2C_SCL=High; I2C_delay(); I2C_SDA=High;//产生停止控制信号,并且释放数据线 I2C_delay(); } /***************************************** I2C初始化.在main函数中必须先调用它. 进行初始化后才能调用其他函数. ******************************************/ void I2C_init(void) { I2C_SDA=High; I2C_SCL=High; I2C_delay(); I2C_stop(); } /***************************************** I2C总线写一个字节,即发送一个字节 发送结束后,需要返回一个检测应答位 ******************************************/ bit I2C_send(uchar I2C_data) { uchar a; for(a=0;a<8;a++) { I2C_SDA=(bit)(I2C_data&0x80); I2C_data=I2C_data<<1; I2C_clock(); }; I2C_SDA=High; I2C_delay(); return(I2C_clock()); //返回应答信号 } /*********************************************** I2C总线读一个字节,即接收一个字节数据 接收结束后需要发送一个应答位acknowledge ***********************************************/ uchar I2C_receive() { uchar a,receive_data; for(a=0;a<8;a++)
上一篇:51单片机数码管串行显示板制作
下一篇:51单片机8位数码管电子时钟仿真图及源代码
推荐阅读最新更新时间:2024-11-12 17:54
设计资源 培训 开发板 精华推荐
- LTC2274CUJ 演示板,16 位,105Msps 串行 ADC,1MHz
- C881492_STC单片机方案验证板-TSSOP-20封装
- 用于微功率 A/D 转换器的 LT1634ACS8-1.25 电压基准的典型应用
- 基于沁恒微ch579 墨水屏名片
- CS5265单芯片设计TYPEC转HDMI2.0 4K@60HZ转换器方案
- LTC3838 的典型应用 - 具有差分输出检测功能的双通道、快速、准确降压型 DC/DC 控制器
- FEBFAN3240_001NDA,基于 FAN3240 智能双线圈继电器驱动器的评估板
- C2845104_LDO方案验证板(C版)
- TESEO-LIV3FL low power module evaluation board
- LT3571,温度补偿型 APD 电源