現(xiàn)在我編寫了一些子程序,但是主程序不知用什么方式調(diào)用來實(shí)現(xiàn)我要完成的功能。附件上傳不了,只能放主程序了(沒完全編好),只想大家提一些建議,方便我編寫更改,各位幫幫忙了!
#include <reg52.h>
#include "intrins.h"
#include"1602.h"
#include"key.h"
#include"hx711.h"
#include"sc1010b.h"
#define uchar unsigned char
#define uint unsigned int
sbit rs=P0^0;
sbit clock=P1^0;
sbit DI=P1^1;
sbit DO=P1^2;
sbit cs=P1^3;
uchar l,m,n,o,p,num;
uchar code table[]="W: ";
uchar code table[]="P: ";
uchar code table[]="Z: ";
void display();//1602液晶顯示函數(shù)
void fenwei();//數(shù)據(jù)處理函數(shù)
unsigned long jiafa();//多次采樣求平均值
unsigned char ad_alarm; //報(bào)警值存儲(chǔ)單元
uint ReadCount(uchar port);//24位AD hx711采樣控制函數(shù)
void init();//1602液晶初始化函數(shù)
void write_date(uchar date);//1602液晶寫數(shù)據(jù)函數(shù)
void write_com(uchar com);//1602液晶寫指令函數(shù)
void delay(uint z);//延時(shí)函數(shù)
void delay1(uint z);//延時(shí)函數(shù)
void main()//主函數(shù)
{
init();
While(1)
{
fenwei();
display();
delay1(10);
}
}
void delay1(uint z) //延時(shí)函數(shù)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
void delay(uint z) //延時(shí)函數(shù)
{
uint x;
for(x=0;x<z;x++)
{
_nop_();
}
}
unsigned long jiafa()//采樣多次求平均值
{
uint i;
unsigned long I=0;
for(i=0;i<200;i++)
{
I+=ReadCount(0);
delay(3);
}
I=I/200;
if(I<=295)I=0;
return(I);
}
void fenwei()//數(shù)據(jù)處理函數(shù)
{
float AD;
uint ad;
ad=jiafa();
if(ad==0)
{
l=0;
m=0;
n=0;
o=0;
p=0;
}
else
{
AD=(ad-292)*0.6601*100+5; // press=((10.0/23.0)*vary)+9.3; ?? //測(cè)試時(shí)補(bǔ)償值為9.3
ad=AD/10; //ad=AD*10; //放大10倍,便于后面的計(jì)算
l=ad/10000; //取壓力值千位
m=ad%10000/1000;//取壓力值百位
n=ad%1000/100;//取壓力值十位
o=ad/100%10;//取壓力值個(gè)位
p=ad%10;//取壓力值十分位
}
}
//void data_pro(void)
//{
//unsigned int temp;
// float press;
// if(14<ad_data<243) //當(dāng)壓力值介于15kpa到115kpa之間時(shí),遵循線性變換
// {
// int vary=ad_data; //y=(115-15)/(243-13)*X+15kpa
// press=((10.0/23.0)*vary)+9.3; //測(cè)試時(shí)補(bǔ)償值為9.3
// temp=(int)(press*10); //放大10倍,便于后面的計(jì)算
// press_bai=temp/1000; //取壓力值百位
// press_shi=(temp%1000)/100; //取壓力值十位
// press_ge=((temp%1000)%100)/10; //取壓力值個(gè)位
// press_dot=((temp%1000)%100)%10; //取壓力值十分位
// }
}
void display()//1602液晶顯示函數(shù)
{
write_com(0x80+0x00);
write_date(table[0]);
write_date(table[1]);
write_date(table[l+2]);
delay(20);
write_date(table[m+2]);
delay(20);
write_date(table[n+2]);
delay(20);
write_date(table[o+2]);
delay(20);
write_date('.');
delay(20);
write_date(table[p+2]);
delay(20);}