Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] need help in develop decimal point logic in seven segment

Status
Not open for further replies.
hi thanx alexan sir good help on interrupt i have to ask one more thing you suggested me below logic for three seven segment
Code:
scale/1000; // this is the first digit
(scale % 1000)/100; // this is the second digit
(scale % 100)/10; // this is the decimal

what should be logic for four seven segment display??
 

Asking me this question means that you don't understand how the code works

I'm using two operators, the division (/) and modulo (%)
When you divide two integers then the result is also an integer and the decimal digits are truncated so if you divide 100/9=11.11 you get a result of 11.
When you divide 9/10=0.9 you get a result of 0 , when you divide 10/4=2.5 you get a result of 2

The modulo, when you use it you get the remainder of the division.
10%4=2 , because 10/4=2 times and the remainder is 2 ( 10-(2*4)=2)
20%3=2 , because 20/3=6 times and the remainder is 2 (20-(3*6)=2)

Now using all that suppose that we have a decimal number like 1234

1234/1000=1.234 which gets truncated to 1 and you get the first digit

1234%1000=234 and 234/100=2.34 which gets truncated to 2 so (1234%1000)/100=2 gives you the second digit

1234%100=34 and 34/10=3.4 which gets truncated to 3 so (1234%100)/10=3 gives you the third digit

1234%10=4 , this time you don't need to do a division so (1234%10)=4 gives you the fourth digit

Alex
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
yes sir i don't have idea about that logic before now after your explanation i understand that very well thank you so much for your kind and informative reply for beginner in c like me.
 

still confuse in using two different interrupts in same code with same ISR vactor?
 

still confuse in using two different interrupts in same code with same ISR vactor?

I don't think you can do that , you mean having two ADC interrupts or two timer0 overflow interrupts ?
 

no alexan sir i am already using timer0 overflow interrupt i want to use timer1 or timer2 as second overflow interrupt i already wrote
Code:
void init_Ex2(void)
{

TIMSK|=(1<<TOIE1); // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0000; // 16bit counter register
TCCR1B = 0x03; // start timer/ set clock
sei();//Enable Global Interrupts

}
this is initialization function
Code:
ISR(TIMER1_OVF_vect) {
	 
if(!(PINC&(1<<PINC1))&&(PINC&(1<<PINC2))){PORTB=(1<<PB0);SEVEN_SEGMENT_PORT=values[10];}


}
but above isr routine not executed when switch is pressed.i have doubt that timer1 interrupt not turn on that why this ISR routine not executed.
 

Your initialization is correct, are you sure that you are not getting the interrupt?
Maybe the condition inside the interrupt is never true.
Maybe you are executing another interrupt which takes too much time and this one is delayed.
 

i am not to sure about that interrupt is get or not but my condition met true then also not showing the desire action my other interrupt is timer0 overflow
Code:
void init_Ex1(void)
{


     TCCR0=0x02;   // Prescaler = FCPU/1024

     TIMSK|=(1<<TOIE0); //Enable Overflow Interrupt Enable
 
     TCNT0=0; //Initialize Counter
	 sei();//Enable Global Interrupts

}

isr routine
Code:
ISR(TIMER0_OVF_vect) //ISR rutine for sevensegment

{
          
		  	
		var1=scale;


    if (show_digit==0) 
	{
		// write code to show digit 1
        
	num1=scale%10; // this is the first digit

   PORTB=(0<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(1<<PB4);       	// Turning ON Units place of display
   SEVEN_SEGMENT_PORT=values[num1];	// Writing corresponding number on Units place 	

 //  _delay_us(450);//rt delay


    }
    else if (show_digit==1)   
	 {
		// write code to show digit 2
		num2=(scale % 100)/10 ;
	
        PORTB=(0<<PB0)|(0<<PB1)|(0<<PB2)|(1<<PB3)|(0<<PB4);	  // Turning ON Tens place and Turning OFF Units place of seconds 
  
       SEVEN_SEGMENT_PORT=values[num2]+0x80;		// Writing corresponding number on Tens place 

     //  _delay_us(450);// Short delay

    }
    else if (show_digit==2)   
	 {
		// write code to show digit 3
	num3=(scale % 1000)/100;
            
		PORTB=(0<<PB0)|(0<<PB1)|(1<<PB2)|(0<<PB3)|(0<<PB4);	           // Turning ON Units place of minutes      // Turning ON Units place of minutes
       SEVEN_SEGMENT_PORT=values[num3];			// Writing corresponding number on Units place of minutes
     //  _delay_us(450);
	

    }
	else if (show_digit==3)//&&(!(PINC&(1<<PINC1))))
	{
	    
	   	
   PORTB=(0<<PB0)|(1<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4); 	           // Turning ON Units place of minutes
	           // Turning ON Tens place and Turning OFF Units place of minutes
        num4=scale/1000;
   SEVEN_SEGMENT_PORT=values[num4];			// Writing corresponding number on Tens place of minutes
  // _delay_us(450);//
	
	}

   else if (show_digit==4) 
   //show_digit=0;  // after showing the third digit restart
   {
               
    PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=values[0];

    

	
	

	

}

  if(++show_digit==5) show_digit=0;

  

  }

this routine works fine but not getting result in timer1 interrupt.
 

the timer0 overflow if fine.
Are you sure that the timer1 overflow is not executed?
How do you check it, did you use a breakpoint while debugging?

---------- Post added at 13:03 ---------- Previous post was at 13:01 ----------

Can you post the complete code here so I can test it in the debugger of AVR studio?
 

i am simulating in Proteus i am attaching my code here
 

Attachments

  • hardness.rar
    19.8 KB · Views: 118

Yes, I'm not getting an interrupt either but I can't figure out what is wrong, I'll check it again later.
 

ok thank you sir
 

You tricked me becasue the code in your previous post was correct ISR(TIMER1_OVF_vect) but in the attached file you have used ISR(TIMER1_OVF1_vect).
I didn't check this the second time because I thought it was correct.
Anyway change it and the code works fine.

You are also using sei(); three times, one in each initialization and a third time after them, there is no point in that, use it just once after the all initializations are finished.
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
no sir i don't mean to trick you i changed that but forget to save that file may be that why showing ISR(TIMER1_OVF1_vect). but i don't understand why it wont support all avrs?


I changed ISR(TIMER1_OVF1_vect). to ISR(TIMER1_OVF_vect).
but it wont change the first character when switch is pressed.
 
Last edited:

There is a list of interrupt vectors in the header file of your microcontroller, you can find it in the have include folder in AVRstudio (left side panel), check the names there.

The interrupt is working fine now so there is something wrong with the condition you use inside it.
 

i am having problem in might be switch condition but i guess i am checking the condition in right way only deb ounce logic is not added
Code:
if(!(PINC&(1<<PINC1))&&(PINC&(1<<PINC2)))//this condition for switch pressed at PinC1
else if(!(PINC&(1<<PINC2))&&(PINC&(1<<PINC1)))//this condition is for switch pressed at PINC2

and i am getting same condition for different scaling factor.so what is wrong in ISR(TIMER1_OVF_vect)

any other logic to check switch input as logic zero on respected pin
 

You can use a simple macro https://www.edaboard.com/blog/861/



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
 
ISR(TIMER1_OVF_vect) {
    if(!CHECKBIT(PINC,1))
    {
        // PINC1 state is 0 this condition for switch pressed at PinC1
    }
    else
        if(!CHECKBIT(PINC,2))
        {
            // PINC2 state is 0 this condition is for switch pressed at PINC2
        }
}



Also make sure that the pullup resistors are enabled for the button pins
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
is there any problem related
Code:
 else if (show_digit==4)

this condition in other ISR
 

No this is not a problem, this is to restart the display refresh from 0
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top