资源简介
基于51单片机的数字温度计设计,并用4位数码管显示。实测可用。采用keil编程,有hex文件,

代码片段和文件信息
#include //调用单片机头文件
#define uchar unsigned char //无符号字符型 宏定义 变量范围0~255
#define uint unsigned int //无符号整型 宏定义 变量范围0~65535
//数码管段选定义 0 1 2 3 4 5 6 7 8 9
uchar code smg_du[]={0x140x770x4c0x450x270x850x840x570x040x05
// A B C D E F 不显示
0x060xa40x9c0x640x8c0x8e0xff}; //断码
//数码管位选定义
sbit smg_we1 = P2^0; //数码管位选定义
sbit smg_we2 = P2^2;
sbit smg_we3 = P2^4;
sbit smg_we4 = P2^6;
uchar dis_smg[8] = {0x140x770x4c0x450x270x850x84};
uchar smg_i = 3; //显示数码管的个位数
sbit dq = P3^3; //18b20 IO口的定义
bit flag_wd_z_f; //正负温度
int temperature ; //
/***********************1ms延时函数*****************************/
void delay_1ms(uint q)
{
uint ij;
for(i=0;i for(j=0;j<120;j++);
}
/***********************小延时函数*****************************/
void delay_uint(uint q)
{
while(q--);
}
/***********************数码位选函数*****************************/
void smg_we_switch(uchar i)
{
switch(i)
{
case 0: smg_we1 = 0; smg_we2 = 1; smg_we3 = 1; smg_we4 = 1; break;
case 1: smg_we1 = 1; smg_we2 = 0; smg_we3 = 1; smg_we4 = 1; break;
case 2: smg_we1 = 1; smg_we2 = 1; smg_we3 = 0; smg_we4 = 1; break;
case 3: smg_we1 = 1; smg_we2 = 1; smg_we3 = 1; smg_we4 = 0; break;
}
}
/***********************数码显示函数*****************************/
void display()
{
static uchar i;
i++;
if(i >= smg_i)
i = 0;
P0 = 0xff; //消隐
smg_we_switch(i); //位选
P0 = dis_smg[i]; //段选
}
/***********************18b20初始化函数*****************************/
void init_18b20()
{
bit q;
dq = 1; //把总线拿高
delay_uint(1); //15us
dq = 0; //给复位脉冲
delay_uint(80); //750us
dq = 1; //把总线拿高 等待
delay_uint(10); //110us
q = dq; //读取18b20初始化信号
delay_uint(20); //200us
dq = 1; //把总线拿高 释放总线
}
/*************写18b20内的数据***************/
void write_18b20(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{ //写数据是低位开始
dq = 0; //把总线拿低写时间隙开始
dq = dat & 0x01; //向18b20总线写数据了
delay_uint(5); // 60us
dq = 1; //释放总线
dat >>= 1;
}
}
/*************读取18b20内的数据***************/
uchar read_18b20()
{
uchar ivalue;
for(i=0;i<8;i++)
{
dq = 0; //把总线拿低读时间隙开始
value >>= 1; //读数据是低位开始
dq = 1; //释放总线
if(dq == 1) //开始读写数据
value |= 0x80;
delay_uint(5); //60us 读一个时间隙最少要保持60us的时间
}
return value; //返回数据
}
/*************读取温度的值 读出来的是小数***************/
uint read_temp()
{
uint value;
uchar low; //在读取温度的时候如果中断的太频繁了,就应该把中断给关了,否则会影响到18b20的时序
init_18b20(); //初始化18b20
write_18b20(0xcc); //跳过64位ROM
write_18b20(0x44); //启动一次温度转换命令
delay_uint(50); //500us
init_18b20(); //初始化18b20
EA = 0;
write_18b20(0xcc); //跳过64位ROM
write_18b20(0xbe); //发出读取暂存器命令
low = read_18b20(); //读温度低字节
value = read_18b20(); //读温度高字节
EA = 1;
value <<= 8; //把温度的高位左移8位
value |= low; //把读
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5402 2014-10-14 22:27 程序\单片机数字温度计.c
文件 10233 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计
文件 5402 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.c
文件 4800 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.hex
文件 64 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.lnp
文件 11555 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.LST
文件 14944 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.M51
文件 11347 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.OBJ
文件 690 2014-10-14 22:27 程序\温度计 程序\单片机数字温度计.plg
....... 90195 2018-11-15 21:57 程序\温度计 程序\单片机数字温度计.uvgui.回首追忆
....... 5406 2018-11-15 21:57 程序\温度计 程序\单片机数字温度计.uvopt
....... 14314 2018-11-15 21:57 程序\温度计 程序\单片机数字温度计.uvproj
....... 0 2014-10-14 22:26 程序\温度计 程序\单片机数字温度计_uvproj.bak
目录 0 2018-11-15 21:57 程序\温度计 程序
目录 0 2016-01-17 23:51 程序
----------- --------- ---------- ----- ----
174352 15
- 上一篇:格斗游戏.rar
- 下一篇:weixin_42809254_10923344.xm
l
相关资源
- 电路图天天读19:局域网中红外遥控发
- 基于89C51的智能台灯
- STC8951系列单片机中方指南
- proteus仿真 AT89C51输出各种波形
- 基于AT89C51的数据采集系统设计新方法
- C51单片机汇编指令查询、学习工具集
- 基于89c51的数字钟
- 基于单片机交通灯设计
- 基于89C51计算机锁定加密键盘设计
- 基于51单片机的计算器(C51编写,有
- STM32+TMC5160代码电路图.rar
- AT89C51+ADC0808 PROTEUS仿真
- 单片机原理及接口技术C51编程张毅刚
- 基于AT89C51的十字路口交通灯设计pro
- 单片机原理及接口技术C51编程
- at89c51单片机外文翻译
- 单片机原理及接口技术C51编程高清P
- 基于C51的电子琴设计
- keilc51源代码
- 在C51中变量的空间分配几个方法
- 初学C51的一些误区
- 单片机初学者学习C51时的一些误区和
- Philips 80C51MX
- 12bit流水线ADC电路整体电路原理图-c
- 0.96OLED_C51系列_IIC应答_例程
- 0-999计数器的C51程序
- [单片机原理与应用设计C51编程+Prote
- ESP8266AP模式控制51单片机亮灯.docx
- C51代码生成器(代码快速生成工具)
- 基于AT89C51单片机信号发生器设计.pd
评论
共有 条评论