高级会员
- 积分
- 767
- 威望
- 454
- 贡献
- 207
- 兑换币
- 174
- 注册时间
- 2016-10-29
- 在线时间
- 53 小时
- 毕业学校
- 安徽中医药大学
|
volatile int8 DisplayMode=0;
extern int16 TimeFlag300ms;
extern int16 g_ValueOfAD[3];
extern float f_error;
int main(void)
{
DisableInterrupts;
init();
EnableInterrupts;
while(1)
{
if(TimeFlag300ms>150)
{
TimeFlag300ms=0;
if(DisplayMode)
{
gpio_turn(C0);
OLED_Print_Num1(64, 1,(int)f_error);
OLED_Print_Num1(64, 3,g_ValueOfAD[0]);
OLED_Print_Num1(64, 5,g_ValueOfAD[1]);
}
}
}
}
int16 TimeFlag300ms = 0;
void PIT_CH0_IRQHandler(void)
{
TimeFlag300ms++;
PIT_FlAG_CLR(pit0);
}
void Set_Parameter(void)
{
if(key==9) //按键S6后一页
{
Page_num++;
line_num=0;
OLED_Fill(0x00);//清屏
}
if(key==1) //按键S4前一页
{
Page_num--;
line_num=0;
OLED_Fill(0x00);
}
if(Page_num>3)Page_num=0;
if(Page_num<0)Page_num=3;
if(key==8) //按键S3向上一行
line_num--;
if(key==10) //按键S9向下一行
line_num++;
if(line_num>3)line_num=0;
if(line_num<0)line_num=3;
if(Page_num==0) //第一页参数显示
{
if(line_num == 0)
{
OLED_P6x8Str(120, 1,"<"); //指示出需要调整的参数
OLED_P6x8Str(120, 3," ");
OLED_P6x8Str(120, 5," ");
OLED_P6x8Str(120, 7," ");
if(key==4) //按键S2减参数
ModelSelectionFlag-=1;
else if(key==6) //按键S8加参数
ModelSelectionFlag+=1;
if(ModelSelectionFlag>3)ModelSelectionFlag=0;
if(ModelSelectionFlag<0)ModelSelectionFlag=3;
}
if(line_num == 1)
{
OLED_P6x8Str(120, 1," ");
OLED_P6x8Str(120, 3,"<");
OLED_P6x8Str(120, 5," ");
OLED_P6x8Str(120, 7," ");
//拨码开关模式
if(key==4) //按键S2飞车模式
DisplayMode=0;
else if(key==6) //按键S8显示模式
DisplayMode=1;
}
if(line_num == 2)
{
OLED_P6x8Str(120, 1," ");
OLED_P6x8Str(120, 3," ");
OLED_P6x8Str(120, 5,"<");
OLED_P6x8Str(120, 7," ");
if(key==4)
UpRight_P-=0.1;
else if(key==6)
UpRight_P+=0.1;
}
if(line_num == 3)
{
OLED_P6x8Str(120, 1," ");
OLED_P6x8Str(120, 3," ");
OLED_P6x8Str(120, 5," ");
OLED_P6x8Str(120, 7,"<");
if(key==4)
UpRight_D-=0.01;
else if(key==6)
UpRight_D+=0.01;
}
switch(ModelSelectionFlag)
{
case 0: OLED_P6x8Str(80,1,"A_S_D"); break;
case 1: OLED_P6x8Str(80,1,"A_x_x"); break;
case 2: OLED_P6x8Str(80,1,"A_S_x"); break;
case 3: OLED_P6x8Str(80,1,"A_x_D"); break;
default:break;
}
switch(DisplayMode)
{
case 0: OLED_P6x8Str(80,3,"GO GO"); break;
case 1: OLED_P6x8Str(80,3,"DEBUG"); break;
default:break;
}
OLED_P6x8Str(0, 5,"UpRight_P:");
OLED_P6x8Str(0, 7,"UpRight_D:");
DisplayFloat(64, 5,UpRight_P);
DisplayFloat(64, 7,UpRight_D);
}
代码如上,代码内容很简单,通过按键来改变一个变量来决定是否显示数据,只要有数据刷新灯就会反转,这样就能看到程序是否能执行if语句内的代码,但是非常奇怪,代码只执行一次,就GG了~
|
|