寫了一個主函數:
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應優(yōu)先級
uart_init(9600);
Key_Init(); //矩陣鍵盤初始化
Moto_Init();//步進電機初始化
delay_init();
int beg = 1; //設置默認樓層為1
int des ;
int dir;
int ang;
while(1)
{
des = Key_Scan(); //獲取按下矩陣鍵盤的鍵值
if (des > beg){
dir = 1;
//print("電機正轉")
ang = (des - beg)*45; //電機旋轉角度
}
else if(des == beg){
//print("無需移動");
continue;
}
else{
dir = 0;
//printf("電機反轉")
ang = (beg - des)*45; //電機旋轉角度
}
beg = dir; //默認樓層為當前按鍵按下的樓層
Motor_Ctrl_Direction_Angle(dir,ang); // 啟動電機
// printf("當前樓層為:%d",beg);
}