关于第十六届省赛模拟Ⅲ功能实现问题
4270查看
您好,我想请问这个第十六届省赛模拟Ⅲ这个功能如何实现 没有什么好思路 希望可以给出答案 谢谢! 以下为我的main.c主程序代码,底层驱动已经确认无误!
#include "main.h"
// Timer
unsigned long ulms = 0;
unsigned long ulPeripherals = 0;
unsigned int uiSeg_Dly = 0;
unsigned int uiADC_Dly = 0;
unsigned int uiKey_Dly = 0;
unsigned int uiLed_Dly = 0;
unsigned int uiPeripherals_Dly = 0;
// Seg
unsigned char pucSeg_Buf[12], pucSeg_Code[8], ucSeg_Pos = 0;
// ADC
float ADC_Val = 0;
float Water_Val = 0;
// Key
unsigned char Key_Val = 0, Key_Val_Old = 0;
// Peripherals
unsigned char Relay_Status = 0;
// Led
unsigned char ucLed = 0x00;
// Parm
unsigned char Water_Parm = 50;
unsigned int Time_Interval = 3;
// Mode
unsigned char Disp_Mode = 0; // 0-温度界面 1-参数界面 2-时间界面
unsigned char Status_Mode = 1; // 0-启动 1-停止
// Fun
void Seg_Proc(void);
void ADC_Proc(void);
void Key_Proc(void);
void Led_Proc(void);
void Peripherals_Proc(void);
// Main
void main(void)
{
System_Init();
Timer0Init();
EA = 1;
while(1)
{
Seg_Proc();
ADC_Proc();
Key_Proc();
Led_Proc();
Peripherals_Proc();
}
}
void Seg_Proc(void)
{
if(uiSeg_Dly <= 200)
return;
uiSeg_Dly = 0;
if(Disp_Mode == 0)
{
sprintf(pucSeg_Buf, "C %2u", (unsigned int)Water_Val);
}
else if(Disp_Mode == 1)
{
sprintf(pucSeg_Buf, "E %2u", (unsigned int)Water_Parm);
}
else
{
sprintf(pucSeg_Buf, "H %2u", Time_Interval);
}
Seg_Tran(pucSeg_Buf, pucSeg_Code);
}
void ADC_Proc(void)
{
if(uiADC_Dly <= 200)
return;
uiADC_Dly = 0;
ADC_Val = Read_ADC() / 51.0;
if(ADC_Val <= 1)
{
Water_Val = 10;
}
else if(ADC_Val >= 4)
{
Water_Val = 90;
}
else if(ADC_Val > 1 && ADC_Val < 4)
{
Water_Val = (80.0 / 3.0) * (ADC_Val - 1) + 10;
}
}
void Key_Proc(void)
{
if(uiKey_Dly <= 20)
return;
uiKey_Dly = 0;
Key_Val = Key_Read();
if(Key_Val == Key_Val_Old)
return;
switch(Key_Val)
{
case 4:
Disp_Mode = (++Disp_Mode) % 3;
break;
case 5:
Status_Mode = (++Status_Mode) % 2;
break;
// 0-温度界面 1-参数界面 2-时间界面
case 8:
if(Disp_Mode == 1)
{
if(Water_Parm == 30)
{
Water_Parm = 90;
}
else
{
Water_Parm -= 5;
}
}
else if(Disp_Mode == 2)
{
if(Time_Interval == 1)
{
Time_Interval = 10;
}
else
{
Time_Interval -= 1;
}
}
break;
case 9:
if(Disp_Mode == 1)
{
if(Water_Parm == 90)
{
Water_Parm = 30;
}
else
{
Water_Parm += 5;
}
}
else if(Disp_Mode == 2)
{
if(Time_Interval == 10)
{
Time_Interval = 1;
}
else
{
Time_Interval += 1;
}
}
break;
}
Key_Val_Old = Key_Val;
}
void Peripherals_Proc(void)
{
if(uiPeripherals_Dly <= 100)
return;
uiPeripherals_Dly = 0;
if(Status_Mode == 0)
{
if(Water_Val < Water_Parm)
{
// 如果当前时间与上次操作时间间隔小于设定时间间隔,则继电器吸合
if(ulms - ulPeripherals <= Time_Interval * 1000)
{
Relay_Status = 1;
}
// 如果当前时间与上次操作时间间隔大于设定时间间隔,则继电器断开
else
{
Relay_Status = 0;
}
}
// 如果湿度值大于等于湿度参数,继电器断开
else
{
Relay_Status = 0;
}
// 更新上次操作时间
ulPeripherals = ulms;
}
else
{
Relay_Status = 0;
}
Set_Peripherals(Relay_Status);
}
void Led_Proc(void)
{
if(uiLed_Dly <= 100)
return;
uiLed_Dly = 0;
if(Disp_Mode == 0)
ucLed |= 0x01;
else
ucLed &= ~0x01;
if(Disp_Mode == 1)
ucLed |= 0x02;
else
ucLed &= ~0x02;
if(Disp_Mode == 2)
ucLed |= 0x04;
else
ucLed &= ~0x04;
if(Status_Mode == 0)
ucLed |= 0x80;
else
ucLed &= ~0x80;
Led_Disp(ucLed);
}
void Time_0(void) interrupt 1
{
ulms++;
uiSeg_Dly++;
uiADC_Dly++;
uiKey_Dly++;
uiLed_Dly++;
uiPeripherals_Dly++;
if(ulms % 2 == 0)
{
ucSeg_Pos = (++ucSeg_Pos) % 8;
Seg_Disp(pucSeg_Code, ucSeg_Pos);
}
}
copy
#课程问答
| 关注
你的回复
请
登录
后回复