CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem SWITCH-command.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jjude



Joined: 12 Nov 2007
Posts: 37

View user's profile Send private message

Problem SWITCH-command.
PostPosted: Wed Dec 12, 2007 11:28 pm     Reply with quote

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)
.
.

------------------------------------------------------
void x_minus()
{
output_high(PIN_B6);
output_low(PIN_B5);
while((input(PIN_A7) == 1) && (data == data_new))
{
pulse();
}
output_low(PIN_B6);
return;
}
------------------------------------------------------
void pulse()
{
y=50000/x;
output_high(PIN_A2);
delay_us(viive);
output_low(PIN_A2);
delay_us(viive);
output_high(PIN_A2);
delay_us(viive);
output_low(PIN_A2);
delay_us(viive);
output_high(PIN_A2);
delay_us(viive);
output_low(PIN_A2);
data_new=input_b()&0x0f;
return;
}
------------------------------------------------------
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Dec 13, 2007 8:53 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group