为什么单片机数码管动态显示人体反应时间测试仪的数码管每次测

5834人阅读
C++学习与思考(28)
如上图所示,PCF8591的9脚和10脚,一个是数据线SDA,一个是时钟线SCL。分别接到的P2.0
, P2.1上面。
为什么选这两个引脚?因为51单片机上没有IIC总线接口,需要用普通的IO模拟,所以它随便选了两个IO接上就行。
VREF是什么?基准,也是它能测量的最大电压。
如何控制?今天先不说IIC总线,只说控制流程。
看器件手册可以知道:
1、发送地址字节,选择该器件。
2、发送控制字节,选择相应通道。
3、重新发送地址字节,选择该器件。
4、接收目标通道的数据。
这次的程序流程是:AD采样,串口发送,循环执行。
具体实现看代码:
#include &reg51.h&
#define uchar unsigned char
#define uint unsigned int
sbit SCL=P2^0;
sbit SDA=P2^1;
sbit spk=P1^4;
sbit WEI=P2^7;
sbit DUAN=P2^6; //duan
unsigned char code dofly_DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};// 显示段码值0~9
unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
void delay(int z)
while(z--);
void Screen(int i,int n)
P0=dofly_WeiMa[i];
P0=dofly_DuanMa[n];
delay(250);
void Get_out_print(uchar temperatureNum)
if(temperatureNum/100&0)
Screen(3,temperatureNum/100);
temperatureNum%=100;
if(temperatureNum/10&0)
Screen(4,temperatureNum/10);
Screen(5,temperatureNum%10);
Screen(7,12); //显示c
void delay()
//延时4-5个微秒
void delay_1ms(uint z)
for(x=z;x&0;x--)
for(y=110;y&0;y--)
void start()
void stop()
void respons()
while((SDA==1)&&(i&250))
void init()
uchar read_byte()
uchar i,k;
for(i=0;i&8;i++)
k=(k&&1)|SDA;
void write_byte(uchar date)
for(i=0;i&8;i++)
temp=temp&&1;
void write_add(uchar control,uchar date)
write_byte(PCF8591);
respons();
write_byte(control);
respons();
write_byte(date);
respons();
uchar read_add(uchar control)
write_byte(PCF8591);
respons();
write_byte(control);
respons();
write_byte(PCF8591+1);
respons();
date=read_byte();
uchar temperatureNum=0;
void main()
TMOD= 0x01;
temperatureNum=read_add(0x41);
Get_out_print(151-temperatureNum);
void Timer0_isr(void) interrupt 1
if(temperatureNum&118)
}注意:温度可能不是很准确,因为我的电压---温度对应关系没有进行仔细的测量。。粗略为y=-x+151
邮箱:acm_
文章:41篇
阅读:72361
文章:32篇
阅读:131503
文章:63篇
阅读:530171
阅读:51099单片机原理 人体反应测速_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
单片机原理 人体反应测速
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
加入VIP
还剩18页未读,
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 单片机数码管显示数字 的文章

 

随机推荐