十六、C语言中的头文件与模块化设计

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6KGM5LiN5Zyw5LiK,size_20,color_FFFFFF,t_70,g_se,x_16

1、txy_smg_ca.c(注意添加ADD)

#include "absacc.h"

void SMG_Bit(unsigned pos, unsigned char dat)//数码管位置、数据
{
	XBYTE[0xe000] = 0xff;//为了效果好先熄灭,一定的消影作用
	XBYTE[0xc000] = 0x01 << pos;//MM模式
	XBYTE[0xe000] = dat;
}

void SMG_All(unsigned char dat)//操作所有数码管
{
	XBYTE[0xc000] = 0xff;//数码管所有位置
	XBYTE[0xe000] = dat;
}

void DelaySMG(unsigned int t)
{
	while(t--);
}	

2、txy_smg_ca.h

#ifndef TXY_SMG_CA_H
#define TXY_SMG_CA_H

unsigned char code SMG_duanma[18] = {
	//  0   1    2    3    4    5    6    7
		0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
	//  8   9    A10  B11  C12  D13  E14  F15
		0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
	// -16  .17
		0xbf,0x7f};  //共阳数码管

unsigned char code SMG_duanmaDot[10] = {
	// 0.   1.   2.   3.   4.   5.   6.   7.
		0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,
	// 8.   9.
    0x00,0x10};  //数码管(小数点)

void SMG_Bit(unsigned pos, unsigned char dat);//数码管位置、数据
void SMG_All(unsigned char dat);//操作所有数码管
void DelaySMG(unsigned int t);

#endif

3、DS18B20.c

#include "reg52.h"
#include "absacc.h"
#include "onewire.h"
#include "txy_smg_ca.h"

unsigned int temp = 0;//温度

void ShowSMG()//显示温度
{
//567
//百位:567 / 100 = 5.67 = 5
//十位:567 % 100 = 5.67 = 67   67 / 10 = 6.7 = 6
//个位:567 % 10 = 56.7 = 7
	
	/*显示1位小数
	SMG_Bit(7, SMG_duanma[temp%10]);
	DelaySMG(100);
	SMG_Bit(6, SMG_duanmaDot[(temp%100)/10]);
	DelaySMG(100);
	SMG_Bit(5, SMG_duanma[temp/100]);
	DelaySMG(100);
	*/
	
	SMG_Bit(7, SMG_duanma[temp%10]);//显示整数
	DelaySMG(100);
	SMG_Bit(6, SMG_duanma[temp/10]);
	DelaySMG(100);
	SMG_Bit(5, 0xff);
	DelaySMG(100);
	
	SMG_Bit(4, 0xff);//不显示值,一定的消影作用
	DelaySMG(100);
	SMG_Bit(3, 0xff); 
	DelaySMG(100);
	SMG_Bit(2, 0xff); 
	DelaySMG(100);
	SMG_Bit(1, 0xff); 
	DelaySMG(100);
	SMG_Bit(0, 0xff); 
	DelaySMG(100);
	
	//最后一个数码管特别亮?
	SMG_All(0xff);//关掉所有数码管
}

void Delay(unsigned int t)
{
	while(t--)//数码管动态显示本质:不断轮流点亮每一个数码管,不可以间断
	{
		ShowSMG();//一旦动态扫描间断,由多个数码管变成只显示一个数码管
	}				  	//因此在等待时间消化的过程中,仍然要保持数码管动态扫描,轮流显示没有间断
}

void Read_DS18B20_temp()//读温度
{
	unsigned char LSB, MSB;//定义8字节变量接收数据
	
	init_ds18b20();//复位
	Write_DS18B20(0xcc);//写入0xcc 跳过ROM指令
	Write_DS18B20(0x44);//写入0x44 开始温度转化
	
	Delay(1000);//延时,等待温度转化完成(注意延时的时候数码管不可以间断:延时里要动态扫描数码管)
	
	init_ds18b20();//复位,开始新一轮操作
	Write_DS18B20(0xcc);//写入0xcc 跳过ROM指令
	Write_DS18B20(0xbe);//写入0xbe 读取16位数据 
	
	LSB = Read_DS18B20();//读低8位数据
	MSB = Read_DS18B20();//读高8位数据
	
	init_ds18b20();//复位,停止数据读取
	
	temp = MSB;//高8位放到temp里
	temp <<= 8;//左移8位
	temp = temp | LSB;//或(加)上低8位=>将LSB、MSB整合成为一个16位数据
	
	temp >>= 4;//右移4位,移走小数(整数不需要换算)//显示整数
	
	/*显示1位小数
	if ((temp & 0xf800) == 0x0000)//正数(16位 高5位为符号位)
	{
		temp >>= 4;//右移四位,移走小数
		temp = temp * 10;//放大10倍
		temp = temp + (LSB & 0x0f) * 0.625;//温度(*0.625是换算)
	}
	*/
}

void main()
{
	XBYTE[0x8000] = 0xff;//关闭LED
	XBYTE[0xa000] = 0x00;//关闭蜂鸣器与继电器
	while(1)
	{
		Read_DS18B20_temp();
		ShowSMG();
	}
}

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6KGM5LiN5Zyw5LiK,size_19,color_FFFFFF,t_70,g_se,x_16

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行不地上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值