c语言编写自动校准量程程序,量程自动切换数字电压表C语言原程序.doc
发布日期:2022-02-18 17:49:53 浏览次数:39 分类:技术文章

本文共 1577 字,大约阅读时间需要 5 分钟。

量程自动切换数字电压表C语言原程序

C语言原程序如下:

#include #define uchar unsigned char;

uchar code scan_con[] 0x03,0x02,0x01,0x00 ; //定义列扫描

uchardispcode[] 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00 ;//定义0~9的显示段码

uchar dispbuf[8] 0,0,0,0,0,0,0,0 ; //定义8个存储空间

uchar dispcount 0;

uchar getdata;

unsigned int temp;//定义暂存空间

uchar i,j,k,l,m;

sbit s3 P2^7; //位定义,控制模拟开关

sbit s2 P2^6;

sbit s1 P2^5;

sbit dp P1^7; //定义小数点

#define v20_on s3 1;s2 0;s1 0; //宏定义不同量程,不同的开关状态

#define v2_on s3 0;s2 1;s1 0;

#define v02_on s3 0;s2 0;s1 1;

sbit ST P2^0; //定义单片机和ADC的控制信号

sbit OE P2^1;

sbit EOC P2^2;

main while 1 _20v: //2~20V量程

v20_on;

ST 0; //启动A/D转换

ST 1;

ST 0;

while EOC 0 ;

OE 0;

getdata P0;

OE 1;

if getdata 21 //量程不合适,切换 goto _2v; l 3;

temp getdata; //量程合适,数据处理

temp temp*100;

temp temp/51 *5;

goto disp; //跳到数码管显示程序段

_2v: //200MV~2V量程

v2_on;

ST 0;

ST 1;

ST 0;

while EOC 0 ;

OE 0;

getdata P0;

OE 1;

if getdata 21 goto _02v; else if getdata 204 goto _20v; l 2;

temp getdata;

temp temp*100/51 *10;

temp temp/2;

goto disp;

_02v: //0~200MV量程

v02_on;

ST 0;

ST 1;

ST 0;

while EOC 0 ;

OE 0;

getdata P0;

OE 1;

if getdata 204 goto _2v; l 1;

temp getdata;

temp temp*100/51 *100;

temp temp/20;

disp:

dispbuf[0] 0;

dispbuf[1] 0;

dispbuf[2] 0;

dispbuf[3] 0;

dispbuf[4] 0;

dispbuf[5] 0;

dispbuf[6] 0;

dispbuf[7] 0;

i 0;

while temp/10 //电压值的每个位计算 dispbuf[i] temp%10;

temp temp/10;

i++; dispbuf[i] temp;

for k 0;k 3;k++ //数码管显示 P1 dispcode[dispbuf[k]];

P3 scan_con[k];

if l 3 if k 2 P1 P1 | 0x80; //小数点的确定

else if l 2 if k 3 P1 P1 | 0x80; else if l 1 if k 1 P1 P1 | 0x80; for m 0;m 2;m++ //延时

for j 0;j 100;j++ ;

转载地址:https://blog.csdn.net/weixin_30942339/article/details/117076203 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C语言用strupr大小写转换函数,C语言strlwr()、strupr()与strstr()、strchr()函数
下一篇:c语言判断一个数是否为质数的n次方,C语言中 输入一个数 判断这个数是否为3的N次方 求代码...

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月16日 23时39分57秒