数字温度计课程设计程序(数字温度计课程设计程序图)

程序设计 572
今天给各位分享数字温度计课程设计程序的知识,其中也会对数字温度计课程设计程序图进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、单片机课程设计,数字温度计。

今天给各位分享数字温度计课程设计程序的知识,其中也会对数字温度计课程设计程序图进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

单片机课程设计,数字温度计。

1. 实验任务

用可调电阻调节电压值作为模拟温度的输入量,当温度低于30℃时,发出长嘀报警声和光报警,当温度高于60℃时,发出短嘀报警声和光报警。测量的温度范围在0-99℃。

2. 电路原理图

(图)见插图

3. 系统板上硬件连线

a) 把“单片机系统”区域中的P1.0-P1.7与“动态数码显示”区域中的ABCDEFGH端口用8芯排线连接。

b) 把“单片机系统”区域中的P2.0-P2.7与“动态数码显示”区域中的S1S2S3S4S5S6S7S8端口用8芯排线连接。

c) 把“单片机系统”区域中的P3.0与“模数转换模块”区域中的ST端子用导线相连接。

d) 把“单片机系统”区域中的P3.1与“模数转换模块”区域中的OE端子用导线相连接。

e) 把“单片机系统”区域中的P3.2与“模数转换模块”区域中的EOC端子用导线相连接。

f) 把“单片机系统”区域中的P3.3与“模数转换模块”区域中的CLK端子用导线相连接。

g) 把“模数转换模块”区域中的A2A1A0端子用导线连接到“电源模块”区域中的GND端子上。

h) 把“模数转换模块”区域中的IN0端子用导线连接到“三路可调电压模块”区域中的VR1端子上。

i) 把“单片机系统”区域中的P0.0-P0.7用8芯排线连接到“模数转换模块”区域中的D0D1D2D3D4D5D6D7端子上。

j) 把“单片机系统”区域中的P3.6、P3.7用导线分别连接到“八路发光二极管指示模块”区域中的L1、L2上。

k) 把“单片机系统”区域中的P3.5用导线连接到“音频放大模块”区域中的SPK IN端口上。

l) 把“音频放大模块“区域中的SPK OUT插入音频喇叭。

四.C语言源程序

#include AT89X52.H

unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,

0xef,0xdf,0xbf,0x7f};

unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,

0x6d,0x7d,0x07,0x7f,0x6f,0x00};

unsigned char dispbuf[8]={10,10,10,10,10,10,0,0};

unsigned char dispcount;

unsigned char getdata;

unsigned int temp;

unsigned char i;

sbit ST=P3^0;

sbit OE=P3^1;

sbit EOC=P3^2;

sbit CLK=P3^3;

sbit LED1=P3^6;

sbit LED2=P3^7;

sbit SPK=P3^5;

bit lowflag;

bit highflag;

unsigned int cnta;

unsigned int cntb;

bit alarmflag;

void main(void)

{

ST=0;

OE=0;

TMOD=0x12;

TH0=0x216;

TL0=0x216;

TH1=(65536-500)/256;

TL1=(65536-500)%256;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

EA=1;

ST=1;

ST=0;

while(1)

{

if((lowflag==1) (highflag==0))

{

LED1=0;

LED2=1;

}

else if((highflag==1)  (lowflag==0))

{

LED1=1;

LED2=0;

}

else

{

LED1=1;

LED2=1;

}

}

}

void t0(void) interrupt 1 using 0

{

CLK=~CLK;

}

void t1(void) interrupt 3 using 0

{

TH1=(65536-500)/256;

TL1=(65536-500)%256;

if(EOC==1)

{

OE=1;

getdata=P0;

OE=0;

temp=getdata*25;

temp=temp/64;

i=6;

dispbuf[0]=10;

dispbuf[1]=10;

dispbuf[2]=10;

dispbuf[3]=10;

dispbuf[4]=10;

dispbuf[5]=10;

dispbuf[6]=0;

dispbuf[7]=0;

while(temp/10)

{

dispbuf[i]=temp%10;

temp=temp/10;

i++;

}

dispbuf[i]=temp;

if(getdata77)

{

lowflag=1;

highflag=0;

}

else if(getdata153)

{

lowflag=0;

highflag=1;

}

else

{

lowflag=0;

highflag=0;

}

ST=1;

ST=0;

}

P1=dispcode[dispbuf[dispcount]];

P2=dispbitcode[dispcount];

dispcount++;

if(dispcount==8)

{

dispcount=0;

}

if((lowflag==1)  (highflag==0))

{

cnta++;

if(cnta==800)

{

cnta=0;

alarmflag=~alarmflag;

}

if(alarmflag==1)

{

SPK=~SPK;

}

}

else if((lowflag==0)  (highflag==1))

{

cntb++;

if(cntb==400)

{

cntb=0;

alarmflag=~alarmflag;

}

if(alarmflag==1)

{

SPK=~SPK;

}

}

else

{

alarmflag=0;

cnta=0;

cntb=0;

}

}

数字温度计单片机课程设计用74LS573驱动4位数码管

在proteus中用74hc573,做数码管显示的仿真。

#includereg52.h

#includeintrins.h

#define uint unsigned int

#define uchar unsigned char

void delay(uint z);

uchar temp,aa,numdu,numwe,bai,shi,ge;

uint shu;

void init();

sbit dula=P2^6;

sbit wela=P2^7;

uchar code table[]={

0x3f , 0x06 , 0x5b , 0x4f ,

0x66 , 0x6d , 0x7d ,

0x07, 0x7f , 0x6f ,

0x77, 0x7c , 0x39 ,0x5e ,0x79 ,

0x71 ,0x00

};

void display(uchar bai,uchar shi,uchar ge);

void main()

{

shu=219;

init();

while(1)

{

display(bai,shi,ge);

}

}

void delay(uint z)

{

uint x,y;

for(x=z;x0;x--)

for(y=110;y0;y--);

}

void display(uchar bai,uchar shi,uchar ge)

{

wela=1;

P0=0xfe;

wela=0;

dula=1;

P0=table[bai];

dula=0;

delay(1);

wela=1;

P0=0xfd;

wela=0;

dula=1;

P0=table[shi];

dula=0;

delay(1);

wela=1;

P0=0xfb;

wela=0;

dula=1;

P0=table[ge];

dula=0;

delay(1);

}

void init()

{

TMOD=0x01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

EA=1;

ET0=1;

TR0=1;

}

void timer0() interrupt 1

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

aa++;

if(aa==2)

{

aa=0;

shu--;

if(shu==10)

{

TR0=0;

ET0=0;

}

bai=shu/100;

shi=shu%100/10;

ge=shu%10;

}

}

关于LCD数字显示温度计的课程设计,急,重赏

/*电子时钟源代码*/

#includegraphics.h

#includestdio.h

#includemath.h

#includedos.h

#define PI 3.1415926 /*定义常量*/

#define UP 0x4800 /*上移↑键:修改时间*/

#define DOWN 0x5000 /*下移↓键:修改时间*/

#define ESC 0x11b /*ESC键 : 退出系统*/

#define TAB 0xf09 /*TAB键 : 移动光标*/

/*函数声明*/

int keyhandle(int,int); /*键盘按键判断,并调用相关函数处理*/

int timeupchange(int); /*处理上移按键*/

int timedownchange(int); /*处理下移按键*/

int digithour(double); /*将double型的小时数转换成int型*/

int digitmin(double); /*将double型的分钟数转换成int型*/

int digitsec(double); /*将double型的秒钟数转换成int型*/

void digitclock(int,int,int ); /*在指定位置显示时钟或分钟或秒钟数*/

void drawcursor(int); /*绘制一个光标*/

void clearcursor(int);/*消除前一个光标*/

void clockhandle(); /*时钟处理*/

double h,m,s; /*全局变量:小时,分,秒*/

double x,x1,x2,y,y1,y2; /*全局变量:坐标值*/

struct time t[1];/*定义一个time结构类型的数组*/

main()

{

int driver, mode=0,i,j;

driver=DETECT; /*自动检测显示设备*/

initgraph(driver, mode, "");/*初始化图形系统*/

setlinestyle(0,0,3); /*设置当前画线宽度和类型:设置三点宽实线*/

setbkcolor(0);/*用调色板设置当前背景颜色*/

setcolor(9); /*设置当前画线颜色*/

line(82,430,558,430);

line(70,62,70,418);

line(82,50,558,50);

line(570,62,570,418);

line(70,62,570,62);

line(76,56,297,56);

line(340,56,564,56); /*画主体框架的边直线*/

/*arc(int x, int y, int stangle, int endangle, int radius)*/

arc(82,62,90,180,12);

arc(558,62,0,90,12);

setlinestyle(0,0,3);

arc(82,418,180,279,12);

setlinestyle(0,0,3);

arc(558,418,270,360,12); /*画主体框架的边角弧线*/

setcolor(15);

outtextxy(300,53,"CLOCK"); /*显示标题*/

setcolor(7);

rectangle(342,72,560,360); /*画一个矩形,作为时钟的框架*/

setwritemode(0); /*规定画线的方式。mode=0, 则表示画线时将所画位置的原来信息覆盖*/

setcolor(15);

outtextxy(433,75,"CLOCK");/*时钟的标题*/

setcolor(7);

line(392,310,510,310);

line(392,330,510,330);

arc(392,320,90,270,10);

arc(510,320,270,90,10); /*绘制电子动画时钟下的数字时钟的边框架*/

/*绘制数字时钟的时分秒的分隔符*/

setcolor(5);

for(i=431;i=470;i+=39)

for(j=317;j=324;j+=7){

setlinestyle(0,0,3);

circle(i,j,1); /*以(i, y)为圆心,1为半径画圆*/

}

setcolor(15);

line(424,315,424,325); /*在运行电子时钟前先画一个光标*/

/*绘制表示小时的圆点*/

for(i=0,m=0,h=0;i=11;i++,h++){

x=100*sin((h*60+m)/360*PI)+451;

y=200-100*cos((h*60+m)/360*PI);

setlinestyle(0,0,3);

circle(x,y,1);

}

/*绘制表示分钟或秒钟的圆点*/

for(i=0,m=0;i=59;m++,i++){

x=100*sin(m/30*PI)+451;

y=200-100*cos(m/30*PI);

setlinestyle(0,0,1);

circle(x,y,1);

}

/*在电子表的左边打印帮助提示信息*/

setcolor(4);

outtextxy(184,125,"HELP");

setcolor(15);

outtextxy(182,125,"HELP");

setcolor(5);

outtextxy(140,185,"TAB : Cursor move");

outtextxy(140,225,"UP : Time ++");

outtextxy(140,265,"DOWN: Time --");

outtextxy(140,305,"ESC : Quit system!");

outtextxy(140,345,"Version : 2.0");

setcolor(12);

outtextxy(150,400,"Nothing is more important than time!");

clockhandle();/*开始调用时钟处理程序*/

closegraph(); /*关闭图形系统*/

return 0; /*表示程序正常结束,向操作系统返回一个0值*/

}

void clockhandle()

{

int k=0,count;

setcolor(15);

gettime(t);/*取得系统时间,保存在time结构类型的数组变量中*/

h=t[0].ti_hour;

m=t[0].ti_min;

x=50*sin((h*60+m)/360*PI)+451; /*时针的x坐标值*/

y=200-50*cos((h*60+m)/360*PI); /*时针的y坐标值*/

line(451,200,x,y);/*在电子表中绘制时针*/

x1=80*sin(m/30*PI)+451; /*分针的x坐标值*/

y1=200-80*cos(m/30*PI); /*分针的y坐标值*/

line(451,200,x1,y1); /*在电子表中绘制分针*/

digitclock(408,318,digithour(h)); /*在数字时钟中,显示当前的小时值*/

digitclock(446,318,digitmin(m)); /*在数字时钟中,显示当前的分钟值*/

setwritemode(1);

/*规定画线的方式,如果mode=1,则表示画线时用现在特性的线

与所画之处原有的线进行异或(XOR)操作,实际上画出的线是原有线与现在规定

的线进行异或后的结果。因此, 当线的特性不变, 进行两次画线操作相当于没有

画线,即在当前位置处清除了原来的画线*/

for(count=2;k!=ESC;){ /*开始循环,直至用户按下ESC键结束循环*/

setcolor(12);/*淡红色*/

sound(500);/*以指定频率打开PC扬声器,这里频率为500Hz*/

delay(700);/*发一个频率为500Hz的音调,维持700毫秒*/

sound(200);/*以指定频率打开PC扬声器,这里频率为200Hz*/

delay(300);

/*以上两种不同频率的音调,可仿真钟表转动时的嘀哒声*/

nosound(); /*关闭PC扬声器*/

s=t[0].ti_sec;

m=t[0].ti_min;

h=t[0].ti_hour;

x2=98*sin(s/30*PI)+451; /*秒针的x坐标值*/

y2=200-98*cos(s/30*PI); /*秒针的y坐标值*/

line(451,200,x2,y2);

/*绘制秒针*/

/*利用此循环,延时一秒*/

while(t[0].ti_sec==st[0].ti_min==mt[0].ti_hour==h)

{ gettime(t);/*取得系统时间*/

if(bioskey(1)!=0){

k=bioskey(0);

count=keyhandle(k,count);

if(count==5) count=1;

}

}

setcolor(15);

digitclock(485,318,digitsec(s)+1);/*数字时钟增加1秒*/

setcolor(12); /*淡红色*/

x2=98*sin(s/30*PI)+451;

y2=200-98*cos(s/30*PI);

line(451,200,x2,y2);

/*用原来的颜色在原来位置处再绘制秒针,以达到清除当前秒针的目的*/

/*分钟处理*/

if(t[0].ti_min!=m){ /*若分钟有变化*/

/*消除当前分针*/

setcolor(15); /*白色*/

x1=80*sin(m/30*PI)+451;

y1=200-80*cos(m/30*PI);

line(451,200,x1,y1);

/*绘制新的分针*/

m=t[0].ti_min;

digitclock(446,318,digitmin(m)); /*在数字时钟中显示新的分钟值*/

x1=80*sin(m/30*PI)+451;

y1=200-80*cos(m/30*PI);

line(451,200,x1,y1);

}

/*小时处理*/

if((t[0].ti_hour*60+t[0].ti_min)!=(h*60+m)){ /*若小时数有变化*/

/*消除当前时针*/

setcolor(15); /*白色*/

x=50*sin((h*60+m)/360*PI)+451;/*50:时钟的长度(单位:像素),451:圆心的x坐标值*/

y=200-50*cos((h*60+m)/360*PI);

line(451,200,x,y);

/*绘制新的时针*/

h=t[0].ti_hour;

digitclock(408,318,digithour(h));

x=50*sin((h*60+m)/360*PI)+451;

y=200-50*cos((h*60+m)/360*PI);

line(451,200,x,y);

}

}

}

int keyhandle(int key,int count) /*键盘控制 */

{ switch(key)

{case UP: timeupchange(count-1); /*因为count的初始值为2,所以此处减1*/br break;br case DOWN:timedownchange(count-1); /*因为count的初始值为2,所以此处减1*/br break;br case TAB:setcolor(15);br clearcursor(count); /*清除原来的光标*/br drawcursor(count); /*显示一个新的光标*/br count++;br break;br }

return count;

}

int timeupchange(int count) /*处理光标上移的按键*/

{

if(count==1){

t[0].ti_hour++;

if(t[0].ti_hour==24) t[0].ti_hour=0;

settime(t); /*设置新的系统时间*/

}

if(count==2){

t[0].ti_min++;

if(t[0].ti_min==60) t[0].ti_min=0;

settime(t); /*设置新的系统时间*/

}

if(count==3){

t[0].ti_sec++;

if(t[0].ti_sec==60) t[0].ti_sec=0;

settime(t); /*设置新的系统时间*/

}

}

int timedownchange(int count) /*处理光标下移的按键*/

{

if(count==1) {

t[0].ti_hour--;

if(t[0].ti_hour==0) t[0].ti_hour=23;

settime(t);/*设置新的系统时间*/

}

if(count==2) {

t[0].ti_min--;

if(t[0].ti_min==0) t[0].ti_min=59;

settime(t);/*设置新的系统时间*/

}

if(count==3) {

t[0].ti_sec--;

if(t[0].ti_sec==0) t[0].ti_sec=59;

settime(t);/*设置新的系统时间*/

}

}

int digithour(double h)/*将double型的小时数转换成int型*/

{int i;brfor(i=0;i=23;i++)br {if(h==i) return i;}

}

int digitmin(double m)/*将double型的分钟数转换成int型*/

{int i;brfor(i=0;i=59;i++)br {if(m==i) return i;}

}

int digitsec(double s) /*将double型的秒钟数转换成int型*/

{int i;brfor(i=0;i=59;i++)br {if(s==i) return i;}

}

void digitclock(int x,int y,int clock)/*在指定位置显示数字时钟:时\分\秒*/

{char buffer1[10];brsetfillstyle(0,2);brbar(x,y,x+15,328);brif(clock==60) clock=0;brsprintf(buffer1,"%d",clock);brouttextxy(x,y,buffer1);br}

void drawcursor(int count) /*根据count的值,画一个光标*/

{switch(count)br{br case 1:line(424,315,424,325);break;br case 2:line(465,315,465,325);break;br case 3:line(505,315,505,325);break;br }

}

void clearcursor(int count) /*根据count的值,清除前一个光标*/

{switch(count)br{br case 2:line(424,315,424,325);break;br case 3:line(465,315,465,325);break;br case 1:line(505,315,505,325);break;br }

}

课程设计:基于单片机的数字温度计的设计

说实话,自己做吧,不难的,理工科的嘛,不多动手出来不好混的。

题目也有点问题,既然是数字温度计,为什么还要用AD?

采用8031芯片用与中断程序

通过8155芯片用于8位LED动态显示电路

这两个很少用吧,我记得就在微机原理的试验箱上见过...

你可以搜索DS18B20,大家在学校最常用的数字温度计,51的程序也一大堆,搜索下就有了。

数字温度计课程设计

用18B20吧 发给你了只是测温的,要是设置的话再加一点就可以了,搞不定了给我发邮件

单片机课程设计 数字温度计

#includereg51.h

#define uchar unsigned char

#define uint unsigned int

sbit DQ=P2^5;//ds18b20与单片机连接口

sbit RS= P3^5;

sbit RW = P3^6;

sbit EN = P3^7;

uchar code str1[]={"temp"};

uchar code str2[]={".C "};

uchar data disdata[5];

uint tvalue;//温度值

uchar tflag;//温度正负标志

/*************************lcd1602程序**************************/

void delay1ms(unsigned int ms)//延时1毫秒(不够精确的)

{

unsigned int i,j;

for(i=0;ims;i++)

for(j=0;j100;j++);

}

void wr_com(unsigned char com)//写指令//

{

delay1ms(1);

RS=0;

RW=0;

EN=0;

P1=com;

delay1ms(1);

EN=1;

delay1ms(1);

EN=0;

}

void wr_dat(unsigned char dat)//写数据//

{

delay1ms(1);;

RS=1;

RW=0;

EN=0;

P1=dat;

delay1ms(1);

EN=1;

delay1ms(1);

EN=0;

}

void lcd_init()//初始化设置//

{

delay1ms(15);

wr_com(0x38);delay1ms(5);

wr_com(0x08);delay1ms(5);

wr_com(0x01);delay1ms(5);

wr_com(0x06);delay1ms(5);

wr_com(0x0c);delay1ms(5);

}

void display(unsigned char *p)//显示//

{

while(*p!='\0')

{

wr_dat(*p);

p++;

delay1ms(1);

}

}

init_play()//初始化显示

{

lcd_init();

wr_com(0x80);

display(str1);

wr_com(0xc6);

display(str2);

}

/******************************ds1820程序***************************************/

void delay_18B20(unsigned int i)//延时1微秒

{

while(i--);

}

void ds1820rst()/*ds1820复位*/

{

unsigned char x=0;

DQ = 1; //DQ复位

delay_18B20(4); //延时

DQ = 0; //DQ拉低

delay_18B20(100); //精确延时大于480us

DQ = 1; //拉高

delay_18B20(40);

}

uchar ds1820rd()/*读数据*/

{

unsigned char i=0;

unsigned char dat = 0;

for (i=8;i0;i--)

{

DQ = 0; //给脉冲信号

dat=1;

DQ = 1; //给脉冲信号

if(DQ)

dat|=0x80;

delay_18B20(10);

}

return(dat);

}

void ds1820wr(uchar wdata)/*写数据*/

{

unsigned char i=0;

for (i=8; i0; i--)

{

DQ = 0;

DQ = wdata0x01;

delay_18B20(10);

DQ = 1;

wdata=1;

}

}

read_temp()//*读取温度值并转换*/

{

uchar a,b;

ds1820rst();

ds1820wr(0xcc);//*跳过读序列号*/

ds1820wr(0x44);//*启动温度转换*/

ds1820rst();

ds1820wr(0xcc);//*跳过读序列号*/

ds1820wr(0xbe);//*读取温度*/

a=ds1820rd();

b=ds1820rd();

tvalue=b;

tvalue=8;

tvalue=tvalue|a;

if(tvalue0x0fff)

tflag=0;

else

{

tvalue=~tvalue+1;

tflag=1;

}

tvalue=tvalue*(0.625);//温度值扩大10倍,精确到1位小数

return(tvalue);

}

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

void ds1820disp()//温度值显示

{

uchar flagdat;

disdata[0]=tvalue/1000+0x30;//百位数

disdata[1]=tvalue%1000/100+0x30;//十位数

disdata[2]=tvalue%100/10+0x30;//个位数

disdata[3]=tvalue%10+0x30;//小数位

if(tflag==0)

flagdat=0x20;//正温度不显示符号

else

flagdat=0x2d;//负温度显示负号:-

if(disdata[0]==0x30)

{

disdata[0]=0x20;//如果百位为0,不显示

if(disdata[1]==0x30)

{

disdata[1]=0x20;//如果百位为0,十位为0也不显示

}

}

wr_com(0xc0);

wr_dat(flagdat);//显示符号位

wr_com(0xc1);

wr_dat(disdata[0]);//显示百位

wr_com(0xc2);

wr_dat(disdata[1]);//显示十位

wr_com(0xc3);

wr_dat(disdata[2]);//显示个位

wr_com(0xc4);

wr_dat(0x2e);//显示小数点

wr_com(0xc5);

wr_dat(disdata[3]);//显示小数位

}

/********************主程序***********************************/

void main()

{

init_play();//初始化显示

while(1)

{

read_temp();//读取温度

ds1820disp();//显示

}

}

原理图很简单的

关于数字温度计课程设计程序和数字温度计课程设计程序图的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

扫码二维码