|
51藍(lán)牙心率計(jì)的程序,我只是搬運(yùn)工==
- #include<reg52.h>
- #include <intrins.h> // 包含頭文件
- #define uint unsigned int
- #define uchar unsigned char
- sbit wei1=P1^0; //數(shù)碼管位選
- 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};
- //發(fā)送十六進(jìn)制字節(jié)數(shù)據(jù)
- void SendByte(uchar dat)
- {
- SBUF = dat;
- while(!TI);
- TI = 0;
- }
- /************ 延時(shí)函數(shù) *****************/
- 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; //顯示個(gè)位
- P0=ge;
- DelayMs(1);
- wei3=1;
- P0=0xff;
-
- }
- void main()
- {
- TCON=0x01;//設(shè)置外部中斷0
- EX0=1;
- TMOD=0x21;//定時(shí)器0初始化
- TH0=(65536-50000)/256;//實(shí)測(cè)每50ms中斷的定時(shí)值
- TL0=(65536-50000)%256;
- ET0=1;//開定時(shí)器中斷
-
- TR0=0;//定時(shí)器停止
- 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;//暫時(shí)關(guān)外部中斷
- if(timecount<8) //當(dāng)連續(xù)兩次檢測(cè)時(shí)間間隔小于8*50ms=400ms不處理
- {
- TR0=1;//開定時(shí)器
- }
- else
- {
- time[i]=timecount*50+TH0*0.256+TL0/1000;//算出間隔時(shí)間
- TL0=(65536-50000)%256;//重新設(shè)置定時(shí)器
- TH0=(65536-50000)/256;
- timecount=0;//50ms計(jì)數(shù)清零
- i++;
- if(i==6)//記錄到超過等于6次時(shí)間
- {
- i=1;//計(jì)數(shù)從1開始
- displayOK=1; //測(cè)得5次開始顯示
- }
-
- }
- EX0=1;
- }
- void et0() interrupt 1
- {
- TL0=(65536-50000)%256;
- TH0=(65536-50000)/256;
-
- timecount++;//每50ms一次計(jì)數(shù)
- if(timecount>25) //當(dāng)超過25*50ms=1.25s沒有檢測(cè)到信號(hào)停止顯示
- {
- i=0;//數(shù)據(jù)個(gè)數(shù)清零
- timecount=0;//50ms計(jì)數(shù)清零
- displayOK=0;//顯示關(guān)
- TR0=0;//定時(shí)器關(guān)
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- }
- }
- void RSINTR() interrupt 4 using 2
- {
- if(RI==1) //接收中斷
- {
- RI=0;
-
- switch(SBUF)
- {
-
- }
- }
- }
復(fù)制代碼
|
-
-
51藍(lán)牙心率計(jì).docx
2017-6-11 10:15 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
14.88 KB, 下載次數(shù): 28, 下載積分: 黑幣 -5
|