|
[code=C/C++]
INT8U key, lastkey;
INT8U err;
INT32U root,a,b,n;
char str[33];
INT32U sum=0;
int times=0;
for (;;) {
if (PC_GetKey(&key)==TRUE){
if(key==0x1B)PC_DOSReturn();
if(key>47&&key<58&×<11||key==8){
if(times==0){
PC_DispStr(27,5," ",DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr(26,6," ",DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
}
if(key!=8){
++times;
PC_DispChar(27+times,5,key,DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
sum=sum*10+key-48;
lastkey=key;
}
if(key==8&×>0){
PC_DispChar(27+times,5,'',DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
sum=(sum-lastkey+48)/10;
times-=1;
}
}
}
if(key==13){
PC_DispStr(5,6,"Result Of The Number:",DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
if(times==0){
PC_DispStr(26,6," ",DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
PC_DispStr(27,5," ",DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
}
a=3;n=2;
for(;a<=sum;a+=2){
OSSemPend(FuncSem,0,&err);
root=(INT32U)sqrt((double)a);
OSSemPost(FuncSem);
for(b=3;;){
if(a%b==0)break;
b+=2;
if(b>root){++n;break;}
}
}
if(sum==1||sum==2)n-=1;
if(sum==0)n=0;
OSSemPend(FuncSem,0,&err);
ultoa(n, str, 10);
OSSemPost(FuncSem);
PC_DispStr(29,6,str,DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
sum=0;times=0;
}
}
[/code]
Take the example written in my junior year: prime number calculation in uC/OS-II environment. You don't need to understand it in detail. The effect is that you enter a non-number and do not respond. The PC_GetKey() function directly stores the key into the actual parameter. |
|