romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
if(input != 255) //when any of the switch is pressed
store = input
return store;
unsigned char pollButtons(void)
{
static unsigned char store;
unsigned char sinput;
sinput = input; // Basically a shadow register see comment below
if(sinput != 255)
{
store = sinput;
}
return store;
}
void main(void)
{
unsigned char state;
while(1)
{
pollButtons(&state);
}
}
void pollButtons(unsigned char * store)
{
unsigned char sinput;
sinput = input; // prevents the value of input from changing during the loop test and the assignment statement;
if(sinput != 255)
{
*store = sinput;
}
}
void main()
{
while(1)
{
PORTB = get_inputDATA();
}
}
unsigned char get_inputDATA()
{
int i,data;
SPI_InLatch = 1; //load data
SPI_InLatch = 0;
SPI_PLOAD = 0;
SPI_PLOAD = 1;
for (i=7; i>=0; i--)
{
if(SPI_SI)
data |= (1 << i); //store data received
toogle_clock();
}
return data;
}
if(input != 255) //when any of the switch is pressed
store = input
return store;
I think I got it.. I need not to always called it in a supper loop but I will just detect if any key is press...
void main()
{
unsigned char switchstate = 0xFF;
while(1)
{
switchstate = get_inputDATA();
if(switchstate != 0xFF)
PORTB = switchstate;
}
}
still not working.. Is there a switch bounce in proteus?
what is the new value that you get when the stored data gets lost, you press a specific button and the value gets stored, when the data is lost as you say without pressing any other button what is the new value that is assigned because it is surely different from 255 since it can pass the condition if(input != 255).
unsigned char get_inputDATA()
{
int i,data;
SPI_InLatch = 1; //load data
SPI_InLatch = 0;
SPI_PLOAD = 0;
SPI_PLOAD = 1;
for (i=7; i>=0; i--)
{
if(SPI_SI)
data |= (1 << i); //store data received
toogle_clock();
}
if(input != 255) //when any of the switch is pressed
store = input
return store;
}
PORTB = get_inputDATA()
int get_inputDATA()
{
int data = 0,i;
SPI_InLatch = 1; //load data
SPI_InLatch = 0;
SPI_PLOAD = 0;
SPI_PLOAD = 1;
for (i=7; i>=0; i--)
{
if(SPI_SI)
data |= (1 << i); //store data received
toogle_clock();
}
//return data;
if(data != 255)
store = data;
return store;
}
void toogle_clock()
{
SPI_Clk = 1;
delayms(2);
SPI_Clk = 0;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?