兼职项目 智能自行车
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

144 lines
4.6 KiB

C51 COMPILER V9.56.0.0 PWM 04/06/2022 21:56:10 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE PWM
OBJECT MODULE PLACED IN pwm.OBJ
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE pwm.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2)
line level source
1 #include "pwm.h"
2
3 unsigned char pwm_val_left =0;//变量定义
4 unsigned char push_val_left =0;// 左电机占空比N/20
5 unsigned char pwm_val_right =0;
6 unsigned char push_val_right=0;// 右电机占空比N/20
7 unsigned char pwm_left=0;
8
9 bit Right_moto_stop=1;
10 bit Left_moto_stop =1;
11
12 unsigned int time1=0;
13
14
15
16 /************************************************************************/
17 //延时函数
18 void delay(unsigned int k)
19 {
20 1 unsigned int x,y;
21 1 for(x=0;x<k;x++)
22 1 for(y=0;y<2000;y++);
23 1 }
24 /************************************************************************/
25 //前速前进
26 void run(void)
27 {
28 1 push_val_left=3; //速度调节变量 0-20。。。0最小,20最大
29 1 push_val_right=pwm_left;
30 1 Left_moto_go ; //左电机往前走
31 1 Right_moto_go ; //右电机往前走
32 1 }
33
34 void backrun(void)
35 {
36 1 push_val_left=3; //速度调节变量 0-20。。。0最小,20最大
37 1 push_val_right=4;
38 1 Left_moto_back; //左电机往前走
39 1 Right_moto_back; //右电机往前走
40 1 }
41
42
43 //左转
44 void leftrun(void)
45 {
46 1 push_val_left=0;
47 1 push_val_right=4;
48 1 Right_moto_go ; //右电机往前走
49 1 }
50
51
52 //右转
53 void rightrun(void)
54 {
55 1 push_val_right=0;
C51 COMPILER V9.56.0.0 PWM 04/06/2022 21:56:10 PAGE 2
56 1 push_val_left=4;
57 1 Left_moto_go ; //左电机往前走
58 1 }
59
60
61 void pwm_out_left_moto(void)
62 {
63 1 if(Left_moto_stop)
64 1 {
65 2 if(pwm_val_left<=push_val_left)
66 2 {
67 3 Left_moto_pwm=1;
68 3 }
69 2 else
70 2 {
71 3 Left_moto_pwm=0;
72 3 }
73 2 if(pwm_val_left>=20)
74 2 pwm_val_left=0;
75 2 }
76 1 else
77 1 {
78 2 Left_moto_pwm=0;
79 2 }
80 1 }
81 /******************************************************************/
82 /* 右电机调速 */
83 void pwm_out_right_moto(void)
84 {
85 1 if(Right_moto_stop)
86 1 {
87 2 if(pwm_val_right<=push_val_right)
88 2 {
89 3 Right_moto_pwm=1;
90 3 }
91 2 else
92 2 {
93 3 Right_moto_pwm=0;
94 3 }
95 2 if(pwm_val_right>=20)
96 2 pwm_val_right=0;
97 2 }
98 1 else
99 1 {
100 2 Right_moto_pwm=0;
101 2 }
102 1 }
103
104 void timer1()interrupt 3
105 {
106 1 TH1=0XFc; //1Ms定时
107 1 TL1=0X18;
108 1 time1++;
109 1 // pwm_val_left++;
110 1 pwm_val_right++;
111 1 // pwm_out_left_moto();
112 1 pwm_out_right_moto();
113 1 }
114
115
116
117
C51 COMPILER V9.56.0.0 PWM 04/06/2022 21:56:10 PAGE 3
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 172 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 7 ----
IDATA SIZE = ---- ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)