| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 121 人关注过本帖
标题:哪位大神可以帮我看看这程序有什么问题,看了好多遍找不出问题啊
只看楼主 收藏
Rk960536610
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-3-28
结帖率:0
  已结贴   问题点数:20  回复次数:1   
哪位大神可以帮我看看这程序有什么问题,看了好多遍找不出问题啊
#include "config.h"        //主函数以及按键设置部分

uint32 ulCount = 0; // 累计X滴

uint16 uiPPM = 0; // 滴/min     

uint8 ucBuzzerOn = 1; // 报警ON

uint16 uiBuzzerTimer = 1000; //2滴间隔X个定时中断(10ms)就报警

void Setting(void)

{

uint8 key = 0;

uint16 tmp1 = uiBuzzerTimer / 100; // ->10ms

if (tmp1 > 999){tmp1 = 999;}

 while (1)

{

//显示当前设定

{

uint16 tmp = tmp1;

DrawText(0, 0, "Set Buzzer Timer");

LcdWrite(0, 1,  '0' + (tmp / 100)); tmp %= 100;

LcdWrite(1, 1,  '0' + (tmp / 10)); tmp %= 10;  

LcdWrite(2, 1,  '0' + (tmp / 1));

DrawText(3, 1, "s");

}

 

//按键判断

key = GetKey(0);

while (key == 0){key = GetKey(0);}

if (key == KEY_UP)

{

if (tmp1 < 999){tmp1++;}

}

else if (key == KEY_DOWN)

{

if (tmp1 > 0){tmp1--;}

}     

else if (key == KEY_SET)

{

return;

}

else if (key == KEY_ENTER)

{

if (tmp1 > 999){tmp1 = 999;}

uiBuzzerTimer = tmp1 * 100;  

return;

}

}//end of while (1)

 

return;

}

void main(void)

{

    uint8 key = 0;

//初始化

    DelayTime1ms(100);

   

    LcdInit();

BUZZER = 1;

TimerInit(0, 10);   //10ms计时精度

InterruptInit(0, 1);  //1=下降沿方式触发

while (1)

{

key = GetKey(0);

if (key == KEY_SET)

{

LcdClear();

Setting();

LcdClear();

}

else if (key == KEY_ENTER)

{

if (ucBuzzerOn == 0){ucBuzzerOn = 1;}

else {ucBuzzerOn = 0;}

}  

//显示当前状态

{

if (ucBuzzerOn){DrawText(13, 0, " ON");}

else {DrawText(13, 0, "OFF");}

}

//显示当前滴速

{

uint16 tmp = uiPPM;

if (tmp > 9999){tmp = 9999;}

   

LcdWrite(0, 0,  '0' + (tmp / 1000)); tmp %= 1000;

LcdWrite(1, 0,  '0' + (tmp / 100)); tmp %= 100;

LcdWrite(2, 0,  '0' + (tmp / 10)); tmp %= 10;  

LcdWrite(3, 0,  '0' + (tmp / 1));

DrawText(4, 0, " P/min");

}

//显示当前累计滴数

{

uint32 tmp = ulCount;

if (tmp > 999999){tmp = 999999;}

   

LcdWrite(0, 1,  '0' + (tmp / 100000)); tmp %= 100000;

LcdWrite(1, 1,  '0' + (tmp / 10000)); tmp %= 10000;

LcdWrite(2, 1,  '0' + (tmp / 1000)); tmp %= 1000;

LcdWrite(3, 1,  '0' + (tmp / 100)); tmp %= 100;

LcdWrite(4, 1,  '0' + (tmp / 10)); tmp %= 10;  

LcdWrite(5, 1,  '0' + (tmp / 1));

DrawText(6, 1, " P");

}

}                        //结束while(1)

}

 

void INT_0(void) interrupt 0  

{

//滴数累计

    ulCount++;

 

//滴速计算

uiPPM = 6000 / GetTimerTick(0);   // P/min

 

SetTimerTick(0, 0);   //重新计时

}

 

 

//定时器部分

void InterruptInit(uint8 ucInterrupt, uint8 ucType)//初始化定时器

{   

    if (ucInterrupt == 0)

    {

     IT0 = ucType;

        EX0 = 1;

    }

    else if (ucInterrupt == 1)

    {

     IT1 = ucType;

        EX1 = 1;

    }

 

    EA = 1;

}

 

void CloseInterrupt(uint8 ucInterrupt)//关闭中断

{

    if (ucInterrupt == 0)

    {

        EX0 = 0;

    }

    else if (ucInterrupt == 1)

    {

        EX1 = 0;

    }

}

uint16 GetTimerTick(uint8 ucTimer)

{

    if (ucTimer <= 2)

    {

        uint16 tmp = uiTimerTick[ucTimer];

        

        while (tmp != uiTimerTick[ucTimer]){tmp = uiTimerTick[ucTimer];}

        

        return tmp;

    }

    else

    {

        return 0;

    }

}

void timer0(void) interrupt 1

{

//定时器重新计时

    TF0 = 0;

    TL0 = ucTimerClock[0][0];

TH0 = ucTimerClock[0][1];

 

    uiTimerTick[0]++;

 

    if (ucBuzzerOn)

{

if (uiTimerTick[0] > uiBuzzerTimer){BUZZER = 0;}   //10s不滴报警

else {BUZZER = 1;}

}

else

{

BUZZER = 1;

}

}

 

//按键部分

uint8 GetKey(uint8 type)

{

uint8 ucKeyValue = 0;

static uint8 s_ucFastKey = 0;

 

//去抖

ucKeyValue = ScanKey();

if (ucKeyValue == 0){s_ucFastKey = 0; return 0;}   //没有按键返回0

   

KeyDelay1ms(10);    //10ms去抖

   

ucKeyValue = ScanKey();

if (ucKeyValue == 0){s_ucFastKey = 0; return 0;}   //没有按键返回0

 

#if BELL_ENABLE == 1

BELL_ON();

KeyDelay1ms(10);    //响蜂鸣器

BELL_OFF();

#endif

    if (type == 0)

    {

        s_ucFastKey = ucKeyValue;

        while (s_ucFastKey != 0)

        {

            s_ucFastKey = ScanKey();

            ucKeyValue |= s_ucFastKey;

        }

        

     s_ucFastKey = 0;

     return ucKeyValue;

    }

    else

    {

     uint16 uiDelay = 0;

                //判断键值

     if (ucKeyValue != s_ucFastKey){s_ucFastKey = 0;}

   

     if (s_ucFastKey == 0) //fast == 0

     {

     uiDelay = 0;

     while (ScanKey() != 0)

     {

     ucKeyValue |= ScanKey();

   

     KeyDelay1ms(1);

     uiDelay++;

     if (uiDelay > FAST_KEY_DELAY){s_ucFastKey = ucKeyValue; return ucKeyValue;}

     }

     }

     else //fast==1

     {

     uiDelay = 0;

     while (ScanKey() != 0)

     {

     KeyDelay1ms(1);

     uiDelay++;

     if (uiDelay > FAST_KEY_RATE){return ucKeyValue;}

     }

     }

    }

        return ucKeyValue;

}

void LcdWrite(uint8 x, uint8 y, uint8 ucData)  //写LCD数据

{

    if (y > 1){return;}

    if (x > 15){return;}

    if (y == 0)

    {

        Lcd_CheckBusy();

        WriteComPort(LCD_SET_DDRAM_ADDR | x);

    }

    else

    {

        Lcd_CheckBusy();

        WriteComPort(LCD_SET_DDRAM_ADDR | 0x40+x);

    }

        Lcd_CheckBusy();

    WriteDataPort(ucData);

uiLcd_x = x+1;

uiLcd_y = y;

        return;

}

 

 

void DrawText(uint8 x, uint8 y, uint8 *pucStr)       //从(x,y)的右下方显示字符串,x点后移

{

    GotoXY(x, y);

 

    while(0 != *pucStr)

    {   

        LcdWrite(GetX(), GetY(), *pucStr);

        pucStr++;

    }

    return;

}

 

void SoftDelay(uint16 ms)  //延时

{

    while (ms != 0)

    {

        SoftDelay_1ms();

        ms--;

    }

}
2018-03-28 10:58
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:10
帖 子:173
专家分:1023
注 册:2016-5-15
  得分:20 
这儿是汇编论坛,请点击上方开发语言,找相关的论坛再提问.
2018-03-28 16:12







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.084753 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved