我在写一个用12864显示DS18B20温度的程序,这几行不明白 ,求指教啊!

我在写一个用12864显示DS18B20温度的程序,这几行不明白 ,求指教啊!,第1张

write_cmd(0x93) //这行是显示的乱森位置吧

write_date(0x30+t1)//显示t1值,因为t1是数值,液晶显示器显示的是字符,所以要加上+0x30转换

write_date(0x30+t2)//显示老旦t2

write_date('.')//显示小数点

write_date(0x30+t3)//哗含亩显示t3的值

write_date(0xA1)//显示度的符号o

write_date(0xE6) //显示C

//并行连接,PSB引脚接电源正

#include <reg51.h>

#include <intrins.h>

#define uint unsigned int

#define uchar unsigned char

sbit rs=P2^0 /*数据\指令 选择*/

sbit rw=P2^1 /*读\写 选择*/

sbit e=P2^2 /*读\写使能*/

sbit ds=P3^2//18B20脚

uint temp

float ftemp

uchar code table[]="0123456789.d"

void writecom(uchar com)

void writedat(uchar dat)

void initinal(void)

delay0(int k) //把你的延时函数改为以毫秒计时的一个延时函数,但是一个“非标准的”毫秒

{

int i,j

for(i=ki>0i--)//i=xms即延时约xms毫秒

for(j=110j>0j--)

}

void dsreset() // ds18b20初始化函数档数

{

uint i

ds=0//拉低总线开始复位

i=103

while(i>0)i--

ds=1//释放总线

i=4

while(i>0)i--

// 省去了等待芯片返回应答的过程 。。。。。。

}

bit readbit(void) //ds18b20读取一个二进制位,参照时序图

{

uint i

bit dat

ds=0i++

ds=1i++,i++

dat=ds

i=8while(i>0)i--

return(dat)

}

uchar tempread(void) //ds18b20读取一个字节的数据

{

uchar i,j,dat

dat=0

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

{

j=readbit()

dat=(j<<7)|(dat>>1) //

}

return(dat)

}

void tempwrite(uchar dat) //ds18b20写入字节数据

{

uint iuchar j

bit testb

for(j=1j<=8j++)

{

testb=dat&0x01

dat=dat>>1

if(testb==1)// 写1

{

ds=0 // 拉低总线以开始一个写时序

i++i++

ds=1 // 释放总线

i=8while(i>0)i--

}

else // 写0

{

ds=0

i=8while(i>0)i--

ds=1

i++i++

}

}

}

void tempchang(void) //

{

dsreset()

delay0(1)

tempwrite(0xcc) //

tempwrite(0x44) //

}

uint gettemp() //

{

uchar a,b

dsreset()

delay0(1)

tempwrite(0xcc) //

tempwrite(0xbe) //

a=tempread() //

b=tempread()//

temp=b

temp<<=8 //////

temp=temp|a

ftemp=temp*0.0625 //

temp=ftemp*10+0.5 //

ftemp=ftemp+0.05 //

return temp //

}

//12MHZ晶振 延时50微秒

void delay50us(uint t)

{

uchar j

for(t>0t--)

for(j=19j>0j--)

}

//////////////////////////////////////////////////////////////信启///////////

//主函数

void main()

{

initinal()

while(1)

{

uint a,b,c,d

tempchang()

a=gettemp()

b=a/薯坦乱100

c=a%100/10

d=a%100%10

writecom(0x83)

writedat(table[b])

delay50us(1)

writedat(table[c])

delay50us(1)

writedat(table[10])

delay50us(1)

writedat(table[d])

delay50us(1)

writedat(table[11])

delay50us(4)

writecom(0x83)

}

}

//////////////////////////////////////////////////////////////////////////

//12864写命令

void writecom(uchar com)

{

rw=0

rs=0

delay50us(1)

P0=com

e=1

delay50us(10)

e=0

delay50us(10)

}

//12864写数据

void writedat(uchar dat)

{

rw=0

rs=1

delay50us(1)

P0=dat

e=1

delay50us(10)

e=0

delay50us(10)

}

//12864初始化

void initinal(void)

{

delay50us(2)

writecom(0x30)

delay50us(4)

writecom(0x30)

delay50us(4)

writecom(0x0f)

delay50us(4)

writecom(0x01)

delay50us(240)

writecom(0x06)

delay50us(10)

}

LCD点阵12864画温度曲线默认分类 2007-08-17 18:54:58 阅读548 评论3 字号:大中小 订阅

#include<reg51.h>

#include"LCD12864.h"

#include"zimo.h"

#include"LCD1602.h"

void hua_zuobiao(void)//画坐标

void delay1ms(uint k)//延时间

void TLC2543(void)//2543读数据子函数

void count_ad(void)//1602的显示

uchar code shuzi[]={0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}//0--8

uchar code number[]={"0123456789"}

uchar tab1[]={" wendu=+49.99c "}// 9 10. 12 13

uchar code tab2[]={"如颂 made of suwei "}

unsigned long int ad

///////////////////TLC2543

sbit clk=P1^3//时钟

sbit cs=P1^2//1变0时TLC2543复位

sbit adtain=P1^1//数据输入

sbit adtaout=P1^0//数据输出

/搏橡举///////////////

void main(void)

{uchar x,y//x页 y列

uchar i

uint j

uchar wendu=30,dp//温度//曲线的点

///////////1602

init_1602()

gotoxy(1,0)

for(i=0i<16i++)write_LCD_data(tab1[i])

gotoxy(2,0)

for(i=0i<16i++)write_LCD_data(tab2[i])

///////////////12864LCD

initi_LCD()//

hua_zuobiao()//画坐标图

y=12//从12列开始

while(1)

{ TLC2543()//2543读数据子函数

count_ad()//lcd1602的更新显示

delay1ms(1)

j++

if(j>50){j=0

wendu=ad/100//取温度的前2位

x=(wendu-1)/8

x=6-x

dp=(wendu-1)%8+1

if(y<64){ set_adr(x,y)

wdata(shuzi[dp],1,0)

}

else { set_adr(x,y-64)

wdata(shuzi[dp],0,1)

}

y++//列

if(y==128){y=12//

clear()//清屏

hua_zuobiao()//画坐标图

}

}

}

}

////////////

/*i=0

initi_LCD()

hua_zuobiao()//画坐标

set_adr(3,12)

y=3c=13

while(1)

{i++

c++

if(i==8){i=0

y=y-1

if(y==0)y=7

temp=0xb8+y

wcode(temp,1,1)

}

if(c==64) set_adr(temp,0)

if(c>=127)while(1)

if(c>=64) wdata(shuzhi[i],0,1)

else wdata(shuzhi[i],1,0)

delay1ms(100)

}

}*/

/////////////

// }

//}

////1602的显示

void count_ad(void)

{uchar i

uint temp

temp=ad

tab1[13]=number[temp%10]temp=temp/10

tab1[12]=number[temp%10]temp=temp/10

tab1[10]=number[temp%10]temp=temp/10

tab1[9]= number[temp%10]

gotoxy(1,0)

for(i=0i<16i++)write_LCD_data(tab1[i])

}

//////////////////////////////////

void TLC2543(void)//2543读数据子函数

{uchar i//输入数据为0x00//0x10为第一通道

ad=0

clk=0

cs=0

for(i=0i<12i++)

{if(adtaout==1)ad=ad|0x01//读出数据

adtain=0//写入数据

clk=1

clk=0

ad<<=1//左移一位

}

cs=1

ad>>=1//数据存在ad里

ad=(ad*1000)/819//temp=(ad*5000)/4095

}

//////////////////基碧/////////

void hua_zuobiao(void)//画坐标

{uchar j

uint i

for(j=0j<8j++)//页码

{set_adr(j,0)

for(i=1i<=64i++){wdata(zuobiao[i+j*128],1,0)

wdata(zuobiao[63+i+j*128],0,1)

}

}

}

////////////////////////

void delay1ms(uint k)//延时间

{k=k*125

while(--k)

}

////////////

调用子程序

#include<reg51.h>

#define _LCD12864_h

#define uchar unsigned char

#define uint unsigned int

void delay(uint k)//延时

void wcode(uchar com,uchar cs1,uchar cs2)//写指令

void wdata(uchar da,uchar cs1,uchar cs2)//写数据

void set_startline(uchar i)//起始行

void set_adr(uchar x,uchar y)//页值设置,起始列值函数

void clear(void)///clear清屏

void initi_LCD(void)//初始化LCD

//////////单片机与液晶显示的引脚连接/////////

//sbit RST=P2^2

sbit CS2=P2^0

sbit CS1=P2^1

sbit RS=P2^2//或DI

sbit RW=P2^3

sbit E=P2^4

//P0口为数据口

//////////////////////////////

void initi_LCD(void)//初始化LCD

{ wcode(0x3f,1,1)//显示开//0x3e关

set_startline(0)//起始行第0行

clear()//清屏

}

///////////////////////

void delay (uint k)//延时

{

while(k--)

}

////////复位///////////

/*void reset()

{

RST=0

delay(200)

RST=1

delay(200)

}

*/

////////write code写指令///////

void wcode(uchar com,uchar cs1,uchar cs2)//写指令

{

CS1=cs1

CS2=cs2

RW=0

RS=0

P0=com

E=0

delay(10)

E=1

delay(10)

E=0

}

/////////write data写数据///////////////

void wdata(uchar da,uchar cs1,uchar cs2)//写数据

{

CS1=cs1

CS2=cs2

RW=0

RS=1

P0=da

E=0

delay(10)

E=1

delay(10)

E=0

}

////////////set start设置起始行/////////////

void set_startline(uchar i)//起始行。11A5A4A3A2A1A0 共有64行

{ //液晶显示器的最底层为第0行

i=0xc0+i//此算法为把最顶层做为第一层

wcode(i,1,1)

}

///////////////////////////////

void set_adr(uchar x,uchar y)//页值设置,起始列值函数

{

x=x+0xb8//行//页地址设置。10111A2A1A0 DDRAM的8行为一页,A0~A2为页码,LCD为64行8页

y=y+0x40//列地址设置。01A5A4A3A2A1A0 两半屏分别有64列,A0~A5送入列地址计数器,

//作为列(Y)地址指针。每读写一次其自动加一,指向下一列DDRAM单元

wcode(x,1,1)

wcode(y,1,1)

}

///////////clear清屏///////////////

void clear(void)///clear清屏

{

uchar i,loop

for(i=0i<8i++)///循环页写0/////////

{

set_adr(i,0)//页码//行

for(loop=0loop<64loop++)wdata(0x00,1,1)//列//左右屏幕同时写//

}

}

调用子程序

#include<reg51.h>

#define _zimo_h

#define uchar unsigned char

#define uint unsigned int/////////////////////////////////////////////////////////////////////////

// 汉字字模表 //

// 汉字库: 宋体16.dot 纵向取模下高位,数据排列:从左到右从上到下 //

//字节倒置

uchar code zuobiao[]={

/*-- 调入了一幅图像:C:\Documents and Settings\Administrator\桌面\温度坐标.bmp --*/

/*-- 宽度x高度=128x64 --*/

0x00,0x00,0x00,0x70,0x50,0xD0,0x00,0xF0,0x10,0xF0,0x00,0xFF,0x40,0x00,0x00,0x00,

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

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

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

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

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

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

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

0x00,0x00,0x00,0xC1,0x01,0xC1,0x00,0xC1,0x41,0xC1,0x00,0xFF,0x00,0x00,0x00,0x00,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0x00,0x00,0x00,0x15,0x15,0x1F,0x00,0x1F,0x11,0x1F,0x00,0xFF,0x04,0x00,0x00,0x00,

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

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

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

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

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

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

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

0x00,0x00,0x00,0x74,0x54,0x5C,0x00,0x7C,0x44,0x7C,0x00,0xFF,0x10,0x00,0x00,0x00,

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

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

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

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

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

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

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

0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0xF0,0x10,0xF0,0x00,0xFF,0x40,0x00,0x00,0x00,

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

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

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

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

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

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

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

0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0xFF,0x00,0x00,0x00,0x00,

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

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

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

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

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

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

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

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0x7C,0x00,0x01,0x01,0x01,0x01,0x01,

0x01,0x01,0x01,0x01,0x01,0x7D,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x75,0x55,

0x5D,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x55,0x55,0x7D,0x01,0x01,0x01,0x01,0x01,

0x01,0x01,0x1D,0x11,0x7D,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x5D,0x55,0x75,0x01,

0x01,0x01,0x01,0x01,0x01,0x01,0x7D,0x55,0x75,0x01,0x01,0x01,0x01,0x01,0x01,0x01,

0x05,0x05,0x7D,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x7D,0x55,0x7D,0x01,0x01,0x01,

0x01,0x01,0x01,0x01,0x1D,0x15,0x7D,0x01,0x01,0x01,0x01,0x01,0x01,0x7D,0x01,0x7D,

0x45,0x7D,0x01,0x01,0x01,0x01,0x01,0x01,0x7D,0x01,0x01,0x7D,0x01,0x01,0x01,0x01,

}

调用子程序

#include <reg51.h>

#define _lcd1602_h

#define uint unsigned int

#define uchar unsigned char

void delayus(uint k)//延时

void write_LCD_command(uchar command)//命令写入LCD

void write_LCD_data(uchar LCDdata)//数据写入LCD

void init_1602(void)//初始化LCD

void clear_LCD()//LCD清屏

void gotoxy(uchar x,uchar y)//光标在x行y列

sbit rs=P2^5//指令寄存器的选择

sbit rw=P2^6//数据写入/读出lcd

sbit en=P2^7//始能端

//////////////////////////////////////////////////.......1

void write_LCD_command(uchar command)//命令写入LCD

{

rw=0//写入LCM

rs=0//指令寄存器

en=1//始能端

P3=command//写命令

delayus(20)//延时40*20us

en=0//关闭始能端

rw=1//读取LCM

}

void write_LCD_data(uchar LCDdata)//数据写入LCD//.......2

{

rw=0

rs=1

en=1

P3=LCDdata

delayus(1)//40us

en=0

rw=1

}

void init_1602(void)//初始化LCD/////...................3

{

write_LCD_command(0x38)// 0x38 单行显示//8位传输

write_LCD_command(0x0c)// 0x0C 屏幕开启//光标不出现//不闪烁

//write_LCD_command(0x0e)// 0x0C 屏幕开启//光标出现//不闪烁

//write_LCD_command(0x0f)// 0x0C 屏幕开启//光标出现 //闪烁

//write_LCD_command(0x0d)// 0x0C 屏幕开启//光标不出现 //闪烁

}

void clear_LCD()//LCD清屏...........................4

{

write_LCD_command(0x01)//0x01 LCD清屏

write_LCD_command(0x02)//0x02 光标回到左上角

}

void gotoxy(uchar x,uchar y)//光标在x行y列...............7

{

if(x==1)

write_LCD_command(128+y)//128=0b1000,0000

else

write_LCD_command(192+y)//192=0b1100,0000

}

void delayus(uint k)//延时..................................8

{

k=10*k//40us

while(k--)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12241187.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存