写的两个方法想拼在一起,主函数是独立按键的程序,里面当按键按下K1去调用另一个程序(步进电机转动的程序),为什么调用不了, 请帮忙看看, 调用motor_ccw()失败。
单片机源程序:
- #include "reg52.h"
- #include "motor.c"
- void delaynms(uint aa);
- void motor_ccw();
- void motor_cw();
- typedef unsigned int u16;
- typedef unsigned char u8;
- sbit led=P2^0;
- sbit K1=P3^1;
- void delay(u16 i)
- {
- while(i--);
- }
- void keypros()
- {
- if(K1==0)
- {
- delay(1000);
- if(K1==0)
- {
- led=~led;
- motor_ccw;
- }
- while(!K1);
- }
- }
- void main()
- {
- while(1)
- {
- keypros();
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------------------------
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
-
- uchar code CCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; //逆时钟旋转相序表
- uchar code CW[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; //正时钟旋转相序表
-
- void delaynms(uint aa)
- {
- uchar bb;
- while(aa--)
- {
- for(bb=0;bb<115;bb++) //1ms基准延时程序
- {
- ;
- }
- }
-
- }
- void motor_ccw()
- {
- uchar i,j,k;
- for(k=0;k<128;k++)
- {
- for(j=0;j<8;j++) //电机旋转一周,不是外面所看到的一周,是里面的传动轮转了一周
- {
- for(i=0;i<8;i++) //旋转45度
- {
- P1=CCW[i];
- delaynms(1); //调节转速
- }
- }
- }
- P1=0xf0;
- }
- void motor_cw()
- {
- uchar i,j,k;
- for(k=0;k<128;k++)
- {
- for(j=0;j<8;j++)
- {
- for(i=0;i<8;i++) //旋转45度
- {
- P1=CW[i];
- delaynms(1); //调节转速
- }
- }
- }
- P1=0xf0;
- }
复制代码
|