|  | 
 
| /******************************************************************** 汇诚科技
 网址:http://www.ourhc.cn
 产品有售淘宝店:http://shop36330473.taobao.com
 *********************************************************************/
 #include<reg52.h>                 //库文件
 #define uchar unsigned char//宏定义无符号字符型
 #define uint unsigned int  //宏定义无符号整型
 /********************************************************************
 初始定义
 *********************************************************************/
 uchar count;   //按键计数,每按一下,count 加1
 uchar a,b;           //定义字符型变量
 uchar temp;    //定义字符型变量
 sbit BY1=P2^1; //定义按键的输入端(为单片机P2口的P2.1按键)
 /********************************************************************
 延时函数
 *********************************************************************/
 void delay10ms(void) //延时程序
 {
 uchar i,j;
 for(i=20;i>0;i--)
 for(j=248;j>0;j--);
 }
 /********************************************************************
 按键判断函数
 *********************************************************************/
 void key() //按键判断程序
 {
 if(BY1==0) //判断是否按下键盘
 {
 delay10ms(); //延时,软件去干扰
 if(BY1==0) //确认按键按下
 {
 count++; //按键计数加1
 if(count==8) //计8次重新计数
 {
 count=0;//将count 清零
 }
 }
 while(BY1==0);//按键锁定,每按一次count 只加1.
 }
 }
 /********************************************************************
 主函数
 *********************************************************************/
 void main()
 {
 temp=0xfe; //定义为11111110
 while(1)
 {
 key(); //调用按键判断函数
 a=temp<<count;//左移count位
 b=temp>>(8-count);//右移8-count位
 P0=a|b;        //求值
 }
 }
 
 /********************************************************************
 结束
 *********************************************************************/
 
 
 
 | 
 |