此仿真是基于单片机直流电机控制系统,使用了用L298驱动直流电机,并用按键控制电机正转、反转、加速、减速、停止、启动等功能,并用LCD作为电机状态显示,实现了基于L298N对电机PWM调速(示波器可观察PWM调速过程)。PWM调
速对LED进行灯光调节。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define lcd P0 /* lcd定义 */
#define KEY P3 /*按键定义 */
void LCD_Writecmd( uchar cmd );
void LCD_Writedata( uchar dat );
void LCD_write_char( uchar x, uchar y, char ch );
void LCD_write_str( uchar x, uchar y, char str[] );
void LCD_Init( void );
void LCD_clear();
void delay_us( uchar n );
void delay_ms( uchar m );
sbit RW = P2 ^ 1;
sbit RS = P2 ^ 0;
sbit EN = P2 ^ 2;
sbit pwm1 = P1 ^ 0;
sbit pwm2 = P1 ^ 1;
sbit pwm = P1 ^ 3;
sbit ZHENG = P1 ^ 4;
sbit FAN = P1 ^ 5;
sbit TIAO = P1 ^ 6;
void timer_init();
uchar a = 50, b = 0, c = 0, flag = 0, flag1 = 0;
void main()
{
LCD_Init();
timer_init();
LCD_write_str( 0, 0, "State:" );
while ( 1 )
{
b = a / 10 + 0x30;
c = a % 10 + 0x30;
if ( KEY == 0xfe )
{