AVR drive floppy drive motor program

Publisher:一条属马的龙Latest update time:2016-10-29 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Times have changed and floppy drives are no longer useful, but the motor inside is quite interesting, so I took it out and studied it.

 

CODE:

/*Use mega32 three port lines to drive the floppy drive motor. 
PA2 connects to LB1833 ENA1\2 pin; 
PA1 connects to LB1833 IN1 pin; 
PA0 connects to LB1833 IN2 pin. 
****************************************************** /
//ICC- AVR  application builder : 2005-5-20 10:40:30 
// Target : M32 
// Crystal: 3.6864Mhz 

#include 
#include 

unsigned char np; 

//Stepper motor operation data table 
const unsigned char motortb[]={0x05,0x07,0x06,0x04,0x05,0x07,0x06,0x04}; 

void delay ( unsigned char t );// Subroutine for each step delay 
void a_step( unsigned char d, unsigned char t );//Stepper motor takes one step d=0 forward d=1 reverse 

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 )// Subroutine for each step delay 

  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) //Stepper motor takes one step d=0 forward d=1 reverse t // The bigger the t, the slower it goes 

  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)// The stepper motor makes one turn 

  unsigned char i; 
  for ( i = 0 ; i < 96 ; i++ ) 
  { 
    a_step ( d, t ); 
  } 



void main ( void ) 

  n p = 4; 
  while (1) 
  { 
    a_turn (1, 1); 
  } 

Keywords:AVR Reference address:AVR drive floppy drive motor program

Previous article:Fast PWM of T0
Next article:Infrared remote control decoding program RC5 decoding

Recommended ReadingLatest update time:2024-11-16 20:30

AVR microcontroller I2C bus experiment
AVR MCU I2C bus experiment. 1. Use 24C02 to record the number of CPU startups and display it on the PB port. 2. Internal 1 M crystal oscillator, program uses single task mode, software delay. 3. For this experiment, please plug in all 8 short-circuit blocks of JP1 and JP7 (LED_EN)/PC0/PC1 short-circuit b
[Microcontroller]
AVR IO output digital tube scanning program
System functions Use AVR to scan four digital tubes, dynamic scanning, dynamic display, left scan, right scan, back and forth scan... hardware design AVR main control circuit schematic diagram  Digital tube dynamic scanning circuit schematic diagram software design The following part is copied from TXT and
[Microcontroller]
AVR IO output digital tube scanning program
The difference and use of AVR's INT external interrupt and PCINT interrupt
INT external interrupt is available in almost all general-purpose microcontrollers and embedded computers. The early 51 series and arm series also have it. However, due to design reasons, most of them only have two INTs. Recently, someone mentioned that "all ports can have external interrupts". Because I was skeptical
[Microcontroller]
The difference and use of AVR's INT external interrupt and PCINT interrupt
Active crystal oscillator recovery method to solve the AVR microcontroller fuse lock problem
Many AVR microcontroller beginners may easily make mistakes in the fuse bits when using AVR microcontrollers, causing the microcontroller to be locked. For example, after JTAGEN is set to 1, the JTAG of the microcontroller can no longer download programs into it, which brings us a lot of trouble.  A common recovery
[Microcontroller]
Active crystal oscillator recovery method to solve the AVR microcontroller fuse lock problem
Lighting and CO2 control system for watermelon greenhouse production based on AVR
1. Project Overview 1.1 Introduction A greenhouse is a place that can change the growth environment of plants, create optimal conditions for plant growth, and avoid the influence of seasonal changes and bad climate on them. It uses light-collecting covering materials as all or part of the structural materials, and
[Microcontroller]
Lighting and CO2 control system for watermelon greenhouse production based on AVR
Analysis of EEPROM Reading and Writing of AVR Microcontroller
Introduction: This article introduces the time problem of reading and writing data in EEPROM of AVR microcontroller, and analyzes the advantages and disadvantages of three methods. Since the AVR EEPROM write cycle is relatively long (usually in milliseconds), special attention should be paid during programming. Ther
[Microcontroller]
AVR MCU fuse configuration and related solutions
Users can configure the fuse bits of AVR using parallel programming, ISP programming, and JTAG programming, but different programming tools provide different ways to configure the fuse bits (referring to the human-machine interface). Some are by directly filling in the fuse bit values ​​(such as: CVAVR, PonyProg2000 a
[Microcontroller]
AVR MCU fuse configuration and related solutions
AVR review notes--IIC read and write multiple 24cxxx
In fact, I just backed up some code and added some comments, because it is easy and there is nothing much to say. . . First define some things #define PORT_IIC PORTC #define DDR_IIC DDRC #define BIT_SCL 0 #define BIT_SDA 1 #define TW_START 0X08 #define TW_REP_START 0X10 #define TW_MT_SLA_ACK 0X18 Let's get to the po
[Microcontroller]
AVR review notes--IIC read and write multiple 24cxxx
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号