Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help to understand code for DC motor

Status
Not open for further replies.

Fan174

Member level 2
Member level 2
Joined
Mar 27, 2018
Messages
51
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
413
someone can tell me whats happening in the code as I can understand it has written to control the speed of DC motor

Code:
/********************************
FILE NAME:        dcmotor.c
CHIP TYPE:        AT89C51
CLOCK FREQUENCY:  12MHZ
IDE:              VSMStudio
COMPILER:         IAR for 8051
TIME:             September 2010
********************************/

#include "ioAT89C51.h"
#include "intrinsics.h"

// Define P3 pins
#define Inc   (P3_bit.P3_4) 
#define Dec   (P3_bit.P3_5)
#define Dir   (P3_bit.P3_6) 
#define PWM   (P3_bit.P3_7)

// Define new types
typedef unsigned char   uchar;
typedef unsigned int    uint;

void delay(uint);

void main(void)
 { int speed;
   // Select initial direction and speed.
   Dir = 1;
   if (Dir)
      speed = 400;
   else
      speed = 100;
   
   // Main control loop
   while(1)
    { if(!Inc)
      // Increase speed   
         speed = speed > 0 ? speed - 1 : 0;
      if(!Dec)
      // Decrease speed
         speed = speed < 500 ? speed + 1 : 500;
      
      // Drive a PWM signal out. 
      PWM=1;
      delay(speed);
      PWM=0;
      delay(500-speed);
    }
 }

void delay(uint j)
 { for(; j>0; j--)
    { __no_operation();
    }
 }
 

Hi,

Please don't ask that global questions. The forum can't replace scool or tutorials.

Please tell us what you understand so far.
Then ask a detailed question about what is not clear to you.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top