单片机 > 单片机程序设计 > 详情

单片机+LCD12864数字电压表设计

发布时间:2023-09-06 发布时间:
|

单片机源程序如下:

//---库函数声明及相关定义---//

#include

#include

#define unint unsigned int

#define unchar unsigned char

#define Databus P1 /*液晶数据总线*/

sbit RS=P3^3; /*数据指令 选择*/

sbit RW=P3^4; /*读写 选择*/

sbit EN=P3^2; /*读写使能*/

sbit cs1=P3^6; /*片选1*/

sbit cs2=P3^7; /*片选2*/



sbit clock=P0^4;//时钟线

sbit dout=P0^2;//数据输出端

sbit cs=P0^3;//片选(低电平有效)



sbit DQ=P0^2;//ds18b20与单片机连接口

float f_temp;//浮点型温度值

unsigned int tvalue;//温度值

unsigned char tflag;

unsigned int temp=0;

unsigned char SegBuf[4]={0};


/********************************/

/* 定义中文字库 */

/********************************/

unchar code Hzk[]={

0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00, //年//0

0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,

0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,//月//1

0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,//日//2

0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,//星//3

0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00,

0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,//期//4

0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00,

0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,//时//5

0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,

0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xC0,0x40,0x00,//分//6

0x00,0x80,0x40,0x20,0x10,0x0F,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,

0x12,0x12,0xD2,0xFE,0x91,0x11,0xC0,0x38,0x10,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,//秒//7

0x04,0x03,0x00,0xFF,0x00,0x83,0x80,0x40,0x40,0x20,0x23,0x10,0x08,0x04,0x03,0x00,


0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,//天//8

0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00,

0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,//一//9

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00,//二//10

0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,

0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,//三//11

0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,//四//12

0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00,

0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00,//五//13

0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00,

0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00,//六//14

0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00,


0x00,0x40,0x42,0x44,0x4C,0x40,0x40,0x7F,

0x40,0x40,0x48,0x44,0xE6,0x40,0x00,0x00,

0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x44,

0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,//当//15


0x08,0x08,0xE8,0x29,0x2A,0x2E,0xE8,0x08,

0x08,0xCC,0x0A,0x0B,0xE8,0x0C,0x08,0x00,

0x00,0x00,0xFF,0x09,0x49,0x89,0x7F,0x00,

0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,//前//16


0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,//电//17

0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,

0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,

0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,


0x00,0x00,0xFE,0x02,0x82,0x82,0x82,0x82,

0xFE,0x82,0x82,0x82,0xC3,0x82,0x00,0x00,

0x40,0x30,0x0F,0x40,0x40,0x40,0x40,0x40,

0x7F,0x40,0x42,0x44,0x4C,0x60,0x40,0x00,//压//18



0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,

0x49,0x49,0x7F,0x00,0x00,0x80,0x00,0x00,

0x01,0x81,0x41,0x21,0x1D,0x21,0x41,0x7F,

0x89,0x89,0x8D,0x89,0x81,0xC1,0x41,0x00,//是//19


0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x31,0x7B,0x7B,0x31,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//://20


0x80,0x40,0x20,0xF8,0x27,0x20,0x20,0x20,//伏//21

0x20,0xFF,0x20,0x24,0x28,0x38,0x20,0x00,

0x00,0x00,0x00,0xFF,0x80,0x40,0x20,0x18,

0x06,0x01,0x06,0x18,0x60,0xC0,0x40,0x00



};

/****************************************/

/* 定义ASCII字库8列*16行 */

/****************************************/

unchar code Ezk[]={

/*此字体下对应的点阵为:宽x高=8x16 --*/

/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07, //0

0x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00, //1

0x00,0x30,0x38,0x08,0x88,0xF8,0x70,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00, // 2

0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00, //3

0x00,0x00,0xF8,0xF8,0x00,0xE0,0xE0,0x00,0x00,0x03,0x03,0x02,0x02,0x0F,0x0F,0x02,//4

0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,//5

0x00,0xC0,0xE0,0x78,0x58,0xC8,0x80,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//6

0x00,0x08,0x08,0x88,0xE8,0x78,0x18,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00,//7

0x00,0x70,0xF8,0xC8,0x88,0xF8,0x70,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x07,0x00,//8

0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x00,0x09,0x0D,0x0F,0x03,0x01,0x00,//9



0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // - -//10

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x80,0x80,0xE0,0xE0,0x80,0x80,0x00, // -+-//11

0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,


0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, // ---//12

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -.-//13

0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00

};




/*状态检查,LCD是否忙*/

void CheckState()

{

unchar dat; /*状态信息,判断是否忙*/

RS=0; /*数据指令选择,D/I(RS)=“L” ,表示 DB7∽DB0 为显示指令数据*/

RW=1; /*R/W=“H” ,E=“H”数据被读到DB7∽DB0*/

do{

Databus=0x00;

EN=1; /*EN下降源*/

_nop_(); /*一个时钟延时*/

dat=Databus;

EN=0;

dat=0x80 & dat;/*仅当第7位为0时才可操作(判别busy信号)*/

}while(!(dat==0x00));

}

/*写命令到LCD中*/

SendCommandToLCD(unchar com)

{

CheckState();/*状态检查,LCD是否忙*/

RS=0; /*向LCD发送命令。RS=0写指令,RS=1写数据*/

RW=0; /*R/W=“L” ,E=“H→L”数据被写到 IR 或 DR */

Databus=com; /*com :命令*/

EN=1; /*EN下降沿*/

_nop_();

_nop_();

EN=0;

}

/*设置页 0xb8是页的首地址*/

void SetLine(unchar page)

{

page=0xb8|page; /*1011 1xxx 0<=page<=7 设定页地址--X 0-7,8行为一页64/8=8,共8页*/

SendCommandToLCD(page);

}

/*设定显示开始行,0xc0是行的首地址*/

void SetStartLine(unchar startline)

{

startline=0xc0|startline; /*1100 0000*/

SendCommandToLCD(startline); /*设置从哪行开始:0--63,一般从0 行开始显示*/

}

/*设定列地址--Y 0-63 ,0x40是列的首地址*/

void SetColumn(unchar column)

{

column=column &0x3f; /*column最大值为64,越出 0=

column= 0x40|column; /*01xx xxxx*/

SendCommandToLCD(column);

}

/*开关显示,0x3f是开显示,0x3e是关显示*/

void SetOnOff(unchar onoff)

{

onoff=0x3e|onoff

[1] [2]


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
MSP430低功耗模式-while循环失效