我的 switch程序运行不正常 求教!!!!!!!!!!
我的程序运行不正常,求教!!!!!!!!!!
#include <reg51.h>
#include "math.h"
#include "stdlib.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
uchar contenty,key_data,key;
uchar r_key(uchar contenty);
/********************************************
* 读键函数
* 返回键值 key_data
*********************************************/
uchar r_key(uchar contenty)
{
switch(contenty)
{
case 0 :key = 0 ;
key_data=key;
key = 1;
break;
case 1 :key = 0;
key_data=key+key;
key = 1;
break;
case 2 :key = 0 ;
key_data=key+key+key;
key = 1;
break;
case 3 :key = 0 ;
key_data=key+key+key+key;
key = 1;
break;
default:key = 1; }
return(key_data);
}
/********************************************
* 主函数
* 返回键值
*********************************************/
void main()
{ while(1){
r_key(1);
}
}
我的程序运行不正常,求教!!!!!!!!!!
行首有 的是实际运行。
程序在执行了 case 1 :key = 0;
key_data=key+key;
跳过了key=1;去执行break;并且执行了switch结构中的default:key = 1; 才退出switch结构
[/size][/size]
发表时间:2007年4月10日21:32:24