#include <conio.h>
#include <stdio.h>
int main()
{
printf("请输入:")
char ch
ch = getch()
if(ch == -32)
while(1)
{
ch = getch()
switch(ch)
{
case 27:
{printf("Esc")return 0} //按esc退出
case 72:
{printf("A")break}
case 80:
{printf("B")break}
default:
break
}
}
}
主要就是按键检测,防抖呗。首先给出检测按键代码:(我这个事4*4键盘。具体你要根据实际情况编写)
uchar TestKey()
{
uchar cord_h,cord_l
P6=0x0f
cord_h=P6&0x0f
if(cord_h!=0x0f)
{
Delay_Xms(1)
if(cord_h!=0x0f)
{
cord_h=P6&0x0f
P6=cord_h|0xf0
cord_l=P6&0xf0
return(cord_h+cord_l)
}
}return(0xff)
}
--------------------------------------
然后你在Main函数里编写循环,检测按键然后做你想做的事情。。。
while(1)
{
key=TestKey()//调用键盘扫描,
switch(key)
{
case 0x7e:P4=0xa1break//0 按下相应的键显示相对应的码值
case 0x7d:Show1Menu()break//1
case 0x7b:P4=0x83break//2
case 0x77:P4=0x88break//3
case 0xbe:P4=0x99break//4
case 0xbd:P4=0x90break//5
case 0xbb:P4=0x82break//6
case 0xb7:P4=0xb0break//7
case 0xde:P4=0xc0break//8
case 0xdd:P4=0x80break//9
case 0xdb:P4=0x92break//a
case 0xd7:P4=0xa4break//b
case 0xee:P4=0xc6break//c
case 0xed:P4=0xf8break//d
case 0xeb:P4=0x99break//e
case 0xe7:P4=0xf9break//f
}
}
#include <stdio.h>void main()
{
int a,c
char flag='y'
float b,z=0
while(flag=='y'||flag=='Y'){
printf("输入工资(元):")
scanf("%d",&a)
b=a-2000
if(b<=500)
c=1
else
if(b<=2000)
c=2
else
if(b<=5000)
c=3
else
if(b<=20000)
c=4
else
if(b<=40000)
c=5
else
if(b<=60000)
c=6
else
if(b<=80000)
c=7
else
if(b<=100000)
c=8
else
if(b<=9998000)
c=9
switch(c)
{
case 1:z=b*0.05break
case 2:z=b*0.10-25break
case 3:z=b*0.15-125break
case 4:z=b*0.20-375break
case 5:z=b*0.25-1375break
case 6:z=b*0.30-3375break
case 7:z=b*0.35-6375break
case 8:z=b*0.40-10375break
case 9:z=b*0.45-15375break
}
printf("应缴税为:%f\n",z)
printf("要继续输入?:(Y\\N)\n")
scanf(" %c",&flag)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)