This is not absolute my code, but example my problem.
This code not work very good. If data change, code not run new "case".
I use fast_io. Data input B3-B0-pin.
----------------------------------------------------
void main()
{
.
.
.
data=input_b()&0x0f;
while(data != 0) //
{
data=input_b()&0x0f;
switch (data)
{
case 0b1101:
{
.
.
data_new=data;
x_minus();
break;
}
case 0b1011:
{
.
.
data_new=data;
x_plus();
break;
}
case 0b0111: // Eteen, ei kaasua
{
.
.
break;
}
case 0b1111:
{
.
.
break;
}
}
}
}
---------------------------------------------
But if i add delay, code work but slow.
.
.
data=input_b()&0x0f;
delay_ms(1000); // I add this.
switch (data)
.
.
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Thu Dec 13, 2007 8:53 am
What is connected to your data input pins B0-B3? Are these (keyboard) switches?
If yes, then that's your problem. Switches can bounce (open and close) for as long as 20ms before reaching a stable new state, that's why you need debouncing hardware or software routines. More good info can be found in the thread http://www.ccsinfo.com/forum/viewtopic.php?t=32166.
In case you have a keyboard matrix connected a debounce function is provided in the file KBD.C in the driver directory of your CCS compiler.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum