📄 motorturn.i
字号:
#line 55 "C:\iccv7avr\include\macros.h"
void _StackCheck(void);
void _StackOverflowed(char);
#line 8 "F:\avr编程\电机转向程序\motorturn.c"
void Delay_1ms(void)
{ unsigned int i;
for(i=1;i<(unsigned int)(8*143-2);i++)
;
}
void Delay_nms(unsigned int n)
{
unsigned int i=0;
while(i<n)
{Delay_1ms();
i++;
}
}
void xpwm0(unsigned char f0)
{
(*(volatile unsigned char *)0x53)=0X2B;
(*(volatile unsigned char *)0x5C)=f0;
}
void xpwm2(unsigned char f2)
{
(*(volatile unsigned char *)0x45)=0X2B;
(*(volatile unsigned char *)0x43)=f2;
}
void io_inti(void)
{
(*(volatile unsigned char *)0x37)|=(1 << (1));
(*(volatile unsigned char *)0x37)|=(1 << (2));
(*(volatile unsigned char *)0x37)|=(1 << (4));
(*(volatile unsigned char *)0x37)|=(1 << (5));
(*(volatile unsigned char *)0x37)|=(1 << (6));
(*(volatile unsigned char *)0x37)|=(1 << (7));
(*(volatile unsigned char *)0x37)|=(1 << (3));
(*(volatile unsigned char *)0x31)|=(1 << (7));
}
void forward()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)|=(1 << (4));
(*(volatile unsigned char *)0x38)&=~(1 << (5));
(*(volatile unsigned char *)0x38)|=(1 << (6));
(*(volatile unsigned char *)0x38)&=~(1 << (7));
xpwm0(56);
xpwm2(56);
}
void back()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)&=~(1 << (4));
(*(volatile unsigned char *)0x38)|=(1 << (5));
(*(volatile unsigned char *)0x38)&=~(1 << (6));
(*(volatile unsigned char *)0x38)|=(1 << (7));
xpwm0(65);
xpwm2(65);
}
faststop()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)|=(1 << (4));
(*(volatile unsigned char *)0x38)|=(1 << (5));
(*(volatile unsigned char *)0x38)|=(1 << (6));
(*(volatile unsigned char *)0x38)|=(1 << (7));
(*(volatile unsigned char *)0x53)=0x00;
(*(volatile unsigned char *)0x45)=0x00;
}
void slowstop()
{ (*(volatile unsigned char *)0x38)&=~(1 << (1));
(*(volatile unsigned char *)0x38)&=~(1 << (2));
(*(volatile unsigned char *)0x53)=0x00;
(*(volatile unsigned char *)0x45)=0x00;
}
void turnleft(void)
{ (*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)|=(1 << (4));
(*(volatile unsigned char *)0x38)&=~(1 << (5));
(*(volatile unsigned char *)0x38)|=(1 << (6));
(*(volatile unsigned char *)0x38)&=~(1 << (7));
xpwm0(89);
xpwm2(98);
delay_nms(200);
}
void turnright()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)|=(1 << (4));
(*(volatile unsigned char *)0x38)&=~(1 << (5));
(*(volatile unsigned char *)0x38)|=(1 << (6));
(*(volatile unsigned char *)0x38)&=~(1 << (7));
xpwm0(98);
xpwm2(89);
delay_nms(200);
}
void backturnleft()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)&=~(1 << (4));
(*(volatile unsigned char *)0x38)|=(1 << (5));
(*(volatile unsigned char *)0x38)&=~(1 << (6));
(*(volatile unsigned char *)0x38)|=(1 << (7));
xpwm0(89);
xpwm2(98);
delay_nms(200);
}
void backturnright()
{
(*(volatile unsigned char *)0x38)|=(1 << (1));
(*(volatile unsigned char *)0x38)|=(1 << (2));
(*(volatile unsigned char *)0x38)&=~(1 << (4));
(*(volatile unsigned char *)0x38)|=(1 << (5));
(*(volatile unsigned char *)0x38)&=~(1 << (6));
(*(volatile unsigned char *)0x38)|=(1 << (7));
xpwm0(98);
xpwm2(89);
delay_nms(200);
}
void port_inti(void)
{ (*(volatile unsigned char *)0x3A)&=~(1 << (1));
(*(volatile unsigned char *)0x3A)&=~(1 << (2));
(*(volatile unsigned char *)0x3A)&=~(1 << (3));
(*(volatile unsigned char *)0x3B)|=(1 << (1));
(*(volatile unsigned char *)0x3B)|=(1 << (2));
(*(volatile unsigned char *)0x3B)|=(1 << (3));
}
void hongwaixunxian()
{ unsigned char temp;
port_inti();
while(1)
{temp=(*(volatile unsigned char *)0x39);
if(temp|0xfd==0xfd)
{
if((temp|0xfb=0xfd)&&(temp|0xf7==0xf7))
forward();
else
{turnleft();delay_nms();}
}
else if((temp|0xf7==0xf7))
{ if((temp|0xfb=0xfd)&&(temp|0xfd==0xfd)
forword();
else
{trunright();delay_nms();}
}
else
{forward();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -