Proteus8.12 基于51单片机的家用供暖系统
????????使用STC89C51單片機(jī)進(jìn)行proteus仿真,包括ADC0832、LCD1602、DS18B20串口發(fā)送、單位按鍵等。效果如下所示。
????????其中NF表示流度,AL為流量,流量大小是根據(jù)流速與時間的乘積得來的。NT為DS18B20測的實時溫度,當(dāng)溫度小于按鍵設(shè)計的閾值ST時,電磁閥閉合,打開水泵并發(fā)出報警聲。
? ? ? ? 硬件框架如下:
? ? ? ? 程序設(shè)計流程圖如下:
????????部分代碼如下:
#include <reg52.h>
#include <stdio.h>
#include "LCD1602.h"
#include "ADC0832.h"
#include "DS18B20.h"
sbit Beep = P3^6;
sbit Motor = P3^7;
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
#define FOSC 11059200L
#define T1MS (65536-FOSC/12/1000) ? //1ms timer calculation method in 12T mode
#define BAUD 9600 //UART baudrate
bit busy;
uint16_t count = 0;
uint16_t Per = 0;//設(shè)定流量
uint16_t All_Per = 0;//總流量
uint16_t Tem = 0;//當(dāng)前溫度
uint16_t Set_Tem = 28;//設(shè)置溫度
void Init();
void Keyscan();
void main() {
?? ?uint8_t Buff[20];
?? ?Init();
?? ?LCD1602_Init();
?? ?Ds18b20Init();
?? ?while(1) {
?? ??? ?Per = Get_ADC0832(0);
?? ??? ?Tem = Ds18b20ReadTemp();
?? ??? ?Keyscan();
?? ??? ?LCD_pos(0,0);//顯示設(shè)定流量
?? ??? ?sprintf(Buff,"NF:%hdcfm ", (uint16_t)Per);
?? ??? ?LCD_Str(Buff);
?? ??? ?LCD_pos(1,0);//顯示設(shè)定溫度
?? ??? ?sprintf(Buff,"ST:%hd%cC ", (uint16_t)Set_Tem, 0xdf);
?? ??? ?LCD_Str(Buff);
?? ??? ?LCD_pos(0,10);//顯示總的流量
?? ??? ?sprintf(Buff,"AF:%hdL ?", (uint16_t)All_Per/1000);
?? ??? ?LCD_Str(Buff);
?? ??? ?LCD_pos(1,8);//顯示當(dāng)前溫度
?? ??? ?sprintf(Buff,"NT:%hd%cC ", (uint16_t)Tem/100, 0xdf);
?? ??? ?LCD_Str(Buff);
?? ??? ?
?? ??? ?if(Tem/100 > Set_Tem) {
?? ??? ??? ?Beep = 0;
?? ??? ??? ?Motor = 0;
?? ??? ?}
?? ??? ?else {
?? ??? ??? ?Beep = 1;
?? ??? ??? ?Motor = 1;
?? ??? ?}
?? ?}
}
/* Timer0 interrupt routine */
void tm0_isr() interrupt 1
{
? ? TL0 = T1MS; ? ? ? ? ? ? ? ? ? ? //reload timer0 low byte
? ? TH0 = T1MS >> 8; ? ? ? ? ? ? ? ?//reload timer0 high byte
? ? if (count-- == 0) ? ? ? ? ? ? ? //1ms * 1000 -> 1s
? ? {
? ? ? ? count = 1000; ? ? ? ? ? ? ? //reset counter
?? ??? ?All_Per += Per;
? ? }
}
/*----------------------------
UART interrupt service routine
----------------------------*/
void Uart_Isr() interrupt 4
{
? ? if (RI)
? ? {
? ? ? ? RI = 0; ? ? ? ? ? ? //Clear receive interrupt flag
? ? ? ? Set_Tem = SBUF; ? ? ? ? ?//P0 show UART data
? ? }
? ? if (TI)
? ? {
? ? ? ? TI = 0; ? ? ? ? ? ? //Clear transmit interrupt flag
? ? ? ? busy = 0; ? ? ? ? ? //Clear transmit busy flag
? ? }
}
void Init() {
?? ?
?? ?//定時器0
?? ?TMOD = 0x01; ? ? ? ? ? ? ? ? ? ?//set timer0 as mode1 (16-bit)
? ? TL0 = T1MS; ? ? ? ? ? ? ? ? ? ? //initial timer0 low byte
? ? TH0 = T1MS >> 8; ? ? ? ? ? ? ? ?//initial timer0 high byte
? ? TR0 = 1; ? ? ? ? ? ? ? ? ? ? ? ?//timer0 start running
? ? ET0 = 1; ? ? ? ? ? ? ? ? ? ? ? ?//enable timer0 interrupt
? ? EA = 1; ? ? ? ? ? ? ? ? ? ? ? ? //open global interrupt switch
?? ?
?? ?//串口
? ? SCON = 0x50; ? ? ? ? ? ?//8-bit variable UART
?? ?TMOD = 0x20; ? ? ? ? ? ?//Set Timer1 as 8-bit auto reload mode
? ? TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
? ? TR1 = 1; ? ? ? ? ? ? ? ?//Timer1 start run
? ? ES = 1; ? ? ? ? ? ? ? ? //Enable UART interrupt
? ? EA = 1; ?
}
void Keyscan() {
?? ?P1 = 0x07;
?? ?if((P1&0x07) != 0x07) {
?? ??? ?switch(P1&0x07) {
?? ??? ??? ?case 0x06:Set_Tem++;
?? ??? ??? ??? ?break;
?? ??? ??? ?case 0x05:if(Set_Tem != 0)Set_Tem--;
?? ??? ??? ??? ?break;
?? ??? ?}
?? ?}while((P1&0x07) != 0x07);
}
?文件下載鏈接:
基于51單片機(jī)的家用集中供暖系統(tǒng) - 細(xì)胞盤-付費(fèi)下載平臺 內(nèi)容支付后下載可見 文件付費(fèi)網(wǎng)盤 (xibaopan.com)https://www.xibaopan.com/i/MW71e3dbe1Vhg
文件內(nèi)資源:
總結(jié)
以上是生活随笔為你收集整理的Proteus8.12 基于51单片机的家用供暖系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 秉火OV7725驱动日志 第二天
- 下一篇: 备份Linux到ntfs硬盘,Linux