找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1230|回复: 1
打印 上一主题 下一主题
收起左侧

速度测量器 lcd1602 stc89c52

[复制链接]
跳转到指定楼层
楼主
ID:812531 发表于 2021-1-21 20:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>

typedef unsigned char uchar;
typedef unsigned int uint;
sbit key=P3^4;
sbit key1=P3^5;
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P2^5;
sbit BEEP=P2^3;
unsigned char i,a,b,c,d,f,g,h,i;
unsigned char x,y,m,n,z;
float p,j;
int q,w,e,r,o;
void delayms(unsigned int xms)
{
   unsigned i,j;
        for(i=xms;i>0;i--)
           for(j=110;j>0;j--);
}

void Read_Busy()
{
        uchar busy;
        P0 = 0xff;
        RS = 0;
        RW = 1;
        do
        {
                EN = 1;
                busy = P0;
                EN = 0;
        }while(busy & 0x80);
}
//?LCD1602??????
void Write_Cmd(uchar cmd)
{
        Read_Busy();//???
        RS = 0;
        RW = 0;
        P0 = cmd;
        EN = 1;
        EN = 0;
}
//???????
void Write_Dat(uchar dat)
{
        Read_Busy();
        RS = 1;
        RW = 0;
        P0 = dat;
        EN = 1;
        EN = 0;
}
void charter(unsigned char x,unsigned char y,unsigned char dat)
{
if(y==0)
{
Write_Cmd(0x80+x);
}
else
{
Write_Cmd(0xc0+x);

}
Write_Dat( dat);  
}
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{     
if (y == 0)
        {     
Write_Cmd(0x80 + x);     
        }
else
        {     
Write_Cmd(0xC0 + x);     
        }        
while (*s)
        {     
Write_Dat( *s);     
s ++;     
        }
}
void lcdinit()
{
   Write_Cmd(0x38);  
   Write_Cmd(0x08);    /*????*/
   Write_Cmd(0x01);    /*????*/
   Write_Cmd(0x06);    /*????????*/
   Write_Cmd(0x0C);    /*????????*/
}
void Timer0Init(void)                //50??@11.0592MHz
{
        TMOD = 0x01;                //???????
       TH0=0xdc;               //10ms??
   TL0=0x00;
                ET0=1;
        EA=1;
        TR0 = 0;                //???0????


}
void beep()
{
    unsigned char y;
    for (y=0;y<180;y++)
    {
      BEEP=!BEEP;                //BEEP??
          delayms(70);
    }
    BEEP=1;                      //?????
}

void main()
{
unsigned char num,num1,u;
lcdinit();
Timer0Init();
        LCD_Write_String(0,1,"time:");
        LCD_Write_String(0,0,"speed:00:00cm/s");
        LCD_Write_String(5,1,"00:00:00:00");
while(1)
{

if(key==0)
{
        delayms(50);
if(key==0)
num=num+1;
while(!key);
}       

switch(num)
{
        case 1:TR0=1;
        //LCD_Write_String(0,0,"begin count 1");
                delayms(5);
        break;
        case 2:TR0=0;
                //LCD_Write_String(0,0,"pause count 2");
        delayms(5);
        break;
        case 3:TR0=1;
                //LCD_Write_String(0,0,"begin count 3");
        delayms(5);
        break;
        case 4:TR0=0;
        //LCD_Write_String(0,0,"pause count 4");
        delayms(5);
        break;                
}
if(key1==0)
{
       
LCD_Write_String(5,1,"00:00:00:00");
}



}
}



void timer() interrupt 1
{
TH0=0xdc;            
   TL0=0x00;
  a++;
        o=3546;
        charter(15,1,'0'+a);       
if(a==10)
{
       
        a=0;
        b++;
        x=b%10;
       
                charter(14,1,'0'+x);
}
if(b==10)
{
        b=0;
c++;

        y=c%10;
        charter(12,1,'0'+y);       
       
}
if(c==10)
{
c=0;

        d++;
        z=d%10;
        charter(11,1,'0'+z);               
}
if(d==6)
{
d=0;
                charter(11,1,'0'+0);       
        e++;
        m=e%10;
        charter(9,1,'0'+m);               
}
if(e==10)
{
e=0;
        f++;
        n=f%10;
                charter(8,1,'0'+n);               
}
p=a*0.01+b*0.1+c*1+d*10;
j=3/p;
o=j*100;
q=o/1000;
w=o%1000/100;
e=o%1000%100/10;
r=o%1000%100%10;
charter(6,0,'0'+q);
        charter(7,0,'0'+w);
        charter(9,0,'0'+e);
        charter(10,0,'0'+r);
}


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1001079 发表于 2022-2-21 17:04 | 只看该作者
有具体程序说明吗?测量原理?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表