📄 exfiles.c
字号:
//单摆运动程序:
#include <pic.h>
#include <math.h>
#include <stdlib.h>
int i,j,k,m,n,x,y,t,left,right,posi=1,tr0,tr1,tr2,tr3,tmr;
void youbai(int); ///电机反转,顺时针
void zuobai(int); ///电机正转,逆时针
void baidong(void);
void ccp();
void baidong()
{
for(j=t;j--;){asm("call delay25ms");};
zuobai(6);
for(j=t;j--;){asm("call delay25ms");};
youbai(6);
}
void zuobai(left)
{for (i=left;i;)
{while(posi==4) ///posi 为位置position标志位
{ PORTD=0x0a;
asm("call delay50ms");
i--;
posi=1;};
if (i==0) break;
while(posi==1)
{
PORTD=0x06;
asm("call delay50ms");
i--;
posi=2;};
if (i==0) break;
while(posi==2)
{
PORTD=0x05;
asm("call delay50ms");
i--;
posi=3;};
if (i==0) break;
while(posi==3)
{
PORTD=0x09;
asm("call delay50ms");
i--;
posi=4;};
if (i==0) break;
}
}
void youbai(right)
{for (i=right;i;)
{while(posi==1) ///posi 为位置position标志位
{ PORTD=0x09;
asm("call delay50ms");
i--;
posi=4;};
if (i==0) break;
while(posi==4)
{
PORTD=0x05;
asm("call delay50ms");
i--;
posi=3;};
if (i==0) break;
while(posi==3)
{
PORTD=0x06;
asm("call delay50ms");
i--;
posi=2;};
if (i==0) break;
while(posi==2)
{
PORTD=0x0a;
asm("call delay50ms");
i--;
posi=1;};
if (i==0) break;
}
}
#asm
delay5ms
movlw 0ah
movwf _tr0
t1loop1
movlw 0a5h
movwf _tr1
t1loop2
decfsz _tr1
goto t1loop2
decfsz _tr0
goto t1loop1
return
delay50ms
movlw 0ah
movwf _tr2
call delay5ms
decfsz _tr2
goto $-2
return
delay25ms
movlw 05h
movwf _tr3
call delay5ms
decfsz _tr3
goto $-2
return
#endasm
void stopmoter()
{
ccp();
x=0;
y=0;
if(RC1==0) x=x+1;
asm("nop");
if(RC4==0) y=y+1;
asm("nop"); if((x%2==0)&&(y%2==1))
zuobai(1);
if((x%2==1)&&(y%2==0))
youbai(1);
}
void ccp()
{
INTCON=0X00;
PIE1=0;
PIR1=0;
TRISC=0X57;
CCP1CON=0X05;
TMR1IE=0;
TMR1IF=0;
T1CON=0X30;
TMR1ON=1;
CCP1IF=0;
if(CCP1IF==1)
{TMR1H=0;TMR1L=0;};
CCP1IF=0;
if(CCP1IF==1)
{tmr=TMR1L+TMR1H*0x100;};
}
main()
{
TRISD=0x00;
PORTD=0x0a;
youbai(3);
for(k=9;k--;)
{t=18;
baidong();};
for(k=77;k--;)
{t=16;
baidong();};
do
{t=22;
baidong();}while(1);
stopmoter();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -