导航:首页 > 编程语言 > 51温控程序

51温控程序

发布时间:2021-03-05 13:26:56

❶ 求一个51单片机的多路温度控制系统的C语言程序

#include<reg52.h> #include<math.h>
#include<INTRINS.H>
#define uchar unsigned char
#define uint unsigned int;
/******************************************************************/
/* 定义端口 */
/******************************************************************/
sbit seg1=P2^0;
sbit seg2=P2^1;
sbit seg3=P2^2;
sbit DQ=P1^7;//ds18b20 端口
sfr dataled=0x80;//显示数据端口
/******************************************************************/
/* 全局变量 */
/******************************************************************/
uint temp;
uchar flag_get,count,num,minute,second;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//7段数码管段码表共阳
uchar str[6];
/******************************************************************/
/* 函数声明 */
/******************************************************************/
void delay1(uchar MS);
unsigned int ReadTemperature(void);
void Init_DS18B20(void);
unsigned char ReadOneChar(void);
void WriteOneChar(unsigned char dat);
void delay(unsigned int i);
/******************************************************************/
/* 主函数 */
/******************************************************************/
main()
{
unsigned char TempH,TempL;
TMOD|=0x01;//定时器设置
TH0=0xef;
TL0=0xf0;
IE=0x82;
TR0=1;
P2=0x00;
count=0;
while(1)
{
str[5]=0x39; //显示C符号
str[1]=tab[TempH/100]; //十位温度
str[2]=tab[(TempH%100)/10]; //十位温度
str[3]=tab[(TempH%100)%10]|0x80; //个位温度,带小数点
str[4]=tab[TempL];
if(flag_get==1) //定时读取当前温度
{
temp=ReadTemperature();
if(temp&0x8000)
{
str[0]=0x40;//负号标志
temp=~temp; // 取反加1
temp +=1;
}
else
str[0]=0;
TempH=temp>>4;
TempL=temp&0x0F;
TempL=TempL*6/10;//小数近似处理
flag_get=0;
}
}
}

/******************************************************************/
/* 定时器中断 */
/******************************************************************/
void tim(void) interrupt 1 using 1//中断,用于数码管扫描和温度检测间隔
{
TH0=0xef;//定时器重装值
TL0=0xf0;
num++;
if (num==50)
{num=0;
flag_get=1;//标志位有效
second++;
if(second>=60)
{second=0;
minute++;
}
}
count++;
if(count==1)
{P2=0;
dataled=str[0];}//数码管扫描
if(count==2)
{P2=1;
dataled=str[1];}
if(count==3)
{ P2=2;
dataled=str[2];
}
if(count==4)
{ P2=3;
dataled=str[3];
}
if(count==5)
{ P2=4;
dataled=str[4];
}
if(count==6)
{ P2=5;
dataled=str[5];
count=0;}
}
/******************************************************************/
/* 延时函数 */
/******************************************************************/
void delay(unsigned int i)//延时函数
{
while(i--);
}
/******************************************************************/
/* 初始化 */
/******************************************************************/
void Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1; //DQ复位
delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
delay(10);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(5);
}
/******************************************************************/
/* 读一个字节 */
/******************************************************************/
unsigned char ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
delay(5);
}
return(dat);
}
/******************************************************************/
/* 写一个字节 */
/******************************************************************/
void WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
delay(5);
DQ = 1;
dat>>=1;
}
delay(5);
}
/******************************************************************/
/* 读取温度 */
/******************************************************************/
unsigned int ReadTemperature(void)
{
unsigned char a=0;
unsigned int b=0;
unsigned int t=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
delay(200);
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar(); //低位
b=ReadOneChar(); //高位
b<<=8;
t=a+b;
return(t);
}
//LZ,这是测温并且用数码管显示程序,报警可以自己另行添加!主要程序就是这些!
()

❷ 我准备用51做一个温度控制的模拟以下是程序但是我不知道怎么接线,求大神帮助 1L是程序

ORG 000BH
AJMP PIT0
ORG 001BH
AJMP PIT1 ;中断入口及优先级

;显示子程序
DIR: MOV SCON ,#00H ;置串行口移位寄存器状态
SETB P1.4 ;开显示
JB 5DH,DL1 ;显示设定温度
DL2: MOV DPTR,#SEGT
DL0: MOV A,@R0
MOVC A,@A+DPTR
MOV SBUF ,A
LOOP1: JNB TI, LOOP1
CLR TI
INC R0
MOV A,@R0
MOVC A,@A+DPTR
ANL A, #7FH ;使数带小数点
MOV SBUF ,A
LOOP2: JNB TI,LOOP2
CLR TI
INC R0
MOV A,@R0
MOVC A,@A+DPTR
MOV SBUF,A
LOOP3: JNB TI,LOOP3
CLR TI
CLR P1.4
CLR 5DH
RET
DL1: MOV 50H,#0AH ;小数位黑屏
AJMP DL2
SEGT: DB 0C0H ,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH
;加一子程序
DAAD1: MOV A,#00H
ORL A,@R1
ADD A,#01H
CJNE A,#30H,DAAD2 ;超过48度了吗?
DAAD3: MOV @R1,A
DAA: RET
DAAD2: JC DAAD3
MOV @R1,#15EH ;超过48则转回到355
AJMP DAA
;减一子程序
DEEC1: MOV A,@R1
DEC A
CJNE A,#15EH,DEEC2 ;低于355度了吗?
DEEC3: MOV @R1,A
DEE: RET
DEEC2: JNC DEEC3
MOV @R1,#30H ;低于355则转回到48
AJMP DEE
;T0中断子程序
PIT0: CLR EA
PUSH ACC
PUSH PSW
PUSH DPL
PUSH DPH
SETB EA ;压栈后开中断响应键盘
PPP: LCALL SAWP ;采样数据
LCALL FILTER ;数字滤波
MOV A,2AH ;取采样值
CJNE A,#07H,AAA ;下限48比较
AJMP BBB
AAA: JC CCC ;小于48度转
CJNE A,#0FEH ,DDD ;上限355比较
AJMP BBB ;转至48~355正常范围处理
DDD: JC BBB
CLR P1.2 ;大于355黄灯亮
SETB 5EH
CLR P1.1 ;置标志 启动风扇
AJMP PPP
CCC: CLR P1.3 ;小于48红灯亮
SETB 5FH
BBB: CLR P1.0 ;置标志启动电炉
AJMP PPP
SETB P1.0
SETB P1.1
SETB P1.2
SETB P1.3
CLR 5EH
CLR 5FH ;50~350之间正常

JNB 20H,EEE ;设定温度小于实际值转到风扇
MOV A,29H
LCALL FFF
CLR P1.0
LOOP10: MOV R0,#56H ;存放相乘结果的首址
MOV R1,#55H ;赋显示缓冲区最高位地址
;标度转化
MOV R0,#53H ;赋显示首址
CLR DIR
JB 0D5H,LOOP10 ;等待T1中断
CLR EA
POP DPH
POP DPL
POP PSW
SETB EA
POP ACC
RETI
EEE: MOV A,28H ;风扇处理
LCALL FFF
CLR P1.1
AJMP LOOP10
FFF: CLR A ;根据PID结果计算T1初值
INC A
MOV TL1,A
MOV TH1,#0FFH
SETB PIT1
SETB TR1
SETB ET1
RET

;采样子程序
SAWP: MOV R0,#20H
MOV R1,#03H
SAW1: MOV DPTR,#7FF8H
MOVX @DPTR,A ;A/D转化
MOV R2,#20H
DLY: DJNZ R2,DLY ;延时
HERE: JB P3.3 ,HERE
MOV DPTR,#7FF8H
MOVX A,@DPTR ;读转化结果
MOV @R0,A
INC R0
DJNZ R1,SAW1
RET
;数字滤波
FILTER: MOV A, 20H
CJNE A,2DH,CMP1
AJMP CMP2
CMP1: JNC CMP2
XCH A,2DH
XCH A,2CH
CMP2: MOV A,2DH
CJNE A,22EH,CMP3
MOV 2AH,A
AJMP RRR
CMP3: JC CMP4
MOV 2AH,A
AJMP RRR
CMP4: MOV A,2EH
CJNE A,2CH,CMP5
MOV 2AH ,A
AJMP RRR
CMP5: JC CMP6
XCH A,2CH
CMP6: MOV 2AH,A
RRR: RET
;T1中断
PIT1: CLR 00H
JB 20H, GGG
SETB P1.0 ;关闭电炉
GG: CLR PT1
RETI
GGG: SETB P1.1 ;关闭风扇
CLR 20H
AJMP GG
;延时10MS子程序
DLY10MS: MOV R7,#0A0H
DL00: MOV R6,#0FFH
DL11: DJNZ R6,DL11
DJNZ R7,DL00
RET

❸ 求一个51单片机温控程序

网络一下,有很多,下一个自己稍加修改就可以了。

❹ 用51单片机编写的温控系统程序该怎么写啊

建议 去 我的领地 5d6d 的 proteus 论坛看看

那里有很多 单片机仿真实例,包括proteus 仿真图 和 源码

❺ 51单片机温度控制系统温控模块要怎么做

你好

温度控制可以用18b20,可以根据18b20的地址,实现多点温度控制

也可以通过串口将温度传到上位机电脑

❻ 51单片机做数电温控系统软件程序

公园丁当初一,808小“为。薄8:8、小入一

❼ 急求用51单片机和热敏电阻制作温度控制器的C程序及电路图

给你一个用ADC0809做AD转换的C程序作参考吧!希望对你有所帮助!

#include<reg52.h>
unsigned char code dispbitcode[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
unsigned char dispbuf[4];
unsigned int i;
unsigned int j;
unsigned char getdata;
unsigned int temp;
unsigned int temp1;
unsigned char count;
unsigned char d;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
sbit P34=P3^4;
sbit P35=P3^5;
sbit P36=P3^6;
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P17=P1^7;
void TimeInitial();
void Delay(unsigned int i);//
void TimeInitial()
{
TMOD=0x10;
TH1=(65536-200)/256;//定时时间为2us,亦即CLK周期为0.4us
TL1=(65536-200)%256;
EA=1;
ET1=1;
TR1=1;
}

void Delay(unsigned int i)//延时函数
{
unsigned int j;
for(;i>0;i--)
{
for(j=0;j<125;j++)
{;}
}
}

void Display()//

{
P1=dispbitcode[dispbuf[3]];//十位
P20=0;
P21=1;
P22=1;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[2]];//个位
P17=1;//显示小数点
P20=1;
P21=0;
P22=1;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[1]];//十分位
P20=1;
P21=1;
P22=0;
P23=1;
Delay(10);
P1=0x00;
P1=dispbitcode[dispbuf[0]];//百分位
P20=1;
P21=1;
P22=1;
P23=0;
Delay(10);
P1=0x00;
}

void main()//主函数
{
TimeInitial();
while(1)
{
ST=0;//关闭转换
OE=0;//关闭输出
ST=1;//开启转换
ST=0;//关闭转换
P34=0;//选择通道0
P35=0;
P36=0;
while(EOC==0);//判断是否转换结束:是则执行以下语句,否则等待
OE=1;//开启数据输出允许
getdata=P0;//将数据取走,存放在变量getdata中
OE=0;//关闭输出
temp=getdata*1.0/255*500;//电压值转换,5V作为参考电压,分成256份
dispbuf[0]=temp%10;//百分位
dispbuf[1]=temp/10%10;//十分位
dispbuf[2]=temp/100%10;//个位
dispbuf[3]=temp/1000;//十位
Display();
}
}

void t1(void) interrupt 3 using 0//定时器中断服务函数;作用:产生CLK信号
{
TH1=(65536-200)/256;
TL1=(65536-200)%256;
CLK=~CLK;
}

❽ lm35,89c51,温控的程序

//安装目录下的EXE文件打开后可在电脑上显示当前温度值
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DS=P2^2; //define interface
uint temp; // variable of temperature
uchar flag1; // sign of the result positive or negative
sbit la=P2^6;
sbit wela=P2^7;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};
void delay(uint count) //delay
{
uint i;
while(count)
{
i=200;
while(i>0)
i--;
count--;
}
}
///////功能:串口初始化,波特率9600,方式1///////
void Init_Com(void)
{
TMOD = 0x20;
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd;
TL1 = 0xFd;
TR1 = 1;
}
void dsreset(void) //send reset and initialization command
{
uint i;
DS=0;
i=103;
while(i>0)i--;
DS=1;
i=4;
while(i>0)i--;
}
bit tmpread()bit(void) //read() a bit
{
uint i;
bit dat;
DS=0;i++; //i++ for delay
DS=1;i++;i++;
dat=DS;
i=8;while(i>0)i--;
return (dat);
}
uchar tmpread()(void) //read a byte date
{
uchar i,j,dat;
dat=0;
for(i=1;i<=8;i++)
{
j=tmpreadbit();
dat=(j<<7)|(dat>>1); //读出的数据最低位在最前面,这样刚好一个字节在DAT里
}
return(dat);
}
void tmpwritebyte(uchar dat) //write a byte to ds18b20
{
uint i;
uchar j;
bit testb;
for(j=1;j<=8;j++)
{
testb=dat&0x01;
dat=dat>>1;
if(testb) //write 1
{
DS=0;
i++;i++;
DS=1;
i=8;while(i>0)i--;
}
else
{
DS=0; //write 0
i=8;while(i>0)i--;
DS=1;
i++;i++;
}
}
}
void tmpchange(void) //DS18B20 begin change
{
dsreset();
delay(1);
tmpwritebyte(0xcc); // address all drivers on bus
tmpwritebyte(0x44); // initiates a single temperature conversion
}
uint tmp() //get the temperature
{
float tt;
uchar a,b;
dsreset();
delay(1);
tmpwritebyte(0xcc);
tmpwritebyte(0xbe);
a=tmpread();
b=tmpread();
temp=b;
temp<<=8; //two byte compose a int variable
temp=temp|a;
tt=temp*0.0625;
temp=tt*10+0.5;
return temp;
}
void readrom() //read the serial
{
uchar sn1,sn2;
dsreset();
delay(1);
tmpwritebyte(0x33);
sn1=tmpread();
sn2=tmpread();
}
void delay10ms() //delay
{
uchar a,b;
for(a=10;a>0;a--)
for(b=60;b>0;b--);
}
void display(uint temp) //显示程序
{
uchar A1,A2,A2t,A3,ser;
ser=temp/10;
SBUF=ser;
A1=temp/100;
A2t=temp%100;
A2=A2t/10;
A3=A2t%10;
la=0;
P0=table[A1]; //显示百位
la=1;
la=0;
wela=0;
P0=0x7e;
wela=1;
wela=0;
delay(1);
la=0;
P0=table1[A2]; //显示十位
la=1;
la=0;
wela=0;
P0=0x7d;
wela=1;
wela=0;
delay(1);
P0=table[A3]; //显示个位
la=1;
la=0;
P0=0x7b;
wela=1;
wela=0;
delay(1);
}
void main()
{
uchar a;
Init_Com();
do
{
tmpchange();
// delay(200);
for(a=10;a>0;a--)
{
display(tmp());
}
}while(1);
}
将二管脚接到P2.2就可以了
你可以参考一下,纯属抄袭,绝非手打

❾ 求教:51单片机智能温控风扇程序编写

一路来定时器扫描做数码源管和按键,另外一路定时器做pwm调速。主程序循环里面去处理温度读取判断,按键处理等。只提供参考思路,这里是几乎不可能要到别人写好的程序的。
如果想要别人帮你写,要几百,某鱼和某宝上有很多,网络知道没有免费的程序员,你这个程序要花掉好几个小时,半天就花掉了,后续有bug你还要debug,你不会还得问,这种麻吃力不讨好的事情没人做的。。。
你要是来不及,花钱去某鱼和某宝代做是最好的选择。

❿ 51单片机温度控制系统的C语言程序

你好!

显示用数码管还是用液晶呢?人机对话,是和上位机通讯吗

阅读全文

与51温控程序相关的资料

热点内容
掌握秘密校园恋爱 日本电影 浏览:927
能看暴力血腥的软件 浏览:120
操嫂子逼电影 浏览:842
免费观看电影网知乎 浏览:490
带着斩魄刀穿越九叔的世界 浏览:554
英伦影院 浏览:358
欧美床戏亲吻电影 浏览:838
妈妈的职业谁演男服务员? 浏览:576
蓝色标是哪个编程软件 浏览:330
谁的电影网 浏览:595
女同电影 浏览:513
电影詹妮前夫杰克叫啥名字 浏览:419
电脑怎么有线连接网络 浏览:290
javascript字符串转布尔 浏览:336
微信电脑给自己发文件 浏览:266
3对情侣去无人岛旅游韩国电影 浏览:922
快递小哥丁冬和浩哥 浏览:625
黛妃全部作品集百度网盘 浏览:59
桃太郎电影共几部 浏览:580
求一部电影名字 女主叫露娜 浏览:449

友情链接