|
---------------------------------------------------------
文件名: digitron_drv.c
描述: 數(shù)碼管模塊驅(qū)動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};
/**********************************************
功能:
輸出位選字節(jié)和段碼字節(jié)
輸入?yún)?shù):
SelectByte: 位選字節(jié)
SegmentByte: 段碼字節(jié)
輸出參數(shù):
無
返回值:
**********************************************/
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_();
}
/**********************************************
功能:
在某位顯示自定義段碼
輸入?yún)?shù):
DigSelect: 數(shù)碼管位選擇(1——8,即最右到最左)
CustomSeg: 自定義段碼值
輸出參數(shù):
無
返回值:
**********************************************/
void DigShowCustom(uint8 DigSelect, uint8 CustomSeg)
{
if(0<DigSelect<9)
{
DigOutput(Select[DigSelect],CustomSeg);
}
}
/**********************************************
功能:
在某位顯示數(shù)字
輸入?yún)?shù):
DigSelect: 數(shù)碼管位選擇(1——8,即最右到最左)
Number: 數(shù)字(0——9)
Dp: 小數(shù)點(diǎn)(1:顯示;0:不顯示)
輸出參數(shù):
無
返回值:
**********************************************/
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));
}
}
}
/**********************************************
功能:
初始化數(shù)碼管,使數(shù)碼管全滅
輸入?yún)?shù):
無
輸出參數(shù):
無
返回值:
**********************************************/
void DigInit(void)
{
DIG_DATA = 0;
DIG_SHCP = 0;
DIG_STCP = 0;
DigOutput(0x00,0xff);
}
#include "PCF8591_AD_drv.h"
/**********************************************
功能:
配置PCF8591的工作模式
輸入?yún)?shù):
anlog_sw: 模擬信號輸出開關(guān)
input_model: 模擬輸入模式設(shè)置
auto_increment: 通道自動增量設(shè)置
AD_channel:模擬轉(zhuǎn)換通道設(shè)置
輸出參數(shù):
無
返回值:
配置完成后的控制字節(jié)
**********************************************/
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采集溫度,光照強(qiáng)度變化
作者:
=========================================================
-----------------------------------------------------------------------------------------------------------*/
#include <reg52.h>
#include "digitron_drv.h"
#include "IIC_drv.h"
#include "PCF8591_AD_drv.h"
/**********************************************
功能:
數(shù)碼管顯示
輸入?yún)?shù):
Data: 數(shù)據(jù)
輸出參數(shù):
無
返回值:
**********************************************/
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);
}
/*---------------------------------------------------------------------------------------------------------*/
/**********************************************
主函數(shù)
**********************************************/
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);
}
}
好東西值得擁有
|
-
-
PCF8591 ADC電壓采樣.pdf
2015-7-26 11:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
2.81 MB, 下載次數(shù): 54, 下載積分: 黑幣 -5
評分
-
查看全部評分
|