我遇到的实际的问题是,当key_number==3时,能够开启计数器0进行计数,当key_number为3以外的其他数值时,都能关闭计数器0,而我想要的是当key_number==1时,关闭计数器0 ,停止计数,不知道我表达清楚了没有,头都大了
#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define lcd_date P0
sbit rs=P2^1;
sbit rw=P2^4;
sbit en=P2^2;
sbit diola=P2^5;
sbit psb=P2^0;//´®²¢ÐпØÖÆÑ¡Ôñ
sbit wela=P2^6;
sbit dula=P2^7;
sbit mai=P3^7;
uint read()
{
uchar t1,th1,th2;
uint val;
while(1)
{
th1=TH0;
t1=TL0;
th2=TH0;
if(th1==th2)
break;
}
val=th1*256+t1;
return val;
}
bit pushkey() //ÅжÏÊÇ·ñÓмü°´ÏÂ
{
P1=0xf0;
if(P1!=0xf0)
return (1);
else
return (0);
}
void key_scan()//¾ØÕóɨÃè
{
uchar keycode,p;
delay(20); // ÑÓʱÏû¶¶
if(P1!=0xf0)
{
P1=0xfe; //¼üÅÌɨÃèÂë³õÖµ£¬ÖðÁÐɨÃ裬P1.0=0,ɨÃèµÚ1ÁÐ
while(1)
{
keycode=P1; //¶Á³öÊý¾Ý£¬¿´ÊÇ·ñÔÚ´ËÐÐÉϵÄijÁа´¼ü±»°´ÏÂ
if((keycode&0xf0)!=0xf0)
break;// Èç¹ûɨÃèµ½°´Ïµļü£¬ÔòÍ˳ö
P1=_crol_(P1,1);//·ñÔò£¬×óÒÆ£¬É¨ÃèÏÂÒ»ÐÐ
}
while((pushkey())); //µÈ´ý°´¼üÊÍ·Å
for(p=0;p<16;p++)
{
if ( keycode==key16[p])
key_number=p; //ÓëÌØÕ÷Öµ¶Ô±ÈµÃÓëÄĸö¼ü°´ÏÂ
}
}
}
void main()
{
uchar i;
wela=0;
dula=0;
delay(10);
init();
TMOD=0x05;
TH0=0;
TL0=0;
while(1)
{
key_scan();
if(key_number==3)
{
TR0=1;//Æô¶¯¶¨Ê±Æ÷1£¬¼Æʱģʽ
jishu();
}
if(key_number==1)
{
TR0=0;//¹Ø±Õ¶¨Ê±Æ÷1£¬¼Æʱģʽ*/
}
}
}
#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define lcd_date P0
sbit rs=P2^1;
sbit rw=P2^4;
sbit en=P2^2;
sbit diola=P2^5;
sbit psb=P2^0;//´®²¢ÐпØÖÆÑ¡Ôñ
sbit wela=P2^6;
sbit dula=P2^7;
sbit mai=P3^7;
uint read()
{
uchar t1,th1,th2;
uint val;
while(1)
{
th1=TH0;
t1=TL0;
th2=TH0;
if(th1==th2)
break;
}
val=th1*256+t1;
return val;
}
bit pushkey() //ÅжÏÊÇ·ñÓмü°´ÏÂ
{
P1=0xf0;
if(P1!=0xf0)
return (1);
else
return (0);
}
void key_scan()//¾ØÕóɨÃè
{
uchar keycode,p;
delay(20); // ÑÓʱÏû¶¶
if(P1!=0xf0)
{
P1=0xfe; //¼üÅÌɨÃèÂë³õÖµ£¬ÖðÁÐɨÃ裬P1.0=0,ɨÃèµÚ1ÁÐ
while(1)
{
keycode=P1; //¶Á³öÊý¾Ý£¬¿´ÊÇ·ñÔÚ´ËÐÐÉϵÄijÁа´¼ü±»°´ÏÂ
if((keycode&0xf0)!=0xf0)
break;// Èç¹ûɨÃèµ½°´Ïµļü£¬ÔòÍ˳ö
P1=_crol_(P1,1);//·ñÔò£¬×óÒÆ£¬É¨ÃèÏÂÒ»ÐÐ
}
while((pushkey())); //µÈ´ý°´¼üÊÍ·Å
for(p=0;p<16;p++)
{
if ( keycode==key16[p])
key_number=p; //ÓëÌØÕ÷Öµ¶Ô±ÈµÃÓëÄĸö¼ü°´ÏÂ
}
}
}
void main()
{
uchar i;
wela=0;
dula=0;
delay(10);
init();
TMOD=0x05;
TH0=0;
TL0=0;
while(1)
{
key_scan();
if(key_number==3)
{
TR0=1;//Æô¶¯¶¨Ê±Æ÷1£¬¼Æʱģʽ
jishu();
}
if(key_number==1)
{
TR0=0;//¹Ø±Õ¶¨Ê±Æ÷1£¬¼Æʱģʽ*/
}
}
}