smart灵 发表于 2012-11-25 17:52:04

小弟又来了

我焊接了一个板子做压力测试 用的HX711AD转化芯片 程序如下 但是硬件上却显示 如图 我就很郁闷了 我焊接是有原理图的怎么弄下来 出现不了结果 求大家帮帮小弟 谢谢 ~~

#include<reg52.h>
#include<intrins.h>
#include<string.h>
#include<hx711.h>
#include<keyboard.h>
#define delayNOP();{_nop_();_nop_();_nop_();_nop_();};
//定义量程系数
#define RATIO   1574/1000   //1574/1000//2114/1623
//定义标识
volatile bit FlagTest = 0;                //定时测试标志,每0.5秒置位,测完清0
volatile bit FlagKeyPress = 0;//有键按下标志,处理完毕清0
volatile bit FlagSetPrice = 0;//价格设置状态标志,设置好为1。
uchar code tab[]=
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//0-9
uchar code tabd[]=
{0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//0-9
//管脚定义
sbit beep = P3^7;
sbit W1=P0^0;        //位1
sbit W2=P0^1;        //位2
sbit W3=P0^2;        //位3
sbit W4=P0^3;        //位4
//显示用变量
int Counter;
uchar idata str1 = "000000";
//称重用变量
ulong idata FullScale; //满量程AD值/1000
ulong AdVal;   //AD采样值
ulong weight;    //重量值,单位g
ulong idata price;   //单价,长整型值,单位为分   
ulong idata money;   //总价,长整型值,单位为分
//键盘处理变量
uchar keycode;
uchar DotPos;                                   //小数点标志及位置
uchar cont;                        //显示用变量
//函数声明
void Delay(uint z);
void Data_Init();
void Port_Init();
void Timer0_Init();
void CDisplay();
void KeyPress(uchar);          
void To_Zero();
void Display_Price();
void Display_Weight();
void Display_Money();

void Delay(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
                for(y=110;y>0;y--);
}
//重新找回零点,每次测量前调用
void To_Zero()
{
           FullScale=ReadCount()/1000;
           price=0;
}
void CDisplay()
{
    P1=0xbf;
        W1=0;
        Delay(1);
    W1=1;
       
        P1=0xbf;
        W2=0;
        Delay(1);
        W2=1;
       
        P1=0xbf;
        W3=0;
        Delay(1);
    W3=1;
       
        P1=0xbf;
        W4=0;
        Delay(1);
        W4=1;
}
//显示单价,单位为元,四位整数,两位小数
void Display_Price()
{
           uint i,j;
        uchar A1,A2,A3,A4;
           i = price/100;    //得到整数部分
           j = price - i*100;//得到小数部分
       
        A1=i%1000%100/10;
        A2=i%1000%100%10;
        A3=j/10;
        A4=j%10;

        P1=tab;
        W1=0;
        Delay(1);
    W1=1;
       
        P1=tabd;
        W2=0;
        Delay(1);
        W2=1;
       
        P1=tab;
        W3=0;
        Delay(1);
    W3=1;
       
        P1=tab;
        W4=0;
        Delay(1);
        W4=1;
}
//显示重量,单位kg,两位整数,三位小数
void Display_Weight()
{
           uint i,j;
           uchar A1,A2,A3,A4;
           if (weight>=5000)
        {
                beep = 0;
                CDisplay();
                return;
        }
        else
        {              
                beep = 1;
                //weight单位是g                                          
                   i = weight/1000;    //得到整数部分
                   j = weight - i*1000;//得到小数部分
                   A1=i%10;
                   A2=j/100;
                   A3=j%100/10;
                   A4=j%100%10;
          P1=tabd;
                W1=0;
                Delay(1);
          W1=1;
               
                P1=tab;
                W2=0;
                Delay(1);
                W2=1;
               
                P1=tab;
                W3=0;
                Delay(1);
          W3=1;
       
                P1=tab;
                W4=0;
                Delay(1);
                W4=1;
        }
}
//显示总价,单位为元,四位整数,两位小数
void Display_Money()
{
           uint i,j;
           uchar A0,A1,A2,A3,A4;
        money = weight*price/1000;//money单位为分
           i = money/100;    //得到整数部分
           j = money - i*100;//得到小数部分
           A0=i%1000/100;
           A1=i%1000%100/10;
           A2=i%1000%100%10;
           A3=j/10;
        A4=j%10;
    if(A0!=0)
        {
                CDisplay();
        }
        else
        {       
                P1=tab;
                W1=0;
                Delay(1);
          W1=1;
               
                P1=tabd;
                W2=0;
                Delay(1);
                W2=1;
               
                P1=tab;
                W3=0;
                Delay(1);
          W3=1;
               
                P1=tab;
                W4=0;
                Delay(1);
                W4=1;
           }
}
//数据初始化
void Data_Init()
{
           price = 0;
           DotPos = 0;
        cont=0;
}
//定时器0初始化
void Timer0_Init()
{
        ET0 = 1;      //允许定时器0中断
        TMOD = 1;       //定时器工作方式选择
        TL0 = 0x06;   
        TH0 = 0xf8;   //定时器赋予初值
        TR0=1;
}
//按键响应程序,参数是键值
//返回键值:
//         7          8    9      10(清0)
//         4          5    6      11(删除)
//         1          2    3      12(未定义)
//         14(未定义) 0    15(.)13(确定价格)

void KeyPress(uchar keycode)
{
        switch (keycode)
           {
              case 0:
              case 1:
              case 2:
              case 3:
              case 4:
              case 5:
              case 6:
              case 7:
              case 8:
              case 9:
          //目前在设置整数位,要注意price是整型,存储单位为分
                   if (DotPos == 0)
                {
                  //最多只能设置到百
                        if (price<1000)
                        {
                              price=price*10+keycode*100;
                        }
                }
               //目前在设置小数位
                else if (DotPos==1)//小数点后第一位
                {
                  price=price+keycode*10;
                        DotPos++;
                }
                else if(DotPos==2)
                {
                        price=price+keycode;
                        DotPos++;
                }
          break;
              case 10:   //清零键
                     To_Zero();
                       FlagSetPrice = 0;
                       DotPos = 0;
                        price=0;
                        cont=0;
                       break;
                  case 11:        //删除键,按一次删除最右一个数字
                        if(DotPos==3)
                        {
                                DotPos--;
                        }
                        if(DotPos==2)
                        {
                                price=price/10;
                                price=price*10;
                                DotPos--;
                        }
                        else if (DotPos==1)
                       {
                                price=price/100;
                                price=price*100;
                                DotPos--;
                       }
                       else if (DotPos==0)
                       {
                               
                                price=price/1000;
                                price=price*100;
                       }
                 break;
                case 12:                //

                        break;
              case 13:   //确认键
                        cont++;
                        if(cont>2)
                        {
                                cont=0;
                                price=0;
                                money=0;
                               FlagSetPrice = 0;
                               DotPos = 0;
                        }
                       break;
                case 14:                

                        break;
                  case 15:   //小数点按下
                       if (DotPos == 0)
                       {   
                                DotPos = 1;      //小数点后第一位
                       }
                     break;
                   }
}
void main()
{
        Data_Init();
           Timer0_Init();
        To_Zero();
        EA = 1;
           while(1)
           {
        }       
}
//定时器0中断
void Timer0_ISR (void) interrupt 1 using 0
{
        TL0 = 0x06;
        TH0 = 0xf8;   //定时器赋予初值
    Counter ++;
        if (Counter >= 30)
    {
               FlagTest = 1;
                   Counter = 0;
                AdVal=ReadCount();
                       weight=FullScale-AdVal/1000;
                       if (weight>0x8000) weight=0;
                       weight=10000*weight/FullScale;
                       weight=weight*RATIO;
    }
        if(cont==0)
        {
                Display_Weight();
        }
        else if(cont==1)
        {
                Display_Price();       
        }
        else if(cont==2)
        {
                Display_Money();       
        }
        keycode = Getkeyboard();
        //有效键值0-15
        if ((keycode<16)&&(FlagKeyPress==0))
        {
           FlagKeyPress = 1;
                Delay(10);
               KeyPress(keycode);
               FlagKeyPress = 0;
                Delay(200);
        }
}

ITOP 发表于 2012-11-25 17:56:26

楼主,图呢?

smart灵 发表于 2012-11-25 18:01:27

压力应该是中断的时候 测一下 显示出来 然后可以继续测 我的程序是这样写的但是 实际作出的东西却并不是这样的 不知道 哪里问题 请大家帮忙看看

smart灵 发表于 2012-11-25 18:02:06

ITOP 发表于 2012-11-25 17:56 static/image/common/back.gif
楼主,图呢?

马上就贴出来 还希望您帮忙看看

yklstudent 发表于 2012-11-25 21:56:59

真好 有错误就找论坛上的网友来查 好用 查错误利器{:lol:}

smart灵 发表于 2012-11-26 12:37:58

yklstudent 发表于 2012-11-25 21:56 static/image/common/back.gif
真好 有错误就找论坛上的网友来查 好用 查错误利器

这个 怎么 没人帮我看看呢 程序和图片都有 那里有错啊~~

lryxr2507 发表于 2012-11-26 13:36:48

赶紧趁阿莫还没注意你换标题吧,看你的积分挺少的,提醒你一下。

smart灵 发表于 2012-11-26 15:00:56

lryxr2507 发表于 2012-11-26 13:36 static/image/common/back.gif
赶紧趁阿莫还没注意你换标题吧,看你的积分挺少的,提醒你一下。

怎么 换标题啊 是不是 不能发这种帖子啊?

lryxr2507 发表于 2012-11-26 15:10:19

smart灵 发表于 2012-11-26 15:00 static/image/common/back.gif
怎么 换标题啊 是不是 不能发这种帖子啊?

参见:http://www.amobbs.com/thread-5468735-1-1.html

wenbo 发表于 2012-11-26 15:44:42

程序是你自己写的吗?此事还是要靠自己,大虾们都很忙,没人会仔细看你的程序。
页: [1]
查看完整版本: 小弟又来了