STC89C52 MCU DC motor debugging

Publisher:asd123yuiLatest update time:2016-04-15 Source: eefocusKeywords:STC89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
///////////////////////////////////////////////////// /////////////////////////

Function: Configure timer 1 to generate an interrupt every 1 millisecond. By counting the number of interrupts,
    the 0th pin of the defined P2 port generates a PWM with a duty cycle of 70%, which is used to drive the DC
    motor
Experimental board model: BS-XYD-C52
Experiment name:  DC motor test experiment
Written by:  Xie Yingdong
Written date:  2012-4-30      
/////////////////////////////////////////////////////////////////////////////
#include

#define uchar unsigned char
#define uint unsigned int

#define FOSC 12000000L
#define TIMS  (65535-FOSC/12/1000)   //Calculation method for timer interrupt 1 second in 12T mode

uchar cCount;     //Define the number of timer interrupts, in turn according to the PWM generated sbit PWM
 
=P2^0;  // Define the   pin connected to the DC motor as PWM 
/// ... This is done, so if you change the frequency of the crystal oscillator , please make corresponding changes / ... /// ... ​ ​ ​ ​ ​ ​



         
   


         



 
 
 
    
    
 







void Init_System()
{
 DelayMs(50);  //Stabilize the system
 TMOD|= 0x10;  //Set timer 1 to mode 1 (16bit)
 //PWM 
 TL1 = TIMS;   //Assign initial value to the low byte register of timer 1
 TH1 = TIMS>>8;   //Assign initial value to the high byte register of timer 1
 TR1  = 1;    //Let timer 1 start working
 ET1=1;    //Turn on the interrupt enable bit of timer 1
 EA=1;            //Enable global interrupts

 cCount  = 0 ; //       Assign initial values ​​to global variables
}
/// ... ​ ​​​​ ​ if(cCount<30)  //define duty cycle PWM =0 ; else PWM = 1 ;  } } /// ...








 
 
 
   
   
   
   
  
 







void Timer1_Routine(void) interrupt 3
{
 TL1 = TIMS;    //Reassign the low byte register of timer 1
 TH1 = TIMS>>8;    //Reassign the high byte register of timer 1
 cCount++;      //
}

Keywords:STC89C52 Reference address:STC89C52 MCU DC motor debugging

Previous article:STC89C52 MCU 1602 LCD driver
Next article:STC89C52 MCU stepper motor debugging

Latest Microcontroller Articles
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号