当前位置:文档之家› 心率计51单片机代码.doc

心率计51单片机代码.doc

t=1500;
while(t--);
}
}
void SMG_Display(unsigned int num)
{
SMG_ShowNum(num/1000);
P0 =0x08>>1;
delay_ms(2);
SMG_ShowNum((num%1000)/100);
P0 =0x08>>2;
delay_ms(2);
void Timer0_Init()
{
TMOD = 0x01;
TR0 = 1;//16位定时器工作方式
TH0 = T1MS>>8;
TL0 = T1MS;
ET0 = 1;//打开定时器0中断
EA = 1;//打开总中断
}
void Timer0_ISR() interrupt 1
{
unsigned int temp;
count++;
TH0 = T1MS>>8;
TL0 = T1MS;
if(count=5000)
temp=Xinlv;
for{}
SMG_Display(temp);
}
数码管部分代码
void HC595_send_byte(unsigned char byte)
{
unsigned char i,temp;
unsigned char seg[10] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
sbit HC595_RST = P0^6;
sbit HC595_SCK = P0^4;
sbit HC595_RCK = P0^5;
sbit HC595_DAT = P0^7;
for(i=0;i<8;i++)
{
temp = byte&(1<<i);
if(temp) HC595_DAT = 1;
else HC595_DAT = 0;
HC595_SCK = 1;//SCK产生一个上升沿
HC595_SCK = 0;
}
HC595_RCK = 1;//RCK产生一个上升沿
HC595_RCK = 0;
外部中断代码
void Exti0_Init()
{
IT0 = 1;//下降沿触发 TCON.0=1
EX0 = 1;//开外部中断0 IE.0=1
EA = 1;//开总中断
}
void Exit0_ISR() interrupt 0
{
Xinlv++;
LED0=0;
delay_ms(2);
LED0=1;
}
定时器代码
SMG_ShowNum((num%100)/10);
P0 =0x08>>3;
delay_ms(2);
SMG_ShowNum(num%10);
P0 =0x08>>4;
delay_ms(2);
}
void main(void)
{
while(1)
{
}
}
}
void SMG_ShowNum(unsigned int num)//数码管显示函数
{
HC595_send_byte(tab_seg[num]);
}
void delay_ms(unsigned int time)//延时函数
{
unsigned int t;
for(;time>0;time--)
{
#includeude "SMG.h"
#define FSOC 24000000L
#define T1MS (65536-FSOC/12/1000)
sbit LED0 = P0^0;
unsigned int count=0;计时标志数
unsigned int xinlv=0;心率计算器
相关主题