使用spi接口完成按钮的控制,使用显示屏ili9341完成数独表盘的显示和相关数字的绑定和填空,利用中断等函数的意义来实现数独棋盘,以下是实现部分
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
//1//
if(GPIO_Pin == GPIO_PIN_0)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_0))
{
Show_Str((u16)startx,(u16)starty,BLACK,0XFFFF,(u8 *)"1",16,1);
tiankong[flag][l] = 1;
l=l+1;
}
}
/***2**/
if(GPIO_Pin == GPIO_PIN_4)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_4))
{
Show_Str((u16)startx,(u16)starty,BLACK,0XFFFF,(u8 *)"2",16,1);
tiankong[flag][l] = 2;
l=l+1;
}
}
/***3***/
if(GPIO_Pin == GPIO_PIN_5)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_5))
{
Show_Str((u16)startx,(u16)starty,BLACK,0XFFFF,(u8 *)"3",16,1);
tiankong[flag][l] = 3;
l=l+1;
}
}
/***4***/
if(GPIO_Pin == GPIO_PIN_9)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_9))
{
Show_Str((u16)startx,(u16)starty,BLACK,0XFFFF,(u8 *)"4",16,1);
tiankong[flag][l] = 4;
l++;
}
}
/***DOWN下/up***/
if(GPIO_Pin == GPIO_PIN_6)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_6))
{
cleartable();
starty = starty + k;
if (starty >= (255-32))
{
starty = 111;
}
gui_circle(startx, starty, BLACK, 12, 0);
}
}
/***RIGHT右/left***/
if(GPIO_Pin == GPIO_PIN_8)
{
if(0 == HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_8))
{
cleartable();
startx = startx + k;
if (startx >= (255-64))
{
startx = 63;
}
gui_circle(startx, starty, BLACK, 12, 0);
}
}
if(l == 3)
{
judge1();
}
}
void cleartable()//画圆图像(光标用)
{
gui_circle(startx, starty, WHITE, 12, 0);
if (f[(startx - 16) / 32 - 2][(starty - 16) / 32 - 5] == 1)
{
gui_circle(startx, starty, BLACK, 5, 1);
}
else if (f[(startx - 16) / 32 - 2][(starty - 16) / 32 - 5] == 2)
{
gui_circle(startx, starty, BLACK, 5, 0);
}
}
void judge1()//判定函数
{
if (tiankong[flag][2] == answer[flag][2])
{
flag++;
Show_Str((u16)85,(u16)250,BLACK,0XFFFF,(u8 *)"good damn man!!!!!",16,1);
Show_Str((u16)85,(u16)270,BLACK,0XFFFF,(u8 *)"you are a genius!!",16,1);
l =0;
LCD_Clear(WHITE);
startx = 63;
starty = 112;
showtable();
}
else
{
Show_Str((u16)85,(u16)250,BLACK,0XFFFF,(u8 *)"you are wrong",16,1);
Show_Str((u16)85,(u16)270,BLACK,0XFFFF,(u8 *)"stupid man ",16,1);
Show_Str((u16)85,(u16)290,BLACK,0XFFFF,(u8 *)"M3!!!!!!!!",16,1);
l = 0;
LCD_Clear(WHITE);
startx = 63;
starty = 112;
showtable();
}
}
void showtable()//画初始表格和棋盘
{
int i = 0, j = 0;
for (i = 0; i < 20; i++)
{
for (j = 0; j < 20; j++)
{
f[i][j] = 0;
}
}
for(int m=0;m<10;m++)//棋盘清屏倒计时绘画
{
LCD_DrawLine(m,0,m,500);
}
LCD_DrawLine(47, 95, 47, 225);//棋盘绘画
LCD_DrawLine(47, 95, 177, 95);
LCD_DrawLine(177, 95, 177, 225);
LCD_DrawLine(47, 225, 177, 225);
for (i = 96; i < 240; i += 32)
{
LCD_DrawLine(48, i, 176, i);
}
for (i = 48; i < 192; i += 32)
{
LCD_DrawLine(i, 96, i, 224);
}
棋盘可以自行设置