我这个步进电机用的键盘扫描,但是一个键按下一去就进入电机的死循环了 我该怎么改啊。。。
2019-07-15 08:11发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
//ioport unsigned port100e;/* 包含文件 */#include "def.h"#include "2410lib.h"#include "option.h"#include "2410addr.h"#include "interrupt.h"int ro=0;unsigned char ch;unsigned char h;unsigned char keyflag;unsigned char min;/* functions */void delay( int count );// 整步模式正转脉冲void Main1(void){unsigned char pluse_table[] = { 0x05, 0x09, 0x0a, 0x06,};
for(;;){ if( ro == 4 ) ro = 0; (*(volatile unsigned char*)0x28000006) = pluse_table[ro++]; delay(20); }
{//整步反
void Main2(void){ unsigned char pluse_table[] = { 0x05, 0x06, 0x0a, 0x09, };
for(;;){ if( ro == 4 ) ro = 0; (*(volatile unsigned char*)0x28000006) = pluse_table[ro++]; delay(20); }}
//半步正
void Main3(void){ unsigned char pluse_table[] = { 0x05, 0x01, 0x09, 0x08,0x0a,0x02,0x06,0x04,};
for(;;){
if( ro == 4 ) ro = 0; (*(volatile unsigned char*)0x28000006) = pluse_table[ro++]; delay(20); }}//半步反void Main4(void){unsigned char pluse_table[] = { 0x05, 0x04, 0x06, 0x02,0x0a,0x08,0x09,0x01,};
for(;;){ if( ro == 4 ) ro = 0; (*(volatile unsigned char*)0x28000006) = pluse_table[ro++]; delay(20); }
}void Main(void){ /* 配置系统时钟 */ ChangeClockDivider(1,1); // 1:2:4 ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz /* 初始化端口 */ Port_Init(); /* 初始化串口 */ Uart_Init(0,115200); Uart_Select(0); /* 打印提示信息 */ PRINTF("
---键盘测试程序---
"); PRINTF("
请将UART0与PC串口进行连接,然后启动超级终端程序(115200, 8, N, 1)
"); /* 开始回环测试 */ while(1) { ch = Key_GetKeyPoll(); h=ch-48; if(ch != 0) { PRINTF("
'%c'键按下", ch); } if(h==2) // 调用转动状态 { Main1();
} if(h==3) {Main2(); } if(h==4) { Main3(); } if(h==5) { Main4(); } } }/*****************************************************************************// Function name : delay// Description : 延时子程序// Return type : void// Argument : count,延时的数值*****************************************************************************/void delay( int count ){ int cnt; for( count = count; count>0; count--) for( cnt = 0; cnt < 100; cnt++);
一周热门 更多>