|
51蓝牙心率计的程序,我只是搬运工==
- #include<reg52.h>
- #include <intrins.h> // 包含头文件
- #define uint unsigned int
- #define uchar unsigned char
- sbit wei1=P1^0; //数码管位选
- sbit wei2=P1^1;
- sbit wei3=P1^2;
- sbit wei4=P1^3;
- unsigned char i=0,timecount=0,displayOK=0,rate=0,aa=0;
- unsigned int time[6]={0};
- uchar code table[]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- //发送十六进制字节数据
- void SendByte(uchar dat)
- {
- SBUF = dat;
- while(!TI);
- TI = 0;
- }
- /************ 延时函数 *****************/
- void DelayMs(unsigned int z)
- {
- unsigned int x;
- for(;z>0;z--)
- for(x=110;x>0;x--);
- }
- void display(uchar bai,uchar shi,uchar ge)
- {
- wei1=0; //显示百位
- P0=bai;
- DelayMs(1);
- wei1=1;
- P0=0xff;
- wei2=0; //显示十位
- P0=shi;
- DelayMs(1);
- wei2=1;
- P0=0xff;
-
- wei3=0; //显示个位
- P0=ge;
- DelayMs(1);
- wei3=1;
- P0=0xff;
-
- }
- void main()
- {
- TCON=0x01;//设置外部中断0
- EX0=1;
- TMOD=0x21;//定时器0初始化
- TH0=(65536-50000)/256;//实测每50ms中断的定时值
- TL0=(65536-50000)%256;
- ET0=1;//开定时器中断
-
- TR0=0;//定时器停止
- EA=1;//开总中断
- SCON=0x50;
- TH1=0xfd;
- TL1=0xfd;
- TCON=0x40;
- TR1=1;
- ES = 1;
- while(1)
- {
-
-
- if(displayOK==1)
- {
- rate=60000/(time[1]/5+time[2]/5+time[3]/5+time[4]/5+time[5]/5);
-
- display(table[rate/100],table[rate/10%10],table[rate%10]);
-
-
- }
- DelayMs(300);
-
-
- SendByte(rate);
-
- }
- }
- void ex0() interrupt 0
- {
- EX0=0;//暂时关外部中断
- if(timecount<8) //当连续两次检测时间间隔小于8*50ms=400ms不处理
- {
- TR0=1;//开定时器
- }
- else
- {
- time[i]=timecount*50+TH0*0.256+TL0/1000;//算出间隔时间
- TL0=(65536-50000)%256;//重新设置定时器
- TH0=(65536-50000)/256;
- timecount=0;//50ms计数清零
- i++;
- if(i==6)//记录到超过等于6次时间
- {
- i=1;//计数从1开始
- displayOK=1; //测得5次开始显示
- }
-
- }
- EX0=1;
- }
- void et0() interrupt 1
- {
- TL0=(65536-50000)%256;
- TH0=(65536-50000)/256;
-
- timecount++;//每50ms一次计数
- if(timecount>25) //当超过25*50ms=1.25s没有检测到信号停止显示
- {
- i=0;//数据个数清零
- timecount=0;//50ms计数清零
- displayOK=0;//显示关
- TR0=0;//定时器关
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- }
- }
- void RSINTR() interrupt 4 using 2
- {
- if(RI==1) //接收中断
- {
- RI=0;
-
- switch(SBUF)
- {
-
- }
- }
- }
复制代码
|
|