心率计程序
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#include<intrins.h>
unsigned int scount;
sbit KEY=P3^0;
sbit RS = P2^4; //定义端口
sbit RW = P2^5;
sbit EN = P2^6;
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
#define DataPort P0
void DelayUs2x(unsigned char t)
{
while(--t);
}//微秒延时
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}//毫秒延迟
/*------------------------------------------------
判忙函数
------------------------------------------------*/
bit LCD_Check_Busy(void)
{
DataPort= 0xFF;
RS_CLR;
RW_SET;
EN_CLR;
_nop_();
EN_SET;
return (bit)(DataPort & 0x80);
}
/*------------------------------------------------
写入命令函数
------------------------------------------------*/
void LCD_Write_Com(unsigned char com)
{
while(LCD_Check_Busy()); //忙则等待
RS_CLR;
RW_CLR;
EN_SET;
DataPort= com;
_nop_();
EN_CLR;
}
/*------------------------------------------------
写入数据函数
------------------------------------------------*/
void LCD_Write_Data(unsigned char Data)
{
while(LCD_Check_Busy()); //忙则等待
RS_SET;
RW_CLR;
EN_SET;
DataPort= Data;
_nop_();
EN_CLR;
}
/*------------------------------------------------
清屏函数
------------------------------------------------*/
void LCD_Clear(void)
{
LCD_Write_Com(0x01);
DelayMs(5);
}
/*------------------------------------------------
写入字符串函数
------------------------------------------------*/
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x); //表示第一行
}
else
{
LCD_Write_Com(0xC0 + x); //表示第二行
}
while (*s)
{
LCD_Write_Data( *s);
s ++;
}
}
/*------------------------------------------------
写入字符函数
------------------------------------------------*/
void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x);
}
else
{
LCD_Write_Com(0xC0 + x);
}
LCD_Write_Data( Data);
}
/*------------------------------------------------
初始化函数
------------------------------------------------*/
void LCD_Init(void)
{
LCD_Write_Com(0x38); /*显示模式设置*/
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
LCD_Write_Com(0x08); /*显示关闭*/
LCD_Write_Com(0x01); /*显示清屏*/
LCD_Write_Com(0x06); /*显示光标移动设置*/
DelayMs(5);
LCD_Write_Com(0x0C); /*显示开及光标设置*/
}
void Timer0_int(void) interrupt 1 using 1
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TF0=0;
scount--;
if(scount>0)
TR0=1;
else
TR1=0;
}
main()
{
unsigned char a[3];
unsigned char shang,yu;
unsigned long int xinlv;
TMOD=0xD1;//定时器1计数方式1,定时器0定时方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
scount=600;
ET0=1;//开定时器0中断
EA=1;//开总中断
while(1)
{
if(!KEY) //如果检测到低电平,说明按键按下
{
DelayMs(10); //延时去抖
if(!KEY)
{
while(!KEY);
{
TR0=1;
TR1=1;
}
}
}
if(!scount)
{
shang=TH1;
yu=TL1;
TH1=0;
TL1=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
scount=600;
xinlv=shang*256+yu;
a[0]=xinlv/100;
a[1]=(xinlv/10)%10;
a[2]=xinlv%10;
LCD_Init();
LCD_Clear();//清屏
}
LCD_Write_Char(6,0,a[0]+'0');
LCD_Write_Char(7,0,a[1]+'0');
LCD_Write_Char(8,0,a[2]+'0');
}
}
我的红外心率计最后下载程序到单片机 按键接计数器1能测按键的次数 但是把心率计的输出接计数器1 30秒后显示计数为0 心率计输出波形我用示波器看过了 是可以的 高电平是3V多的一个矩形波 求助
#include<intrins.h>
unsigned int scount;
sbit KEY=P3^0;
sbit RS = P2^4; //定义端口
sbit RW = P2^5;
sbit EN = P2^6;
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
#define DataPort P0
void DelayUs2x(unsigned char t)
{
while(--t);
}//微秒延时
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}//毫秒延迟
/*------------------------------------------------
判忙函数
------------------------------------------------*/
bit LCD_Check_Busy(void)
{
DataPort= 0xFF;
RS_CLR;
RW_SET;
EN_CLR;
_nop_();
EN_SET;
return (bit)(DataPort & 0x80);
}
/*------------------------------------------------
写入命令函数
------------------------------------------------*/
void LCD_Write_Com(unsigned char com)
{
while(LCD_Check_Busy()); //忙则等待
RS_CLR;
RW_CLR;
EN_SET;
DataPort= com;
_nop_();
EN_CLR;
}
/*------------------------------------------------
写入数据函数
------------------------------------------------*/
void LCD_Write_Data(unsigned char Data)
{
while(LCD_Check_Busy()); //忙则等待
RS_SET;
RW_CLR;
EN_SET;
DataPort= Data;
_nop_();
EN_CLR;
}
/*------------------------------------------------
清屏函数
------------------------------------------------*/
void LCD_Clear(void)
{
LCD_Write_Com(0x01);
DelayMs(5);
}
/*------------------------------------------------
写入字符串函数
------------------------------------------------*/
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x); //表示第一行
}
else
{
LCD_Write_Com(0xC0 + x); //表示第二行
}
while (*s)
{
LCD_Write_Data( *s);
s ++;
}
}
/*------------------------------------------------
写入字符函数
------------------------------------------------*/
void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x);
}
else
{
LCD_Write_Com(0xC0 + x);
}
LCD_Write_Data( Data);
}
/*------------------------------------------------
初始化函数
------------------------------------------------*/
void LCD_Init(void)
{
LCD_Write_Com(0x38); /*显示模式设置*/
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
DelayMs(5);
LCD_Write_Com(0x38);
LCD_Write_Com(0x08); /*显示关闭*/
LCD_Write_Com(0x01); /*显示清屏*/
LCD_Write_Com(0x06); /*显示光标移动设置*/
DelayMs(5);
LCD_Write_Com(0x0C); /*显示开及光标设置*/
}
void Timer0_int(void) interrupt 1 using 1
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TF0=0;
scount--;
if(scount>0)
TR0=1;
else
TR1=0;
}
main()
{
unsigned char a[3];
unsigned char shang,yu;
unsigned long int xinlv;
TMOD=0xD1;//定时器1计数方式1,定时器0定时方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
scount=600;
ET0=1;//开定时器0中断
EA=1;//开总中断
while(1)
{
if(!KEY) //如果检测到低电平,说明按键按下
{
DelayMs(10); //延时去抖
if(!KEY)
{
while(!KEY);
{
TR0=1;
TR1=1;
}
}
}
if(!scount)
{
shang=TH1;
yu=TL1;
TH1=0;
TL1=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
scount=600;
xinlv=shang*256+yu;
a[0]=xinlv/100;
a[1]=(xinlv/10)%10;
a[2]=xinlv%10;
LCD_Init();
LCD_Clear();//清屏
}
LCD_Write_Char(6,0,a[0]+'0');
LCD_Write_Char(7,0,a[1]+'0');
LCD_Write_Char(8,0,a[2]+'0');
}
}
我的红外心率计最后下载程序到单片机 按键接计数器1能测按键的次数 但是把心率计的输出接计数器1 30秒后显示计数为0 心率计输出波形我用示波器看过了 是可以的 高电平是3V多的一个矩形波 求助
麻烦 问一下,心率是 怎么检测的呢很想只要, 可以做一个类似心电图的东西出来么...
没看到你在哪儿计的数呢
电路图可以贴出来看看吗?