本帖最后由 daemondong 于 2022-7-4 09:57 编辑
直接上代码,希望你能看明白。
- void main(void) {
- char stat[4],step;
- stat[0]=0; //初始状态为全零
- step=0;
- while (1) {
- if (step>=2) {
- if (stat[1]==0x01 && stat[2]==0x11) {} //正转
- else if (stat[1]==0x10 && stat[2]==0x11) {} //反转
- else {} //霍尔器件安装错误
- step=0;
- }
- }
- }
- void exint0() interrupt 0 {
- _nop_();
- step++;
复制代码 |