这个小东西简单而好玩,可以做为单片机入门的一个课业设计。
将你的食指轻轻地放在传感器上,就能看到LED指示灯随着你的心跳而闪动,15秒钟以后,还能在数码管上显示你当前的心率。
核心部分在传感器上,这里用的是一套红外对管。
人体指尖的动脉比较发达,当动脉血管随心脏周期性收缩与舒张时,血管中的血液容积也会发生变化。
这时红外接收探头便能采集到的相应的光脉冲信号,经过去噪和放大后送到单片机,进行运算处理,便得到了心率数据。
笔者虽然不是自动化专业毕业,但是对单片机和PLC都有相当深入的了解。笔者毕业后从事产品设计,开发的第一款产品就是基于16位的80C196单片机来作为硬件平台;之后也接受过西门子S5与S7PLC的培训,并在某特高压工程中采用S5PLC作为控制系统硬件并开发相应的工程软件,所以笔者自信能为楼主解惑答疑!
采集部分的原理图
运算与显示部分的原理图
单片机代码
/*
Project: Measuring heart rate through fingertip
Copyright @ Rajendra Bhatt
January 18, 2011
PIC16F628A at 4.0 MHz external clock, MCLR enabled
*/
sbit IR_Tx at RA3_bit;
sbit DD0_Set at RA2_bit;
sbit DD1_Set at RA1_bit;
sbit DD2_Set at RA0_bit;
sbit start at RB7_bit;
unsigned short j, DD0, DD1, DD2, DD3;
unsigned short pulserate, pulsecount;
unsigned int i;
//-------------- Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0xC0;
case 1 : return 0xF9;
case 2 : return 0xA4;
case 3 : return 0xB0;
case 4 : return 0x99;
case 5 : return 0x92;
case 6 : return 0x82;
case 7 : return 0xF8;
case 8 : return 0x80;
case 9 : return 0x90;
} //case end
}
void delay_debounce(){
Delay_ms(300);
}
void delay_refresh(){
Delay_ms(5);
}
void countpulse(){
IR_Tx = 1;
delay_debounce();
delay_debounce();
TMR0=0;
Delay_ms(15000); // Delay 1 Sec
IR_Tx = 0;
pulsecount = TMR0;
pulserate = pulsecount*4;
}
void display(){
DD0 = pulserate%10;
DD0 = mask(DD0);
DD1 = (pulserate/10)%10;
DD1 = mask(DD1);
DD2 = pulserate/100;
DD2 = mask(DD2);
for (i = 0; i<=180*j; i++) {
DD0_Set = 0;
DD1_Set = 1;
DD2_Set = 1;
PORTB = DD0;
delay_refresh();
DD0_Set = 1;
DD1_Set = 0;
DD2_Set = 1;
PORTB = DD1;
delay_refresh();
DD0_Set = 1;
DD1_Set = 1;
DD2_Set = 0;
PORTB = DD2;
delay_refresh();
}
DD2_Set = 1;
}
void main() {
CMCON = 0x07; // Disable Comparators
TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P only
TRISB = 0b10000000; // RB7 input, rest output
OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 for counter mode
pulserate = 0;
j = 1;
display();
do {
if(!start){
delay_debounce();
countpulse();
j= 3;
display();
}
} while(1); // Infinite loop
}
HEX代码
:020000001B29BA
:100006002428C03083120313F0000800F930F000F2
:100016000800A430F0000800B030F0000800993065
:10002600F00008009230F00008008230F00008006E
:10003600F830F00008008030F00008009030F00042
:100046000800831203132A08003A031904282A0811
:10005600013A031909282A08023A03190C282A0822
:10006600033A03190F282A08043A031912282A0802
:10007600053A031915282A08063A031918282A08E2
:10008600073A03191B282A08083A03191E282A08C2
:08009600093A031921280800B2
:0E009E008312031321088A0020088200080044
:1000AC0083120313F8010830FC00700DF80D74086E
:1000BC00F80203186328F8070310F00DFC0B5B28FB
:0200CC0008002A
:1000CE00831203137008F100F0010830FC00710870
:1000DE00F40C03187628FC0B6F28F1010034031082
:1000EE007B28F40C0318F107F10CF00CFC0B7828AC
:0200FE000800F8
:100100000D3083120313FC00FB30FD00FD0B86282D
:0A011000FC0B862800000000080028
:10011A00043083120313FB000C30FC003330FD0063
:10012A00FD0B9528FC0B9528FB0B95280000000079
:02013A000800BB
:10013C004F208A110A128000840AA00A0319A10A0E
:08014C00F003031D9E280800CA
:100154008312031385158D208D2081019930FB00B6
:100164003130FC00A230FD00FD0BB628FC0BB62894
:10017400FB0BB628000085110108A3002308A20088
:0A018400A20D2210A20D22100800A7
:10018E000A3083120313F4002208F0005620780878
:10019E00F0007008A9007008AA0003207008A900DA
:1001AE000A30F4002208F00056200A30F4005620DF
:1001BE007808F0007008A8007008AA0003207008E4
:1001CE00A8006430F4002208F00056207008A60043
:1001DE007008AA0003207008A600A401A501270834
:1001EE00F000B430F400672025087102031D0129C8
:1001FE0024087002031C19290511851405142908F9
:10020E00860080200515851005142808860080209C
:10021E00051585140510260886008020A40A0319EA
:08022E00A50AF62805140800DA
:100236000730831203139F00303083168500803009
:100246008600283081008312A2010130A700C72052
:10025600861B32298D20AA200330A700C7202B2910
:0202660033293A
:02400E006A2125
:00000001FF
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
调光控制输出电路最终是要控制远近灯的切换。而单片机的工作电压一般是在5V甚至更低,电流也是毫安级别的,是无法直接驱动远近灯光的切换的。因此本系统采用继电器驱动作为功率驱动。具体的控制电路如图4所示。