编程按动说话

2023-12-10 10:05:23 数码极客 bianji01

 

下面的C语言编程怎么理解,麻烦补一下释义!!!

软件的编程要与硬件相关的。程序大概意思是:单片机的P0、P1端口与开关K1、K2相连接。声明了一个延时函数和一个按键扫描函数。while里面采用循环扫描形式。比较耗费单片机。好的方法是采用中断形式。。。while里面采用延时消抖的方法(按键按下是实际上开关接触点是轻微震荡的接触)。监测到按键后(scan_key();),延时一段时间(delayms()),再次检测按键(调用scan_key();),即延时消抖。如果这两次都检测到按键。才说明有按键按下。之后调用proc_key(key_v);函数就行功能处理。即根据是K1、K2来判断是执行循环左移还是循环右移。

本回答由提问者推荐

一道C语言编程题

我最近写了一个图书管理程序,和你这个差不多,你可以稍微修改就可以使用,不过我用的是链表的方式来完成的。程序如下:

#include

#include

#include

#defineNULL0

#definefilename"lib.dat"

charshowmain();/*显示系统菜单*/

voiddaTAinput(structNode*head);/*图书数据的输入*/

voidshowdata(structNode*head);/*图书数据的显示*/

voidshownode(structNode*p);/*单个数据节点的显示*/

voiddelnode(structNode*p);

voidsavedata(structNode*head);

voidloaddata(structNode*head);

voidsortdata(structNode*head);

voidfreedata(structNode*head);

voiddeldata(structNode*head);

voidmodifydata(structNode*head);

structNode

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

structNode*next;/*指向数据节点的指针*/

voidmain()

structNode*head,*tail;

intnum;

charanswer;

head->next=NULL;

head=(structNode*)malloc(sizeof(structNode));/*给节点分配内存,并通过head指向*/

tail=(structNode*)malloc(sizeof(structNode));/*给节点分配内存,并通过tail指向*/

head->next=tail;

tail->next=NULL;/*建立head和tail的关系并将tail指向空节点*/

head->id=0;

loaddata(head);

answer=showmain();

while(answer!=q)

switch(answer)

case1:showdata(head);

printf("pressanykeytocontinue\n");

getch();

break;

case2:datainput(head);break;

case3:modifydata(head);break;

case4:deldata(head);break;

case5:sortdata(head);break;

case6:savedata(head);break;

answer=showmain();

}/*主界面的运行程序*/

printf("youaregoingtoquitsystem\n");

printf("doyouwanttosaveY/N\n");

answer=getch();

if(answer=y)savedata(head);

freedata(head);

charshowmain()

charoutchar;

clrscr(0);

system("cls");

printf("\n==========welcometouselibsystem=================\n");

printf("==\n");

printf("=1show=\n");

printf("=2add=\n");

printf("=3modify=\n");

printf("=4del=\n");

printf("=5sort=\n");

printf("=6save=\n");

printf("=qquit=\n");

printf("\n");

printf("====================================================\n");

outchar=getch();

returnoutchar;

voidloaddata(structNode*head)

FILE*fp;

structNode*p;

inti,num;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

p=head->next;

if((fp=fopen(filename,"r"))==NULL)

printf(filename);

printf("cantbeopen.\n");

getch();

fscanf(fp,"%d",&num);

head->id=num;

for(i=0;i

p=(structNode*)malloc(sizeof(structNode));/*申请一个新的节点*/

fscanf(fp,"%d",&id);

fscanf(fp,"%s",&bname);

fscanf(fp,"%s",&wname);

fscanf(fp,"%s",&pname);

fscanf(fp,"%f",&price);

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

p->next=head->next;

head->next=p;/*将新的节点插入链表当中*/

fclose(fp);

/*显示数据*/

voidshowdata(structNode*head)

structNode*p;

p=head->next;

clrscr(0);

system("cls");

printf("====showingdatainlibsystem======\n\n");

printf("format:id|bookname|writer|publishment|price\n");

if(p->next==NULL)printf("nodatainlib\n");

printf("\n");

while(p->next!=NULL)/*当链表没有达到尾部时则输出数据*/

shownode(p);/*显示单个节点的数据*/

p=p->next;

/*显示单个节点的数据*/

voidshownode(structNode*p)

intlen,i;

printf("%5d)",p->id);

printf("%s",p->bname);

len=strlen(p->bname);

for(i=0;i<(16-len);i++)printf("");

printf("%s",p->wname);

len=strlen(p->wname);

for(i=0;i<(16-len);i++)printf("");

printf("%s",p->pname);

len=strlen(p->pname);

for(i=0;i<(16-len);i++)printf("");

printf("%1f",p->price);

printf("\n");

/*数据输入,添加*/

voiddatainput(structNode*head)

structNode*p;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

charanswer=;

clrscr(0);

system("sys");

printf("===========inputdatatolibsystem=============\n\n");

while(answer!=q)

p=(structNode*)malloc(sizeof(structNode));/*申请一个新的节点*/

printf("pleaseinputidofbook:");

scanf("%d",&id);

printf("\npleaseinputbookname:");

scanf("%s",&bname);

printf("\npleaseinputwriter:");

scanf("%s",&wname);

printf("\npleaseinputpublishment:");

scanf("%s",&pname);

printf("\npleaseinputprice:");

scanf("%f",&price);/*得到图书相应的数据*/

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

p->next=head->next;

head->next=p;/*将新的节点插入链表当中*/

printf("\npressanykeytocontinetoadd,qtobacktomain\n");

answer=getch();

voidmodifydata(structNode*head)

intnum;

structNode*p;

charanswer;

intid;/*编号*/

charbname[16];/*名称*/

charwname[16];/*图书作者*/

charpname[16];/*出版社名称*/

floatprice;/*图书价格*/

clrscr(0);

system("cls");

showdata(head);

printf("===========inputdatatolibsystem=============\n\n");

printf("whichbook(id)doyouwanttomodify:");

scanf("%d",&num);

p=head->next;

while(p->next!=NULL)

if(p->id==num)

printf("pleaseinputidofbook:");

scanf("%d",&id);

printf("\npleaseinputbookname:");

scanf("%s",&bname);

printf("\npleaseinputwriter:");

scanf("%s",&wname);

printf("\npleaseinputpublishment:");

scanf("%s",&pname);

printf("\npleaseinputprice:");

scanf("%f",&price);/*得到图书相应的数据*/

p->id=id;

stpcpy(p->bname,bname);

stpcpy(p->wname,wname);

stpcpy(p->pname,pname);

p->price=price;/*将数据拷贝到节点上*/

break;

p=p->next;

if(p->next==NULL)

printf("cantfindthebookpressanykeytocontinue");

getch();

showdata(head);

printf("pressanykeytocontinue");

getch();

voiddelnode(structNode*p)

structNode*p1,*temp;

temp=p->next;

p1=temp->next;

p->next=p1;

free(temp);

voiddeldata(structNode*head)

intnum;

structNode*p0,*p1;

charanswer;

clrscr(0);

system("cles");

showdata(head);

printf("whichbook(id)doyouwantdelete:");

scanf("%d",&num);

p0=head;

p1=head->next;

while(p1->next!=NULL)

if(p1->id==num)

printf("doyoureallywanttodelete%d,n>:",num);

answer=getch();

if(answer==y)delnode(p0);

break;

p1=p1->next;

p0=p0->next;

if(p1->next==NULL)

printf("cantfindthebookpressanykeytocontinue");

getch();

showdata(head);

printf("\n

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告