標(biāo)題:
霍爾測速單片機源程序
[打印本頁]
作者:
Eric1235
時間:
2017-4-23 13:38
標(biāo)題:
霍爾測速單片機源程序
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
//sbit out=P2^2;
sbit dula=P2^6;
sbit wela=P2^7;
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P2^5;
uint z,n;
uchar num,a1,a2,a3,c,flag=0;
uchar code table []={"0123456789"};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uchar com) //寫命令
{
rs=0;
rw=0;
en=0;
P0=com;
delayms(4);
en=1;
delayms(4);
en=0;
}
void write_byt(uchar date) //寫數(shù)據(jù)
{
rs=1;
rw=0;
en=0;
P0=date;
delayms(4);
en=1;
delayms(4);
en=0;
}
void lcdinit() //初始化
{
write_com(0x38); //設(shè)置16*2顯示 5*7點陣 8位數(shù)據(jù)口
write_com(0x0c); //設(shè)置開顯示 不顯示光標(biāo)
write_com(0x06); //寫入字符后地址指針加1
write_com(0x01); //顯示清0;
}
void init()
{
TMOD=0x01;
TH0=0x4C;
TL0=0x00;
EA=1;
ET0=1;
TR0=1;
EX1=1;
IT1=1;
}
void main()
{
init();
lcdinit();
while(1)
{
write_com(0x80);
write_byt('R');
if(flag==1)
{
write_byt(table[a1]);
write_byt(table[a2]);
write_byt(table[a3]);
flag=0;
}
}
}
void t0() interrupt 1
{
TH0=0x4C;
TL0=0x00;
c++;
if(c==20)
{
c=0;
EX1=0;
n=60*z;
z=0;
flag=1;
TH0=0x4C;
TL0=0x00;
EX1=1;
}
a1=n/100;
a2=n%100/10;
a3=n%10;
}
void ji() interrupt 2
{
num++;
if(num==2)
{
z++;
num=0;
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1