i have difficulty in programming with delays and 7 segment display routines;
now my doubt is,
i have data(in bytes) in a variable, i need to check the location of bit(from byte mentioned) which is zero. then i need to display in a single seven segment display(1~8). here i use for loop and bit manipulation function to find the location,on the same time i need to display which location is zero.for this i use delay function in for loop.how to avoid this delay function in for loop and the same time display the output
i put my code here:
problems in my code:
"The goto and continue keywords shall not be used. The break keyword shall not be used outside
of a switch statement. These keywords lead to spaghetti code."
"i have implemented delay in a closed loop so it make my code to too lazy one,so controller wait some time until the closed loop has to complete"
so i keep on searching i found that RTOS concept.
that means time slicing or time slot method by using cooperative tasking and round-robin technique.is this technique suitable for my problem?
please give some solution to solve this problem
now my doubt is,
i have data(in bytes) in a variable, i need to check the location of bit(from byte mentioned) which is zero. then i need to display in a single seven segment display(1~8). here i use for loop and bit manipulation function to find the location,on the same time i need to display which location is zero.for this i use delay function in for loop.how to avoid this delay function in for loop and the same time display the output
i put my code here:
Rich (BB code):
#include <16f877a.h>
#fuses HS,PUT,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=4000000)
#define crystal 4000000
#define time 750
#define relay_time 500
#define debounce 50
unsigned int8 curr_ipt=0xff,i,sli=0,temp=0;
int1 rd_ipt=1;
int conv(unsigned int8 data) //function with return value
{
switch(data) //return the converted data to display in the 7-segment
{
case 1:
return(0xf9);
break;
case 2:
return(0xa4);
break;
case 3:
return(0xb0);
break;
case 4:
return(0x99);
break;
case 5:
return(0x92);
break;
case 6:
return(0x82);
break;
case 7:
return(0xf8);
break;
case 8:
return(0x80);
break;
case 9:
return(0x90);
break;
default:
return(0xff);
break;
}
}
void output()
{
if((curr_ipt==0xff) && sliver==1) //if all pins in portc is high
{
output_low(pin_A1);
output_low(pin_A2);
output_high(pin_A3); //relay,error_led signal are low and ready signal is high
delay_ms(relay_time);
} else if((curr_ipt!=0xff) || sliver==0) //any of the input is low
{
rd_ipt=0;
output_high(pin_A1);
output_high(pin_A2);
output_low(pin_A3); //relay,error_led signal are high and ready signal is low
delay_ms(relay_time);
}
}
void display()
{
if(curr_ipt!=0xff) //check input if any change enter loop
{
for(i=0;i<=7;i++)
{
if((curr_ipt &(1<<i))==0) //for each value of i bit location is change to ith location
{ //if any particular bit is zero means enter
delay_ms(debounce); //debounce time
if((curr_ipt &(1<<i))==0) //check again if still bit 0
{
temp=i; //save the location i in temp variable
output_B(conv(temp+1)); //call function "conv" and display in the portB
delay_ms(time); //time for display the content
}
}
}
}
if(sli==0) //if sli input is zero means enter here
{
delay_ms(debounce); //debounce time
if(sli==0) //check again still input is zero enter
{
output_b((conv(9))); //call fn"conv" and display digit '9' on display
delay_ms(time);
}
}
if((curr_ipt==0xff) && sli==1) //if all inputs are high display empty
{
output_b((conv(0)));
}
}
void main()
{
while(TRUE)
{
start:
if(rd_ipt==1) //read port when rd_ipt is enabled
{
curr_ipt=input_c(); //assign port c value to variable curr_ipt
sli=input(pin_a0);
}
output(); //call output function
display(); //call display function
if(input(pin_A5))
{
delay_ms(20);
if(input(pin_A5))
{
rd_ipt=1;
goto start;
output_high(pin_E0);
}
}
}
}
"The goto and continue keywords shall not be used. The break keyword shall not be used outside
of a switch statement. These keywords lead to spaghetti code."
"i have implemented delay in a closed loop so it make my code to too lazy one,so controller wait some time until the closed loop has to complete"
so i keep on searching i found that RTOS concept.
that means time slicing or time slot method by using cooperative tasking and round-robin technique.is this technique suitable for my problem?
please give some solution to solve this problem