Home > Back-end >  There is nothing wrong with Keil run the program, while judgement there only while judgement stateme
There is nothing wrong with Keil run the program, while judgement there only while judgement stateme

Time:09-21

I feel it should not be programming problems, because only num2 while statement and interrupt1 where used, and as long as the while statement num2 value limit under 256 is no problem, as long as one is greater than or equal to 256 couldn't enter the while statement, like 256 is the number of the problem, I've been don't understand,


#include
#include
# define KEYPORT P2
# define COM8255 XBYTE [0 x0003]
# define PB8255 XBYTE [0 x0001]
# define PA8255 XBYTE [0 x0000]
# define uchar unsigned char
Sbit line0=KEYPORT ^ 0;
Sbit, line1=KEYPORT ^ 1;
Sbit line2=KEYPORT ^ 2;
Sbit line3=KEYPORT ^ 3;
Led []={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92, 0 x82, 0 xf8, 0 x80, 0 x90};
Uchar money, n, num2;

Void inti ()
{
COM8255=0 x80;
TMOD=0 x00;
IE=0 x83;
IT0=1;
TH0=(65536-1)/256;
TL0=(65536-1) % 256;
TR0=1;
}



Bit iskeyinput ()
{
KEYPORT=0 x0f;
If ((KEYPORT& 0 x0f)==0 x0f)
return 0;
The else
return 1;
}




Uchar key_identify ()
{
Uchar linecode=0, rowcode=0;
uchar i;
Uchar scancode=0 xef;
for(i=0; i<4. I++)
{
KEYPORT=scancode;
If ((KEYPORT& 0 x0f)==0 x0f)
{
Rowcode++;
Scancode=scancode<1 | 1;
}
The else
{
If (line0==0) linecode=0;
If (, line1==0) linecode=4;
If (line2==0) linecode=8;
If (line3==0) linecode=12;
break;
}
}
Return linecode + rowcode + 1;
}




Void wait_key ()
{
While (1)
{
KEYPORT=0 x0f;
If ((KEYPORT& 0 x0f)==0 x0f)
break;
}
}


Void the count (uchar n)
{
If (n % 3==0)
Money=(n/3) * 2;
Else if (n % 3!=0)
Money=(n/3 + 1) * 2;
}


Void service_int () interrupt 0
{
PA8255=led [0];
PB8255=led [0];

}



Void the display (uchar money)
{
If (0 & lt;=money& & Money<=9)
PA8255=led [money];
If (9 & lt; Money& & Money
=99){

PA8255=led [10] money %;
PB8255=[10] money/led;
}
}



Void lh-zd () interrupt 1
{
TH0=(65536-1)/256;
TL0=(65536-1) % 256;
Num2 + +;
}


Int main ()
{
Unsigned int I;
Num2=0;
Inti ();
While (1)
{
while(! Iskeyinput (), if not press the//button, execute
{
While (num2 & gt;
=256){

PA8255=led [0];
PB8255=led [0];
Num2=0;

}
}
for(i=0; i<500; i++);
If (iskeyinput ())//button if press execute
{
N=key_identify ();
Wait_key ();
The count (n);
The display (money);
TH0=(65536-1)/256;
TL0=(65536-1) % 256;

}


}


}

CodePudding user response:

Uchar not 8 bit, said up to 0 ~ 255, greater than 256
  • Related