RM新时代网站-首页

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

12位AD DS1621與12864液晶的單片機(jī)程序概述

2oON_changxuemc ? 來(lái)源:未知 ? 作者:易水寒 ? 2018-07-19 16:46 ? 次閱讀

DS1621與lcd12864和單片機(jī)接口仿真原理圖



//EDM12864B DRIVE//

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

PAGEADD為頁(yè)地址起使

TIERADD為行地址起使

DIS_STARTADD為開(kāi)始命令

CTABLE為漢字字庫(kù)數(shù)組

ETABLE為英文字庫(kù)數(shù)組

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

#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,//測(cè)(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)

};

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

顯示用的延時(shí)函數(shù)

延時(shí)長(zhǎng)度有參數(shù) n 決定

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

Delay_nms(uchar n)

{ uchar a;

for(;n>0;n--)

{

for(a=0;a<100;a++)

{

_nop;

_nop;

_nop;

_nop;

};

};

}

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

DEM12864B狀態(tài)檢測(cè),從EDM12864B讀出數(shù)

據(jù)檢測(cè)標(biāo)志位BF

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

void LCD_Busy()

{

uchar busy;

E=Low;

DI=Low;

RW=High;

while(1)

{

E=High;

_nop;

_nop;

busy=P2;//讀狀態(tài)標(biāo)志寄存器

_nop;

E=Low;

if((busy&0x90)==0)//檢測(cè)BF和RES位,兩者都為零時(shí)表示可進(jìn)行寫入

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;

}

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

寫一個(gè)字節(jié)的顯示數(shù)據(jù)

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

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;

}

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

讀顯示數(shù)據(jù)

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

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

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時(shí)鐘時(shí)序要求的數(shù)據(jù)建立時(shí)間,

nop_可以用其它短延時(shí)替代,比如喂狗

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

I2C_delay()

{

uchar n=5;

while(n--)

{

_nop;

_nop;

}

}

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

I2C的時(shí)鐘信號(hào)可發(fā)送和接收.

接收時(shí)通過(guò)判斷sample對(duì)寄存器的值加.

發(fā)送的時(shí)候只調(diào)用程序產(chǎn)生時(shí)序.

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

bit I2C_clock(void)

{

bit sample;

I2C_delay();

I2C_SCL=High;

I2C_delay();

sample=I2C_SDA;

I2C_SCL=Low;

I2C_delay();

return(sample);

}

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

I2C確定接收有效的應(yīng)答信號(hào)Acknowledge

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

I2C_ACK()

{

I2C_SDA=Low;

I2C_clock();

I2C_SDA=High;

}

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

I2C的非應(yīng)答信號(hào)

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

I2C_NACK()

{

I2C_SDA=High;

I2C_clock();

I2C_SDA=High;

}

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

I2C的開(kāi)始信號(hào).發(fā)送和接受數(shù)據(jù)時(shí),必須先調(diào)用.

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

I2C_start()

{

I2C_SDA=High;

I2C_delay();

I2C_SCL=High;

I2C_delay();

I2C_SDA=Low;

I2C_delay();

I2C_SCL=Low;

I2C_delay();

}

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

I2C停止信號(hào).發(fā)送和接受數(shù)據(jù)時(shí)結(jié)束時(shí),需要調(diào)用.

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

I2C_stop()

{

I2C_SDA=Low;

I2C_delay();

I2C_SCL=High;

I2C_delay();

I2C_SDA=High;//產(chǎn)生停止控制信號(hào),并且釋放數(shù)據(jù)線

I2C_delay();

}

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

I2C初始化.在main函數(shù)中必須先調(diào)用它.

進(jìn)行初始化后才能調(diào)用其他函數(shù).

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

void I2C_init(void)

{

I2C_SDA=High;

I2C_SCL=High;

I2C_delay();

I2C_stop();

}

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

I2C總線寫一個(gè)字節(jié),即發(fā)送一個(gè)字節(jié)

發(fā)送結(jié)束后,需要返回一個(gè)檢測(cè)應(yīng)答位

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

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()); //返回應(yīng)答信號(hào)

}

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

I2C總線讀一個(gè)字節(jié),即接收一個(gè)字節(jié)數(shù)據(jù)

接收結(jié)束后需要發(fā)送一個(gè)應(yīng)答位acknowledge

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

uchar I2C_receive()

{

uchar a,receive_data;

for(a=0;a<8;a++)

{

receive_data=receive_data<<1;

if(I2C_clock())

{

receive_data++;

};

};

//I2C_ACK();

return(receive_data);

}

DS1621_start()

{

do

{

I2C_start();

}

while(I2C_send(0x90));//發(fā)送數(shù)據(jù)完地址字節(jié)的數(shù)據(jù)時(shí),檢測(cè)從機(jī)的應(yīng)答位

if(I2C_send(0xee)==0)

{

I2C_stop();

return 1;

}

else

return 0;

}

DS1621_stop()

{

do

{

I2C_start();

//I2C_send(0x90);

}

while(I2C_send(0x90));

if(I2C_send(0x22)==0)

{

I2C_stop();

return 1;

}

else

return 0;

}

char read_count_remain()

{

char temp_remain=0;

do

{

I2C_start();

}

while(I2C_send(0x90));//是否應(yīng)答

if(I2C_send(0xa8)==0)

{

I2C_start();

if(I2C_send(0x91)==0)

{

temp_remain=I2C_receive();

I2C_NACK();

I2C_stop();

return temp_remain;

}

else

return 0;

}

else

return 0;

}

char read_count_c()

{

char temp_c=0;

do

{

I2C_start();

}

while(I2C_send(0x90));//是否應(yīng)答

if(I2C_send(0xa9)==0)

{

I2C_start();

if(I2C_send(0x91)==0)

{

temp_c=I2C_receive();

I2C_NACK();

I2C_stop();

return temp_c;

}

else

return 0;

}

else

return 0;

}

bit read_temperature(char *point1)

{

do

{

I2C_start();

}

while(I2C_send(0x90));

if(I2C_send(0xaa)==0)

{

do{

I2C_start();

}

while(I2C_send(0x91));

(*point1)=I2C_receive();

I2C_ACK();

(*(point1+1))=I2C_receive();

I2C_NACK();

I2C_stop();

return 1;

}

else

return 0;

}

DS1621_state()

{

do

{

I2C_start();

}

while(I2C_send(0x90));

if(I2C_send(0xac)==0)

{

do

{

I2C_start();

}

while(I2C_send(0x90));

if(I2C_send(0x00)==0)

//if(I2C_send(0x01)==0)

{

I2C_stop();

return 1;

}

else

return 0;

}

else

return 0;

}

DS1621_th()

{

}

DS1621_tl()

{

}

DS1621_init()

{

while(DS1621_stop()==0)

{};

while(DS1621_state()==0)

{};

DS1621_th();

DS1621_tl();

}

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

字符為16*16顯示,分為兩個(gè)部分寫入32個(gè)字節(jié)

前16個(gè)字節(jié)寫入第一頁(yè)(16*8),后16個(gè)字節(jié)寫入

第二頁(yè)(16*8)

左側(cè)寫入"歡迎",右側(cè)寫入"使用"

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

C_display_L(uchar C_Pagenum,uchar C_Tiernum,uchar C_Temp)

{

uchar k;

C_Pagenum=PAGEADD|C_Pagenum;

C_Tiernum=TIERADD|C_Tiernum;

WRCommand_L(C_Pagenum);

WRCommand_L(C_Tiernum);

for(k=0;k<16;k++)

{

WRdata_L(table2[C_Temp*32+k]);

};

C_Pagenum=C_Pagenum+1;

WRCommand_L(C_Pagenum);

WRCommand_L(C_Tiernum);

for(k=0;k<16;k++)

{

WRdata_L(table2[C_Temp*32+k+16]);

};

}

C_display_R(uchar C_Pagenum,uchar C_Tiernum,uchar C_Temp)

{

uchar k;

C_Pagenum=PAGEADD|C_Pagenum;

C_Tiernum=TIERADD|C_Tiernum;

WRCommand_R(C_Pagenum);

WRCommand_R(C_Tiernum);

for(k=0;k<16;k++)

{

WRdata_R(table2[C_Temp*32+k]);

};

C_Pagenum=C_Pagenum+1;

WRCommand_R(C_Pagenum);

WRCommand_R(C_Tiernum);

for(k=0;k<16;k++)

{

WRdata_R(table2[C_Temp*32+k+16]);

};

}

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

寫入西文字符,共11個(gè)字符,左側(cè)寫入6個(gè)

右側(cè)寫入5個(gè),左側(cè)起始從16開(kāi)始,右側(cè)從

0開(kāi)始

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

E_Display_L(uchar E_Pagenum,uchar E_Tiernum,uchar E_Temp)

{

uchar k;

WRCommand_L(PAGEADD|E_Pagenum);

WRCommand_L(TIERADD|E_Tiernum);

for(k=0;k<8;k++)

{

WRdata_L(table1[E_Temp*8+k]);

};

}

E_Display_R(uchar E_Pagenum,uchar E_Tiernum,uchar E_Temp)

{

uchar k;

WRCommand_R(PAGEADD|E_Pagenum);

WRCommand_R(TIERADD|E_Tiernum);

for(k=0;k<8;k++)

{

WRdata_R(table1[E_Temp*8+k]);

};

}

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

清除所有顯示RAM內(nèi)容

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

CLR_DisplayRAM()

{

uchar C_page,i,k;

for(i=0;i<8;i++)

{

C_page=PAGEADD|i;//清除起始頁(yè)為0

WRCommand_L(C_page);//清除起始頁(yè)寫入

WRCommand_L(TIERADD);//清除起始行地址寫入

WRCommand_R(C_page);

WRCommand_R(TIERADD);

for(k=0;k<64;k++)

{

WRdata_L(0x00);

WRdata_R(0x00);//lcm的ram自動(dòng)加一,只許循環(huán)64次即可

};

};

}

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

初始化 設(shè)置啟使行

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

void Init_LCD(void)

{

CLR_DisplayRAM();//清除所有顯示寄存器

WRCommand_L(DIS_STARADD);

WRCommand_R(DIS_STARADD);//設(shè)置顯示起始行地址

WRCommand_L(0x3f);

WRCommand_R(0x3f);//開(kāi)顯示

}

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

max1241讀轉(zhuǎn)換結(jié)果

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

uint read_max1241()

{

uint voltage_temp=0;

uchar ucloop=12;

cs=High;

//dout=low;

sclk=Low;

cs=Low;

while(dout==0);//EOC信號(hào)為高表示轉(zhuǎn)換結(jié)束

sclk=High;

sclk=Low;

while(ucloop--)

{

sclk=High;//上升沿?cái)?shù)據(jù)穩(wěn)定并讀出

voltage_temp<<=1;

if(dout==1)

voltage_temp+=1;

sclk=Low;

};

//sclk=low;

cs=High;

return voltage_temp;

}

main()

{

uchar a=0,temp=0,b=0,number=0,pagenum=0;

uchar etable[]={0,0,0,0,0,45,53,60,51,63,61,53,10,69,67,53};//Welcome use

uchar ttable[]={42,57,61,53,19,10,2,0,0,6,18,1,1,18,0,7};//Time:2006/11/07

char count_remain=0,count_c=0;

bit flag=1;

char temperature_buf[2]={0};

uchar temperature_display[8]={0};

//uchar voltage=0; //測(cè)試0831時(shí)使用

double voltage=0;

double temp_buffer=0;

cs=High;

sclk=High;

Init_LCD();

I2C_init();

DS1621_init();//初始化

DS1621_start();//開(kāi)始溫度采集

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

利用開(kāi)機(jī)顯示時(shí)間(大概三秒)空讀一次DS1621

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

for(b=0;b<2;b++)

{

for(number=0;number<20;number++)

{

//中文顯示:歡迎使用液晶模塊

pagenum=1;//在第二行開(kāi)始顯示

for(a=0;a<4;a++)

{

C_display_L(pagenum,a*16,a);

C_display_R(pagenum,a*16,a+4);

};

//英文顯示:Welcome use

pagenum=5;//在第六行顯示

for(a=0;a<3;a++)

{

E_Display_L(pagenum,(a+5)*8,etable[a+5]);

};

for(a=0;a<8;a++)

{

E_Display_R(pagenum,a*8,etable[a+8]);

};

//顯示制作時(shí)間:Time:2006/11/07

pagenum=7;//在第八行顯示

for(a=0;a<8;a++)

{

E_Display_L(pagenum,a*8,ttable[a]);

E_Display_R(pagenum,a*8,ttable[a+8]);

}

Delay_nms(100);

};

if(flag)

{

read_temperature(temperature_buf);//在轉(zhuǎn)到下一個(gè)顯示界面之前空讀一次

read_count_remain();

read_count_c();

DS1621_start();

flag=0;

};

};

WRCommand_L(0x3e);

WRCommand_R(0x3e);

CLR_DisplayRAM(); //清除顯示ram

WRCommand_L(0x3f);

WRCommand_R(0x3f);

while(1)

{

while(read_temperature(temperature_buf)==0);//讀溫度值(兩字節(jié)有符數(shù)),并檢測(cè)應(yīng)答位,只使用第一字節(jié)

count_remain=read_count_remain();//讀斜率

count_c=read_count_c();//讀計(jì)數(shù)器

temp_buffer = temperature_buf[0] -0.75 + (count_c-count_remain) / (double)count_c;

DS1621_start();//讀完數(shù)據(jù)后,重新開(kāi)始一次溫度轉(zhuǎn)化

temperature_display[0]=19;

if(temp_buffer<0)

{

temperature_display[1]=16;//顯示負(fù)號(hào)

temperature_display[2]=(-temp_buffer)/10;//十位

temperature_display[3]=((uchar)(-temp_buffer))%10;

temperature_display[4]=17;//小數(shù)點(diǎn)

temperature_display[5]=(int)((-temp_buffer)*10)%10;

temperature_display[6]=(int)((-temp_buffer)*100)%10;//小數(shù)點(diǎn)后兩位

}

else

{

temperature_display[1]=temp_buffer/100;//百位

temperature_display[2]=((uchar)temp_buffer)/10%10;

temperature_display[3]=((uchar)temp_buffer)%10;

temperature_display[4]=17;

temperature_display[5]=((int)(temp_buffer*10))%10;

temperature_display[6]=((int)(temp_buffer*100))%10;//小數(shù)點(diǎn)后兩位

}

// 測(cè)試從max1241讀出的原始數(shù)據(jù)

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

//pagenum=3;

voltage=read_max1241();

voltage_display[0]=19;

voltage_display[1]= voltage/1000;

voltage_display[2]=(voltage/100)%10;

voltage_display[3]=(voltage/10)%10;

voltage_display[4]= voltage%10;

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

//LCD顯示第二部分

for(b=0;b<40;b++)

{

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

//更新max1241顯示值

voltage=(double)read_max1241();

voltage=5000*voltage/4095;

voltage_display[0]=19;

voltage_display[5]=(uint)voltage %10;//個(gè)位

voltage_display[2]=17;

voltage_display[4]=(uint)(voltage/10)%10;//小數(shù)點(diǎn)后1位

voltage_display[3]=(uchar)(voltage/100)%10;//小數(shù)點(diǎn)后2位

voltage_display[1]=(uchar)(voltage/1000)%10;//小數(shù)點(diǎn)后3位

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

//顯示文字:電壓測(cè)量

pagenum=2;

for(a=0;a<2;a++)

C_display_L(pagenum,a*16,a+8);

for(a=0;a<2;a++)

C_display_L(pagenum,(a+2)*16,a+12);

//顯示文字:溫度測(cè)量

pagenum=5;

for(a=0;a<2;a++)

C_display_L(pagenum,a*16,a+10);

for(a=0;a<2;a++)

C_display_L(pagenum,(a+2)*16,a+12);

//顯示1241采樣值

pagenum=3;

for(a=0;a<6;a++)

{

E_Display_R(pagenum,a*8,voltage_display[a]);

}

//顯示ds1621采樣值

pagenum=6;

for(a=0;a<7;a++)

{

E_Display_R(pagenum,a*8,temperature_display[a]);

}

};

};

}

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 單片機(jī)
    +關(guān)注

    關(guān)注

    6035

    文章

    44554

    瀏覽量

    634624
  • AD
    AD
    +關(guān)注

    關(guān)注

    27

    文章

    868

    瀏覽量

    150266
  • 12864
    +關(guān)注

    關(guān)注

    0

    文章

    124

    瀏覽量

    44681
  • DS1621
    +關(guān)注

    關(guān)注

    1

    文章

    16

    瀏覽量

    11575

原文標(biāo)題:51單片機(jī)實(shí)例:12位AD_DS1621與12864液晶(程序)

文章出處:【微信號(hào):changxuemcu,微信公眾號(hào):暢學(xué)單片機(jī)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    誰(shuí)有12864顯示ds1261采集的溫度程序啊,請(qǐng)各位幫幫忙

    在Proteus中ds1621只能虛擬顯示,要在12864顯示,該怎么寫程序,求一個(gè)程序
    發(fā)表于 11-28 14:08

    12AD_DS162112864液晶

    12AD_DS162112864液晶,很實(shí)用的資料,快來(lái)學(xué)習(xí)吧。
    發(fā)表于 05-12 16:25 ?18次下載

    msp430單片機(jī)adc+12864液晶顯示菜單程序

    msp430單片機(jī)adc+12864液晶顯示菜單程序
    發(fā)表于 07-20 14:39 ?11次下載

    DS1621溫度傳感器論文

    DS1621溫度傳感器protues仿真
    發(fā)表于 03-01 11:59 ?17次下載

    反向的DS1721數(shù)字溫度傳感器DS1621的兼容性

    配置登記 有DS1621DS1721配置寄存器的幾點(diǎn)區(qū)別。一個(gè)主要的區(qū)別是在配置登記DS1621一定位存儲(chǔ)在EEPROM。圖1和圖2顯示,DS1721
    發(fā)表于 04-10 09:57 ?4次下載
    反向的<b class='flag-5'>DS</b>1721數(shù)字溫度傳感器<b class='flag-5'>DS1621</b>的兼容性

    使用51單片機(jī)實(shí)現(xiàn)12864液晶的顯示程序免費(fèi)下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是使用51單片機(jī)實(shí)現(xiàn)12864液晶的顯示程序免費(fèi)下載。
    發(fā)表于 08-29 17:28 ?17次下載
    使用51<b class='flag-5'>單片機(jī)</b>實(shí)現(xiàn)<b class='flag-5'>12864</b><b class='flag-5'>液晶</b>的顯示<b class='flag-5'>程序</b>免費(fèi)下載

    使用51單片機(jī)進(jìn)行12864液晶時(shí)鐘的C語(yǔ)言程序免費(fèi)下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是使用51單片機(jī)進(jìn)行12864液晶時(shí)鐘的C語(yǔ)言程序免費(fèi)下載。
    發(fā)表于 06-19 17:44 ?17次下載
    使用51<b class='flag-5'>單片機(jī)</b>進(jìn)行<b class='flag-5'>12864</b><b class='flag-5'>液晶</b>時(shí)鐘的C語(yǔ)言<b class='flag-5'>程序</b>免費(fèi)下載

    LCD12864DS1621數(shù)字溫度傳感器的使用仿真資料和工程文件

    本文檔的主要內(nèi)容詳細(xì)介紹的是LCD12864DS1621數(shù)字溫度傳感器的使用仿真資料和工程文件。
    發(fā)表于 07-24 17:30 ?10次下載
    LCD<b class='flag-5'>12864</b>和<b class='flag-5'>DS1621</b>數(shù)字溫度傳感器的使用仿真資料和工程文件

    DS1621溫度傳感器實(shí)驗(yàn)的程序和工程文件免費(fèi)下載

     本文檔的主要內(nèi)容詳細(xì)介紹的是DS1621溫度傳感器實(shí)驗(yàn)的程序和工程文件免費(fèi)下載。
    發(fā)表于 09-08 18:07 ?11次下載
    <b class='flag-5'>DS1621</b>溫度傳感器實(shí)驗(yàn)的<b class='flag-5'>程序</b>和工程文件免費(fèi)下載

    使用單片機(jī)實(shí)現(xiàn)DS1621測(cè)溫的仿真文件免費(fèi)下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是使用單片機(jī)實(shí)現(xiàn)DS1621測(cè)溫的仿真文件免費(fèi)下載。
    發(fā)表于 03-19 13:48 ?17次下載

    使用單片機(jī)實(shí)現(xiàn)12AD DS162112864液晶C語(yǔ)言實(shí)例免費(fèi)下載

    本文檔的主要內(nèi)容詳細(xì)介紹的是使用單片機(jī)實(shí)現(xiàn)12AD DS162112864液晶C語(yǔ)言實(shí)例免費(fèi)
    發(fā)表于 03-30 14:11 ?16次下載

    使用單片機(jī)實(shí)現(xiàn)I2C接口溫度傳感器DS1621應(yīng)用測(cè)試的C語(yǔ)言實(shí)例

    本文檔的主要內(nèi)容詳細(xì)介紹的是使用單片機(jī)實(shí)現(xiàn)I2C接口溫度傳感器DS1621應(yīng)用測(cè)試的C語(yǔ)言實(shí)例免費(fèi)下載。
    發(fā)表于 03-31 14:45 ?10次下載

    008基于單片機(jī)DS1621+MAX1241(12串口ADC)電壓溫度采樣Proteus仿真設(shè)計(jì)

    008基于單片機(jī)DS1621+MAX1241(12串口ADC)電壓溫度采樣Proteus仿真設(shè)計(jì)(220轉(zhuǎn)5v電源方案)-008基于單片機(jī)
    發(fā)表于 07-26 12:15 ?18次下載
    008基于<b class='flag-5'>單片機(jī)</b><b class='flag-5'>DS1621</b>+MAX1241(<b class='flag-5'>12</b><b class='flag-5'>位</b>串口ADC)電壓溫度采樣Proteus仿真設(shè)計(jì)

    DS1621 DS1621 - (Maxim Integrated) - 溫度傳感器 - 模擬和數(shù)字輸出

    電子發(fā)燒友網(wǎng)為你提供()DS1621相關(guān)產(chǎn)品參數(shù)、數(shù)據(jù)手冊(cè),更有DS1621的引腳圖、接線圖、封裝手冊(cè)、中文資料、英文資料,DS1621真值表,DS1621管腳等資料,希望可以幫助到廣
    發(fā)表于 11-02 08:23
    <b class='flag-5'>DS1621</b> <b class='flag-5'>DS1621</b> - (Maxim Integrated) - 溫度傳感器 - 模擬和數(shù)字輸出

    DS1721數(shù)字溫度傳感器與DS1621的反向兼容性

    由于許多應(yīng)用不需要DS0 5線數(shù)字溫度傳感器的±1621.2°C精度,因此設(shè)計(jì)了精度為±1.0°C的DS1721溫度傳感器IC,以提供DS1621的低成本替代方案。在大多數(shù)方面,DS1621
    的頭像 發(fā)表于 05-16 11:25 ?874次閱讀
    <b class='flag-5'>DS</b>1721數(shù)字溫度傳感器與<b class='flag-5'>DS1621</b>的反向兼容性
    RM新时代网站-首页