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
}
}
}
You must avoid to use Delay this maner, that is implemented intrinsicly on closed loop.
Another approach is perform a time slot, which releases program to keep runing.
+++
You want to check which bit in the byte is 0 and then display the position of those bits on 7 Segment display? If yes, what is the problem you are facing?
Post the full code so that it can be fixed.
#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);
}
}
}
}
Mention the problem area of the code. You said that another pin is forcing to read something again. Which pin is that. Point to that pin.
if(input(pin_A5))
{
delay_ms(20);
if(input(pin_A5))
{
rd_ipt=1;
goto start;
output_high(pin_E0);
}
}
Is the display() function called again. If yes, before goto start; set a flag and use this flag to execute display() function i.e., if(flag==1)//then don't execute display() if(flag == 0)display();
If that doesn't help then clearly explain step by step the flow of program needed so that program flow can be modified as needed.
This is more commonly known as Timeslicing....I want to know about this method please give some examples or explain the concept...
Other point : You must strongly avoid to use goto statement in C....input(pin_A5),by using goto statement...
mailus,
This is more commonly known as Timeslicing.
Basically, you must to use Interrupt handler to generate time base to slot each routine according its time requirements.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 while(TRUE) { 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; break; output_high(pin_E0); } } }
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?