×
单片机 > 单片机程序设计 > 详情

用Proteus仿真H桥+直流伺服电机 附详细文档+源程序

发布时间:2020-06-05 发布时间:
|

仿真原理图如下

单片机源程序如下:

/*******************************************************************************

* 文 件 名       : main.c

* 函数功能                 : LCD 显示控制|中断初始化|主程序

*******************************************************************************/



#include

#include "stdio.h"

#include "lcd.h"

#include "key.h"


sbit motor_en1=P2^4;                 //电机方向控制引脚

sbit motor_en2=P2^5;

sbit motor_en=P2^0;


sbit Led_start=P2^2;

sbit Led_stop=P2^1;


double speed=0;

uint state=0;                                 //电机状态

uint dirt=0;                                //运行方向



sbit temp=P0^7;


void init()

{

        TMOD=0x51;

        TH0=(65536-1000)/256;                        //定时1ms

        TL0=(65536-1000)%256;                        //低8位

        TH1=0;

        TL1=0;

        EA=1;                                                   //总中断开启

        ET0=1;

        TR1=1;                                                         //计数

        TR0=1;


          Led_start=0;

          Led_stop=0;

          motor_en=0;

}


void main ()

{

        uchar str[9];

        init();

        lcd_init();                                //LCD初始化



        

        while(1)

        {

                sprintf((char*)str,"%.1frpm",speed);

                write_com(0x80+0x06);

                write_string(str);

                write_com(0x80+0x40+10);

                if(dirt)

                {

                        write_data('+');

                }

                else

                {

                        write_data('-');

                }




                key_judge();

                motor_control();

                

                

        }


}




『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
8051单片机的函数发生器的设计