- #include <reg52.h>
- #include "sound.h"
- #include "LED.h"
- #include "moto.h"
- #include "IT0.h"
-
- static int normal_speed = 2; //标准速度
-
- static char speed=0,now_speed=0; //保存原速度
- static int num=0,num1,num2 ,moto_mian_i;
- /*速度自动调整对照表*/
- char speed_table1[]={0,1,2,3,4,5,6,7,8,};
- char speed_table2[]={0,-1,-2,-3,-4,-5,-6,-7,-8,};
-
- void moto_seed_table0()
- {
- if(normal_speed > speed) //水滴速度过慢,电机正转
- {
- now_speed = speed_table1[normal_speed - speed];
- LED1_display(now_speed); /*显示要调整的速度*/
-
- /*重新设置电机转动角度*/
- moto_begin = moto_qu_j = 0;
- moto_qu_k = 0;
- moto_qu_kk = moto_qu_one * (now_speed);
-
- }
- if(normal_speed < speed) //水滴速度过快,电机反转
- {
- now_speed = speed_table2[speed - normal_speed];
- LED1_display(-now_speed);
-
- moto_begin = moto_qu_j = 4;
- moto_qu_k = 0;
- moto_qu_kk = moto_qu_one * (-now_speed);
- }
- }
- void moto_seed(void)
- {
- moto_seed_table0();
-
- moto_dispose(now_speed); //设置速度
-
- }
- /*速度计算*/
- void IT0_done()
- {
- speed = num/1; //计算速度
-
- moto_seed_table0(); //设置速度
- num1 = num/10; //分离出十位
- num2 = num%10;
- num = 0; //计算清0
- }
- void main()
- {
- init_IT0(2); //设置彩样周期
-
- IT0=1;
- EX0=1;
-
- while(1)
- {
-
- if(normal_speed!=speed) moto_seed();
- /*防止误计数保持一定间隔时间(水滴的最大速度)*/
- for(moto_mian_i=100;moto_mian_i>0;moto_mian_i--)
- {
- EX0=0;
- LED2_display(num1,num2);
- }
-
- EX0=1;
-
- }
-
- }
- void Int0() interrupt 0 //采样处理函数
- {
-
- EX0=0; //防止连续计数
-
- sound(); //发出声音、同时起延时作用
-
- num ++; //保存计数值
-
- EX0=1;
-
- }