|
/****
* 【外部晶振】: 11.0592mhz
* 【主控芯片】: STC89C52
* 【編譯環(huán)境】: Keil μVisio4
* 【程序功能】:
* 【使用說明】: 實(shí)時采集當(dāng)前環(huán)境溫度值,并顯示于數(shù)碼管上。
同時,當(dāng)溫度高于某一值時(此處設(shè)為40攝氏度)低于5也會響,蜂鳴器便會發(fā)出報警。
而當(dāng)?shù)陀谠撝禃r,蜂鳴器自動停止報警。以及上傳溫度到pc
**********************************************************************************/
#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 dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
uint num;
uchar A1,A2,A2t,A3;
void uart();//函數(shù)聲明
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 uart()
{
EA=1;//開總中斷
ES=1;//串口中斷允許位,ES=1允許串口中斷 ES=0禁止串口中斷,IE中斷允許寄存器
SM0=0;SM1=1;//串口工作方式1,8位uart波特率可變
REN=1;//串口允許接收
TR1=1;//啟動定時器1
TMOD |= 0X20;//定時器1工作模式2,8位自動重裝
TH1=0XFD;
TL1=0XFD;//設(shè)置波特率9600
}
void delay(uint count) //delay
{
uint i;
while(count)
{
i=200;
while(i>0)
i--;
count--;
}
}
void mx()
{
TI=1;
SBUF=0x00;;//送sbuf
while(!TI);
TI=0;
delay(10);
}
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--;
}
............完整代碼在文件中
|
|