51单片机实例一:12位AD_DS1621与12864液晶

发布者:悠闲时光最新更新时间:2021-02-07 来源: eefocus关键字:51单片机  12864液晶 手机看文章 扫描二维码
随时随地手机看文章

简介:本文为关于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++)

[1] [2]
关键字:51单片机  12864液晶 引用地址:51单片机实例一:12位AD_DS1621与12864液晶

上一篇:51单片机数码管串行显示板制作
下一篇:51单片机8位数码管电子时钟仿真图及源代码

推荐阅读最新更新时间:2024-11-12 17:54

51单片机开发之矩阵键盘
3.6 矩阵键盘 3.6.1 矩阵键盘原理图 要使用矩阵键盘,需要将JP4接到JP8(P1)上面,JP165跳线帽需要断开(否则会导致矩阵键盘最右一排无法正常使用)。 图3-6-1 图3-6-2 3.6.2 矩阵键盘介绍 在键盘中按键数量较多时,为了减少I/O口的占用,通常将按键排列成矩阵形式。在矩阵式键盘中,每条水平线和垂直线在交叉处不直接连通,而是通过一个按键加以连接。这样,一个端口(如P1口)就可以构成4*4=16个按键,比之直接将端口线用于键盘多出了一倍,而且线数越多,区别越明显,比如再多加一条线就可以构成20键的键盘,而直接用端口线则只能多出一键(9键),在需要的键数比较多时,采用矩阵法来做键盘是合理的。
[单片机]
<font color='red'>51单片机</font>开发之矩阵键盘
基于51单片机的红外反射式的测速机
引言 在工程实践中,经常会遇到各种需要测量转速的场合。转速是电动机极为重要的一个状态参数,在很多运动系统的测控中,都需要对电机的转速进行测量,不论是直流调速系统还是交流调速系统,只有转速的高精度检测才能得到高精度的控制系统。迄今为止,测速可分为两类:模拟电路测速和数字电路测速。随着微电子技术的发展,计算机技术的广泛应用,出现了以计算机为核心的数字测速装置。这样的速度测量装置测量范围宽、工作方式灵活多变、适应面广,具有普通数字测速装置不可比拟的快速性、精确性和优良性。 一:设计思路 用一个红外发光二极管和一个接受红外光的二极管组成一套光电管。当检测到物表面为黑色时,反射光很弱,接收端检测到的光线可以忽略,使接收端呈现一种
[单片机]
基于<font color='red'>51单片机</font>的红外反射式的测速机
基于51单片机的正弦信号发生器的设计
正弦信号是电子电路设计中非常重要的信号之一。在很多电子设备和系统中,需要正弦信号作为输入源。基于51单片机的正弦信号发生器设计是一种较为简单且常见的方法。本文将详细介绍如何设计一个基于51单片机的正弦信号发生器。 一、51单片机简介 51单片机是以英特尔公司的MCS-51单片机为核心的一族单片机,主要用于嵌入式系统和电子设备上。51单片机内部集成了CPU、RAM、ROM、计时器、串行通信接口等功能模块,具有较强的实时控制能力和通用性。 二、正弦信号的生成原理 正弦信号是一种周期性连续信号,可由谐振电路或数字信号处理的方法生成。在本文中,我们采用数字信号处理的方法来生成正弦信号。 数字信号的表示 在51单片机中,数字信号是
[单片机]
51单片机-数码管模块-计数器
#include reg52.h #define uchar unsigned char #define uint unsigned int #define ulong unsigned long sbit DULA = P2^6; sbit WELA = P2^7; unsigned char code WETable = { ~0x80,~0x40,~0x20,~0x10, ~0x08,~0x04,~0x02,~0x01 }; unsigned char code DUTable = { 0x3F,0x06,0x5B,0x4F, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x7
[单片机]
51单片机+1602+DS18B20的温度报警程序
51单片机做的温度显示,温度显示在LCD1602液晶屏上。 然后按键可以调整温度阈值,温度高于或低于所设温度,蜂鸣器就会响…… 单片机源程序如下: /************************************************************************************** * 基于单片机的实时温度报警系统设计 * (1)DS18b20采集到的温度可以实时地在数码管或者在液晶上显示出来; (2)用三个独立键盘设置阀值,包括设置键,加键
[单片机]
<font color='red'>51单片机</font>+1602+DS18B20的温度报警程序
用于51单片机的智能灌溉系统 自动浇花程序
#include reg52.h //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义 #include intrins.h #define u8 unsigned char #define u16 unsigned int #define uchar unsigned char #define uint unsigned int uchar yushe_Moisture=20; //Moisture预设值下限 uchar yushe_MoistureH=40; //Moisture
[单片机]
51单片机汇编学习例程(5)——USART串口篇
5.ASM5_USART: 串口发送0-9及换行,接收任意数据并显示 /** ****************************************************************************** * @file USART.asm * @author Alex——小白 * @version V1.0 * @date 2019.9.1 * @brief 自动发送数据0-9和换行,接收的数据会打印该数据 ****************************************************
[单片机]
<font color='red'>51单片机</font>汇编学习例程(5)——USART串口篇
MCS_51单片机与8255A的接口设计
所谓可编程的接口芯片是指其功能可由微处理机的指令来加以改变的接口芯片,利用编程的方法,可以使一个接口芯片执行不同的接口功能。目前,各生产厂家已提供了很多系列的可编程接口,MCS-51单片机常用的两种接口芯片是8255以及8155。 8255和MCS-51相连,可以为外设提供三个8位的I/O端口:A口、B口和C口,三个端口的功能完全由编程来决定。 1.  8255的内部结构和引脚排列 下图7为8255的内部结构和引脚图。 (1)A口、B口和C口。A口、B口和C口均为8位I/O数据口,但结构上略有差别。A口由一个8位的数据输出缓冲/锁存器和一个8位的数据输入缓冲/锁存器组成。B口由一个8位的数据输出缓冲/锁存器和一个8位的
[单片机]
MCS_<font color='red'>51单片机</font>与8255A的接口设计
小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved