PIC单片机解密网


首页 -- PIC单片机解密-- PIC24单片机解密-- PIC33单片机解密-- PIC18单片机解密 --关于我们
 

AVR驱动软驱电机程序

[导读]时代变了,软驱没有用了,但是里面的电机是比较好玩的,拿出来研究研究。CODE:
/*用mega32三个口线驱动软驱电机.
PA2接LB1833 ENA1\2 脚;
PA1接LB1833 IN1 脚;
PA0接LB1833 IN2 脚.

时代变了,软驱没有用了,但是里面的电机是比较好玩的,拿出来研究研究。

CODE:
/*用mega32三个口线驱动软驱电机.
PA2接LB1833 ENA12 脚;
PA1接LB1833 IN1 脚;
PA0接LB1833 IN2 脚.
*************************************************** /
//ICC-AVRapplication builder : 2005-5-20 10:40:30
// Target : M32
// Crystal: 3.6864Mhz

#include
#include

unsigned char np;

//步进电机运行数据表
const unsigned char motortb[]={0x05,0x07,0x06,0x04,0x05,0x07,0x06,0x04};

void delay ( unsigned char t );// 每步延时的子程序
void a_step( unsigned char d, unsigned char t );//步进电机走一步d=0 正转d=1 反转

void port_init( void )
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0x00;
PORTC = 0xFF;
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}

//call this routine to initialise all peripherals
void init_devices( void )
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}

void delay ( unsigned char t )// 每步延时的子程序
{
unsigned char i;
unsigned int j;
for (i = 0 ; i < t ; i++ )
{
for ( j = 0 ;j < 800 ; j++ )
;
}
}
void a_step ( unsigned char d, unsigned char t) //步进电机走一步d=0 正转d=1 反转 t // 越大走得越慢
{
if ( d & 0x01 )
{
if ( np == 0 )
{
np = 7;
}
else
{
np--;
}
}
else
{
if ( np == 7 )
{
np = 0;
}
else
{
np++;
}
}
PORTA = motortb[np];
delay(t);
}
void a_turn (unsigned char d, unsigned char t)// 步进电机走一圈
{
unsigned char i;
for ( i = 0 ; i < 96 ; i++ )
{
a_step ( d, t );
}
}


void main ( void )
{
np = 4;
while (1)
{
a_turn ( 1, 1 );
}

}
返回顶部


2013-2015 PIC单片机解密网 All Rights Reserved.
如有任何问题和建议请联系:498187676@qq.com

深圳市星光芯电子有限公司 版权所有

电话:0755-88820678 QQ: 498187676 地址:深圳市龙岗区南湾街道平吉大道1号建昇大厦B栋1618(李朗软件园对面)
手机:13713820066 联系人:周工


 


站点地图

粤ICP备12084176号