上面的程序采用AD574来采集八路温度通过四位数码管来显示程序怎么写
时间: 2023-08-10 21:09:44 浏览: 42
以下是一个简单的示例程序,使用AD574采集八路温度并通过四位数码管来显示:
```C
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS = P1^0; //定义片选信号接口
sbit WR = P1^1; //定义写信号接口
sbit RD = P1^2; //定义读信号接口
sbit BUSY = P2^7; //定义忙状态接口
void delay(uint t); //延时函数
void write_AD574(uchar channel); //写AD574函数
void write_display(uchar channel, uchar value); //写数码管函数
uchar code table[] = { //数码管显示表
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
void main()
{
uchar i, temp;
while(1)
{
for(i=0; i<8; i++) //循环采集八路温度
{
write_AD574(i); //写AD574采集对应通道温度
while(BUSY); //等待AD574采集完成
temp = P0; //读取AD574采集结果
write_display(i, table[temp/16]); //显示温度的十位
write_display(i+8, table[temp%16]); //显示温度的个位
}
}
}
void delay(uint t)
{
uint i, j;
for(i=0; i<t; i++)
for(j=0; j<125; j++);
}
void write_AD574(uchar channel)
{
CS = 0; //片选AD574
P0 = channel; //写入采集通道
WR = 0; //写信号有效
_nop_(); //等待一段时间
_nop_();
WR = 1; //写信号无效
CS = 1; //取消片选AD574
}
void write_display(uchar channel, uchar value)
{
switch(channel)
{
case 0: case 8: //数码管1
P3 &= 0x0f;
P3 |= 0x10;
P0 = value;
break;
case 1: case 9: //数码管2
P3 &= 0x0f;
P3 |= 0x20;
P0 = value;
break;
case 2: case 10: //数码管3
P3 &= 0x0f;
P3 |= 0x40;
P0 = value;
break;
case 3: case 11: //数码管4
P3 &= 0x0f;
P3 |= 0x80;
P0 = value;
break;
case 4: case 12: //数码管5
P3 &= 0xf0;
P3 |= 0x01;
P0 = value;
break;
case 5: case 13: //数码管6
P3 &= 0xf0;
P3 |= 0x02;
P0 = value;
break;
case 6: case 14: //数码管7
P3 &= 0xf0;
P3 |= 0x04;
P0 = value;
break;
case 7: case 15: //数码管8
P3 &= 0xf0;
P3 |= 0x08;
P0 = value;
break;
}
WR = 0; //写信号有效
_nop_(); //等待一段时间
_nop_();
WR = 1; //写信号无效
}
```
需要注意的是,此示例程序仅供参考,具体实现需要根据硬件电路和实际需求进行调整。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)