int main(void)
{
uint8_t ledState, m, receiveId, i, canMode;
/* 初始化 */
TFT_Init();
FLASH_Init();
SYSTICK_Config();
USART1_Config(9600);
LED_Config();
KEY_Config();
/* 彩屏显示初始化 */
GUI_DisplayInit();
m = 10;
canMode = 1; //要设置canMode不等于CAN_SendData[10],以便进入循环一开始就初始化
while(1)
{
/* 修改模式 */
if(canMode != CAN_SendData[10] )
{
canMode = CAN_SendData[10];
if(CAN_SendData[10])
{
CAN1_Config(CAN_Mode_Normal);
Mode = (uint8_t *)CAN_ModeNormal;
}
else
{
CAN1_Config(CAN_Mode_LoopBack);
Mode = (uint8_t *)CAN_ModeLoopBack;
}
CAN1_Config16BitFilter(CAN_SendData[9], 0x00);
}
/* 如果接收ID改变,就重新设置接收ID */
if(receiveId != CAN_SendData[9])
{
receiveId = CAN_SendData[9];
if(receiveId != 0x00)
{
CAN1_Config16BitFilter(CAN_SendData[9], 0x00);
}
}
/* 显示数据 */
GUI_DisplayData(m);
/* LED灯闪烁 */
i++;
if(i > 0x5F)
{
i = 0;
if(ledState == 0xFE)
{
ledState = 0xFF;
}
else
{
ledState = 0xFE;
}
LED_SetState(ledState);
}
/* 根据键盘,做出相应的操作 */
switch(KEY_Scan())
{
case(KEY_UP):
if(m == 10)
{
CAN_SendData[10] = ~CAN_SendData[10];
}
else
{
CAN_SendData[m]++;
}
GUI_Show12Char(175, 20, "等待发送", RED, BLACK);
break;
case(KEY_DOWN):
if(m == 10)
{
CAN_SendData[10] = ~CAN_SendData[10];
}
else
{
CAN_SendData[m]--;
}
GUI_Show12Char(175, 20, "等待发送", RED, BLACK);
break;
case(KEY_LEFT):
if(m == 10)
{
m = 0;
}
else
{
m++;
}
break;
case(KEY_RIGHT):
CAN1_SendMesg(CAN_SendData[8], 8, CAN_SendData);//发送数据
GUI_Show12Char(175, 20, "发送成功", BLUE, BLACK);
break;
default:
break;
}
}
}
|