51单片机测试马达转速
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include "INTRINS.H"
#define uchar unsigned char
#define uint unsigned int
#include "lcd12864.h"
uchar write,miao,shi,fen;
#include "ad.h"
sbit vcc=P2^7;
sbit leda=P2^6;
sbit beep=P2^3;
sbit PASS=P2^4;
sbit FAIL=P2^5;
sbit mada=P4^0;
//sbit key=P3^2;
sbit key=P0^6;
sbit PASS_BY1=P0^5;
sbit FAIL_BY1=P0^4;
void DisplayOneChar(uchar X,uchar Y,uint num);//在第X+1行的第Y+1位置显示一个字符
void DelayMs(uint Ms);//1MS基准延时程序
uint gb,gb1,gb2,gb3;//转速值
uint rs;
uchar write,miao,shi,fen;
uchar pass_num;
uchar mada_temp;
uchar key_num,key1_num;
uchar ck;
void didi(uchar num, uint teme,teme1)
{
uchar di_num;
for(di_num=num;di_num>0;di_num--)
{
beep=0;
delayms(teme);
beep=1;
delayms(teme1);
}
}
//***********************主程序******************************
main()
{
uchar num;
Lcd_Init();
mada=0;
vcc=0;
leda=0;
P4M1=0x00;
P4M0=0xff;
PASS=1;
FAIL=0;
ADC_Power_On(); //开AD电源
TMOD=0x51;//设定T0以工作方式1定时10毫秒
ET0=1;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
TR0=0;//关闭定时0
TR1=0;
delayms(10);
while(1)
{
if((key==0)&&(key_num!=1))
{
delayms(20);
if((key==0)&&(key_num!=1))
{
key_num=1;
}
}
if(key==1)
{
delayms(20);
if(key==1)
{
key_num=0;
key1_num=0;
ck=0;
}
}
if((key_num==1)&&(key1_num==0))
{
mada=1;
mada_temp=0;
miao=0;
pass_num=0;
Lcd_WriteCmd(0x80+3);
for(num=8;num<14;num++)
{
Lcd_WriteData(table1[num]);
}
Lcd_WriteCmd(0x98+0);
for(num=8;num<25;num++)
{
Lcd_WriteData(table1[num]);
}
key1_num=1;
}
if((TR1!=1)&&(mada==1))
{
Lcd_WriteCmd(0x90);
for(num=0;num<16;num++)
{
Lcd_WriteData(table6[num]);
}
/* if((gb>5)&&(miao<6))
{
Lcd_WriteCmd(0x88);
for(num=0;num<10;num++)
{
Lcd_WriteData(table8[num]);
}
Lcd_WriteData(digit[miao]);
} */
if(miao>1)
{
if((rs>200)&&(rs<283))
{
if(pass_num==0)
{
Lcd_WriteCmd(0x80+3);
for(num=0;num<4;num++)
{
Lcd_WriteData(table1[num]);
}
didi(1, 500,1000);
pass_num=1;
delayms(100);
mada=0;
if((ck==0)&&(key!=1))
{
PASS_BY1=0;
delayms(1000);
delayms(1000);
PASS_BY1=1;
ck=1; //只闪一次;
}
}
}
else
if(pass_num!=1)
{
Lcd_WriteCmd(0x80+3);
for(num=4;num<8;num++)
{
Lcd_WriteData(ta
ble1[num]);
}
if(miao>2)
{
didi(3, 500,1000);
}
delayms(100);
mada=0;
if((ck==0)&&(key!=1))
{
PASS_BY1=1;
FAIL_BY1=0;
delayms(1000);
delayms(1000);
FAIL_BY1=1;
ck=1; //只闪一次;
}
}
}
caiyangP10();
displayP10();
TR0=1;//10毫秒开始计时
TR1=1;//开始计数
}
}
}
void t0() interrupt 1 //定时中断服务函数
{
uchar num;
TH0=(65536-50000)/256; //对TH0 TL0赋值
TL0=(65536-50000)%256; //重装计数初值
write++;
if(write>=20)
{
write=0;
TR0=0;//关闭定时0
TR1=0;
gb=(unsigned long)(TH1*256+TL1);
rs=gb;
Lcd_WriteCmd(0x88);
for(num=0;num<8;num++)
{
Lcd_WriteData(table7[num]);
}
DisplayOneChar(0x88, 4, rs);
if(miao<3)
{
miao++;
}
TF0=0;//清楚定时器0溢出标志
TH1=0;
TL1=0;
}
}
//*****************************************************