PDA

View Full Version : c/c++ : electrocardiogram data acquisition


FunZooL
04-08-03, 03:44 PM
akum sume

ermmm camni... funzool nak wat program yg acquire data (ecg signal) dari rs-232(serial) thru comm port 2 n then plot graf ecg tuh. dah compile n debug, tapi still tabley nak debug sampai tade error. dah fenin dah. ada sesape bley tulun cekkan tak? stakat ni ada 5 error remaining... kat bawah funzool ada tunjuk katne error tu occur... thanx in advance. jenis compiler = turbo c 3.0


#include stdio.h
#include stdlib.h
#include conio.h
#include Time.h
#include iostream.h
#include string.h
#include graphics.h
#include dos.h
#include alloc.h
#include limits.h

int main(void);
void wake_ad(void);
int get_ad(void);
void sleep_ad(void);
void delay_time(float wait);
void MicroDelay(long MicroSecs);
void PlotData(float ad_value);

static unsigned int MSR=0X3FE;
static unsigned int MCR=0X3FC;
FILE *fp;
char ecg_record[80];
char f_name[100];
char e_reply[1];
float adjustment=2.5;

#define SCLK 1
#define CS 2

enum {w320h200, w640h480, w800h600, w1024h768, w1280h1024} BGI256Mode;

int main(void)
{
unsigned long k;
int gdriver, gmode=w640h480;
float ad_value;

float I=10, M[10];
unsigned int b=0, n=1;

randomize();

label_top:
char y[]="";

printf("Enter file name:\n");
scanf("%s",ecg_record);
strcat(ecg_record,".txt");
fp=fopen(ecg_record,"w+t");

printf("Press any key to start recording ECG data:\n");
scanf("%s",e_reply);

if(stricmp(e_reply,y)>0)
{

cout<<clock()/CLK_TCK<<"*";

gdriver=installuserdriver("BGI256v2",NULL);

initgraph(&gdriver,&gmode,"");

moveto(0,240);
wake_ad();

for (k=1;k<15001;k++)
{
ad_value=get_ad();
ad_value=(ad_value*5)/4095;

M[I]=ad_value;

if(I==0)
{
I=20;
}
else
{
I=I=1;
}
if(b<10)
{
M[I]=0;
}

ad_value=ad_value-M[I];

PlotData(ad_value);

fprintf(fp, "%.3f\t%.3f\t%.3f\n",ad_value,ad_value,ad_value);

b++;
n++;
}

sleep_ad();
closegraph();

fclose(fp);

cout<<clock()/CLK_TCK;

printf("-A/D converter is done and now sleeping\n");
printf("Press 'q' to quit or any other key to for\n");
printf("another sample...\n\n\n");

while(!kbhit());

if(getch()=='q')
{
printf("good day\n");
delay(300);
return(0);
}
else
{
goto label_top;
}
}

return(0);
}

void wake_ad()
{
outportb(MCR,SCLK);
return;
}

int get_ad()
{
int ad_result,i,j;
void delay_time(float wait);

MicroDelay(400);
outportb(MCR,SCLK+CS);

while((inp(MSR)&32)!=0)

ad_result=0;
for(i=1;i<=12;i++)
{
MicroDelay(135);
outportb(MCR,CS);
MicroDelay(135);
outportb(MCR,CS+SCLK);

MicroDelay(135);

if((inp(MSR)&32)==0)
{
ad_result += 0;
{
else //<--KAT SINI ADA ERROR (MISPLACED ELSE)
{
ad_result += 1;
}
ad_result=ad_result<<1;
}

outportb(MCR,SCLK);
ad_result=ad_result>>1;

return(ad_result);
}

void sleep_ad()
{ //<-- ERROR KAT SINI GAK (DECLARATION SYNTAX ERROR)
outportb(MCR,0);
}

void MicroDelay(long MicroSecs)
{
asm
{
mov cx, word ptr [MicroSecs+2]
mov dx, word ptr [MicroSecs]
mov ah, 0x86
int 0x15
}
}

void PlotData(float ad_value)
{
static int ls=0,le=20,li=10;
int x,y;
x=getx();
y=gety();
setviewport(0,0,639,479,0);
moveto(x,y);

x=getx();
y=gety();
setviewport(0,120,639,360,1);
setfillstyle(SOLID_FILL,0);
if(x>637)
{
x=0;
bar(0,0,2,240);
}
else
{
bar(x+1,0,x+2,240);
}

setcolor(4);
line(0,0,639,0);
line(0,240,639,240);
line(0,120,639,120);
setcolor(11);
line(x+3,ls,x+3,le);
ls=le;
if((le<=0) || (le>=240))

li=-li;
le+=li;
setcolor(10);
moveto(x,y);
lineto(x+1,-((ad_value-adjustment)*18)+120);
} <--// ERROR KAT SINI (DECLARATION MISSING ; )

FunZooL
04-08-03, 10:15 PM
huhuhuh sedeynyer.. tade org bley tulun ke... :uwaa:

KrisEmas
05-08-03, 06:32 AM
try to match the "{"..."}" carefully and you'll see the problem.

Hint: check the "}" for the "if" before the first "else" error.