|
---------------------------------------------------------
文件名: digitron_drv.c
描述: 数码管模块驱动c文件
作者:
=========================================================
-----------------------------------------------------------------------------------------------------------*/
#include "digitron_drv.h"
code uint8 Segment[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
code uint8 Select[] = {0xff,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
/**********************************************
功能:
输出位选字节和段码字节
输入参数:
SelectByte: 位选字节
SegmentByte: 段码字节
输出参数:
无
返回值:
**********************************************/
static void DigOutput(uint8 SelectByte, uint8 SegmentByte)
{
uint8 i;
DIG_SHCP = 0;
DIG_STCP = 0;
for(i=0; i<8; i++)
{
if(SegmentByte&0x80)
{
DIG_DATA = 1;
}
else
{
DIG_DATA = 0;
}
_nop_();
DIG_SHCP = 1;
_nop_();
DIG_SHCP = 0;
_nop_();
SegmentByte <<= 1;
}
for(i=0; i<8; i++)
{
if(SelectByte&0x80)
DIG_DATA = 1;
else
DIG_DATA = 0;
_nop_();
DIG_SHCP = 1;
_nop_();
DIG_SHCP = 0;
_nop_();
SelectByte <<= 1;
}
DIG_STCP = 1;
_nop_();
DIG_STCP = 0;
_nop_();
}
/**********************************************
功能:
在某位显示自定义段码
输入参数:
DigSelect: 数码管位选择(1——8,即最右到最左)
CustomSeg: 自定义段码值
输出参数:
无
返回值:
**********************************************/
void DigShowCustom(uint8 DigSelect, uint8 CustomSeg)
{
if(0<DigSelect<9)
{
DigOutput(Select[DigSelect],CustomSeg);
}
}
/**********************************************
功能:
在某位显示数字
输入参数:
DigSelect: 数码管位选择(1——8,即最右到最左)
Number: 数字(0——9)
Dp: 小数点(1:显示;0:不显示)
输出参数:
无
返回值:
**********************************************/
void DigShowNumber(uint8 DigSelect, uint8 Number, bit Dp)
{
if((0<DigSelect<9)&&(Number<10))
{
if(Dp)
{
DigOutput(Select[DigSelect],(Segment[Number]&~0x80));
}
else
{
DigOutput(Select[DigSelect],(Segment[Number]|0x80));
}
}
}
/**********************************************
功能:
初始化数码管,使数码管全灭
输入参数:
无
输出参数:
无
返回值:
**********************************************/
void DigInit(void)
{
DIG_DATA = 0;
DIG_SHCP = 0;
DIG_STCP = 0;
DigOutput(0x00,0xff);
}
#include "PCF8591_AD_drv.h"
/**********************************************
功能:
配置PCF8591的工作模式
输入参数:
anlog_sw: 模拟信号输出开关
input_model: 模拟输入模式设置
auto_increment: 通道自动增量设置
AD_channel:模拟转换通道设置
输出参数:
无
返回值:
配置完成后的控制字节
**********************************************/
unsigned char model_set(bit anlog_sw,unsigned char input_model,bit auto_increment,unsigned char AD_channel)
{
unsigned char Control_Key;
Control_Key = 0x00;
if(anlog_sw)
{
Control_Key |= 0x40;
}
input_model = input_model << 4;
Control_Key |= input_model;
if(auto_increment)
{
Control_Key |= 0x04;
}
Control_Key |= AD_channel;
return Control_Key;
}
---------------------------------------------------------
文件名: PCF8591_AD.c
描述: AD采集温度,光照强度变化
作者:
=========================================================
-----------------------------------------------------------------------------------------------------------*/
#include <reg52.h>
#include "digitron_drv.h"
#include "IIC_drv.h"
#include "PCF8591_AD_drv.h"
/**********************************************
功能:
数码管显示
输入参数:
Data: 数据
输出参数:
无
返回值:
**********************************************/
void Display(unsigned int Data1,unsigned int Data2)
{
DigShowNumber(8,Data1/100,0);
DigShowNumber(7,Data1%100/10,0);
DigShowNumber(6,Data1%10,0);
DigShowNumber(3,Data2/100,0);
DigShowNumber(2,Data2%100/10,0);
DigShowNumber(1,Data2%10,0);
}
/*---------------------------------------------------------------------------------------------------------*/
/**********************************************
主函数
**********************************************/
void main()
{
unsigned char model;
unsigned char hot,light;
while(1)
{
model = model_set(anlog_output_off,anlog_model_0,auto_increment_off,anlog_channel_0);
hot = ReadIIC(0x90,model);
model = model_set(anlog_output_off,anlog_model_0,auto_increment_off,anlog_channel_1);
light = ReadIIC(0x90,model);
Display(hot,light);
}
}
好东西值得拥有
|
评分
-
查看全部评分
|