正文

网络基础课程设计,A/D转换(c代码)2006-03-19 22:34:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/11183.html

分享到:

/*****------ad.c-------******输入要求:输入二进制字符串,如1110011。*          尽量小于10,不然后面的图形无法显示***************************/#include<stdio.h>#include<graphics.h>#include<conio.h>#include<math.h>char str_num[100];void initgraphics(){    int gd=DETECT;    int gm;    initgraph(&gd,&gm,"d:\\language\\tc20\\bgi");    return;}void graph_xy(int len){    setfillstyle(SOLID_FILL,BLUE);    bar(0,20+len,635,220+len);    setcolor(WHITE);    line(100,30+len,100,200+len);    outtextxy(95,30+len,"\/");    outtextxy(100,30+len,"\\y");    outtextxy(90,130+len,"0");    line(25,125+len,600,125+len);    outtextxy(600,120+len,"\\");    outtextxy(593,125+len,"x\/");    setcolor(RED);    outtextxy(200,30,"manchester graph");    outtextxy(200,270,"sine  graph");    return;}void manchester_graph(int len,int y1,int y2,int count,int flag){    setcolor(WHITE);    if(flag==1)        outtextxy(len+10,60,"1");    else        outtextxy(len+10,60,"0");    setcolor(WHITE);    line(0+len,y1,25+len,y1);    line(25+len,y1,25+len,y2);    line(25+len,y2,50+len,y2);    if(str_num[count]==str_num[count-1])    {        setcolor(WHITE);        line(0+len,y1,len,y2);    }}void sine_graph(int len,int k,int flag){    double i;    setcolor(WHITE);    if(flag==1)        outtextxy(len+10,300,"1");    else        outtextxy(len+10,300,"0");    for(i=0;i<50;i+=0.001)    putpixel(i+len,(200+k*sin(6.28*i/50))+150,WHITE);    return;}int main(void){    int count=0;    int length=50;    int flag=0;    initgraphics();    graph_xy(0);    graph_xy(240);    printf("input your b_str_num(strlen<=10):");    gets(str_num);    while(str_num[count]!='\0')    {        switch(str_num[count])        {        case '0':            flag=0;            manchester_graph(length,100,75,count,flag);            sine_graph(length,10,flag);            length=length+50;            break;        case '1':            flag=1;            manchester_graph(length,75,100,count,flag);            sine_graph(length,50,flag);            length=length+50;            break;        default:            cleardevice();            outtextxy(200,200,"input error number!");            getch();            closegraph();            exit(8);        }        ++count;    }    getch();    closegraph();    return 0;}http://www.programfan.com/blog/article.asp?id=36

阅读(3490) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册