#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define OUT P2
sbit pos = P1^0;
sbit neg = P1^1;
uint TIME;
uchar code turn[] = {0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
void main()
{
uchar a;
OUT = 0x03;
TMOD = 0x01;
TH0 = 0x3c;
TL0 = 0xb0;
EA = 1;
ET0 = 1;
TR0 = 1;
/*
定时器时间=(65536-15536)*12/12=5000us=5ms
电机转速计算n=60000/(10*8)=750 r/min
*/
while(1)
{
if (pos&&neg) TIME=0;
if (!pos)
{
if (TIME==2)
{
a = a<8?a+1:0;
OUT = turn[a];
TIME = 0;
}
}
if (!neg)
{
if (TIME==2)
{
a = a>0?a-1:7;
OUT = turn[a];
TIME = 0;
}
}
}
}
void timer(void)interrupt 1 using 0
{
TH0=0x3c;
TL0=0xb0;
TIME++;
}
关键字:51单片机 Proteus仿真 步进电机
引用地址:
(逗比小憨憨51单片机Proteus仿真系列视频)第43期基于单片机的步进电机的正反转控制
推荐阅读最新更新时间:2026-03-24 17:11
基于srtm32驱动步进电机Proteus仿真程序
单片机源程序如下: #include main.h #include stm32f1xx_hal.h TIM_HandleTypeDef htim1; void LcdDelay(uint32_t time) { while(time--); } void _NOP_(void) { uint32_t i = 100; while(i 0) { i--; } } void Delay(__IO uint32_t nCount) { for(; nCount != 0; nCount--); } void delay_us(__IO uint32
[单片机]
四相步进电机proteus仿真及程序
#include regx51.h #define forward P2_0 #define backward P2_1 #define bujinjia P2_2 #define bujinjian P2_3 #define jiasu P2_6 #define jiansu P2_5 #define stop P2_4 static unsigned int k=0; static unsigned int j=0; code char fward ={0x33,0x99,0xcc,0x66}; code char bward ={0x99,0x33,0x66,0xcc}; unsigned char timer0_tic
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第18期单片机矩阵键盘+数码管显示
源代码: KEYBUF EQU 40H ORG 0000H LJMP MAIN ORG 0030H MAIN: MOV KEYBUF,#0 MOV R0,#30H MOV R2,#0CH CLR A QING: MOV @R0,A INC R0 DJNZ R2,QING MOV P0,#8FH MOV R1,#30H DIS1: MOV R0,#30H MOV R2,#04H MOV R3,#05H DIS2: MOV A,@R0 AN
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第16期基于单片机的走马灯设计与仿真
源代码: #include reg52.h unsigned char RunMode; void Delay1ms(unsigned int count) { unsigned int i,j; for(i=0;i count;i++) for(j=0;j 120;j++); } unsigned char code LEDDisplayCode = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, //0~7 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF}; void Display(unsigned
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第33期单片机+DAC0832产生三角波(汇编)
源代码: 第33期DAC0832产生三角波(汇编) ;程序中产生的电压的最大幅度受DAC0832的基准电压限制 ORG 0000H AJMP MAIN ORG 0030H MAIN: MOV DPTR,#7FFFH MOV A,#00H LOOP1:MOVX @DPTR,A INC A NOP CJNE A,#0FFH,LOOP1 LOOP2:DEC A MOVX @DPTR,A CJNE A,#00H,LOOP2 INC A NOP AJMP LOOP1 END
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第15期基于单片机的LCD12864显示图片实验
源代码: #include reg52.h #include intrins.h #define LcdDataPort P2 typedef unsigned char u8; typedef unsigned int u16; sbit Busy = P2^7; sbit Reset = P3^0; sbit RS = P3^1; sbit E = P3^2; sbit RW = P3^3; sbit CS1 = P3^4; sbit CS2 = P3^5; const u8 code table1 =
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第9期单片机驱动LCD1602显示
源代码: #include reg52.h typedef unsigned char u8; typedef unsigned int u16; sbit lcden = P3^4; sbit lcdrs = P3^5; u8 code line1 = "good"; u8 code line2 = " Doubixiaohanhan"; u8 num; void delay(u16); void init(); void write_com(u8); void write_data(u8); void main(v
[单片机]
《逗比小憨憨51单片机Proteus仿真系列》第13期单片机的虚拟串口实验仿真
源代码: #include reg51.h //void delay_ms(int xms) //{ // int k,j; // for(k = 0; k xms; k++) // for(j = 0; j 125; j++);//1ms //} void init(void) { TMOD = 0X20; SCON = 0X50; PCON = 0X00; TL1 = 0XFD; TH1 = 0XFD; //11.0592M 9600 TR1 = 1; } void main(void) { unsigned char dat; init(); while(1) { if(RI) {
[单片机]