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.
ok i tried condition for switch as you suggested i try make PA3 pin toggle when interrupt 1 occurs
Code:
ISR(TIMER1_OVF_vect) {
    if(!CHECKBIT(PINC,1))
    {
        // PINC1 state is 0 this condition for switch pressed at PinC1

		PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=0xc6;
	    PORTA=(1<<PA3);
		_delay_us(100);
		PORTA=(0<<PA3);   


    
    }
    else
        if(!CHECKBIT(PINC,2))
        {
            // PINC2 state is 0 this condition is for switch pressed at PINC2
			PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=values[11];
    
        }
}

even PIN 3 of PORT A is not toggling when switch is zero.
 

The counter counts up t0 65535+1 to give the overflow interrupt , the button condition is only checked when the interrupt occurs

The timer is set to count with clk/64 so for 8MHz the interrupt is executed once every 0.5sec , are you sure that the proteus simulation has reached that time and that you keep the button pressed long enough.
Note that in simulation usually everything runs in slow motion.
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
yes sir i agree with you ill check code on hardware and let you know about result....

thank yo so much sir for all your replies i learned many good and new things from you.
 

hi alexan sir i check code on hardware but i am getting three problems
first is timer1 interrupt is executing desire function but its produce flickers in 7segments i tried with all different pre scaling value for timer but still problem not solve.

second i am getting both the interrupts on logic 0 in desire pin i mean i have to make my switch to interrupts occur when i remove my push button its comes to default state

third one is timer1 ISR is only executes once then if i pressed same switch again it wont display desire character on seven segment.so if i power reset controller it execute timer1 ISR when first time switch is pressed.

so i tried debug the code in avr studio but i really cant find any bug so can u please tell me the possible reason for this errors?
 

Timer1 interrupt may introduce flicker is you set it to a very fast speed.
A polling rate at about 20 time/sec should be fine.
Apart from the timer prescaller you can preload a value in the start of the interrupt in order to shorten the times it takes for the counter to overflow or you can use the CTC mode set to give a match interrupt at a lower count.

I'm not sure what you mean with the second problem, the condition inside the interrupt checks is button1 is grounded and if not it checks for button2

I don't see any reason for the interrupt to be executed only once have you made any changes to your code?
 

in second i mean that i have to maintain ground logic on switch pin till it finish adc scaling if i remove push button mean logic 0 is removed from pin it comes to zero 7segment showing 0values.

actually i want to developed logic that once switch is pressed it wont come out from that condition until its task over
 

The you can set a flag variable (buttton_pressed=1) once the button is pressed and use that in order to make the actions you want instead of the actual pin state
 

hi alex sir i cant get working two interrupt together so i decided to do with one interrupt my new code is as below
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <math.h>
#include <util/delay.h>


#define SEVEN_SEGMENT_PORT PORTC
#define SEVEN_SEGMENT_DDR DDRC




/*global variable declaration
*/

unsigned int values[12]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xC6,0x83};
//unsigned int values[11]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xC6};

unsigned int var1,num1,num2,num3,num4,var2,key1,key2;
uint16_t t;
uint16_t volt,scale,offset,final,ac;

// static uint8_t show_digit;




/*function declaration
*/ 
void ADC_init(void);
//void init_Ex2(void);
unsigned int ADC_read(unsigned char);
void init_Ex1(void);
int button1_is_pressed();
int button2_is_pressed();

  



/*main programm starts here*/

int main()
{ 


      init_Ex1();
//	  init_Ex2();
 sei();//Enable Global Interrupts
 
   DDRB=0xff;
   PORTB=0xff;
   

   
 SEVEN_SEGMENT_DDR=0xff; //Turn off all segments
 SEVEN_SEGMENT_PORT=0XFF;

  
   DDRA=0x00;
   PORTA=(1<<PA3)|(1<<PA4);
   
  // DDRA=0xff;
  // PORTA=(1<<PA3); 
 
  

  ADC_init();
  key1=0;
  key2=0;

while(1)
{

 // ADC_init();
    t=ADC_read(1);
  //volt=(((5.000)*t)/1023)*1000;
    // scale=t*.01955;
        // final=((scale/2)-1);


	 if(button1_is_pressed()) {key1=1;}
	  

           if(key1==1)
	      {
		 scale=(((uint32_t)t)*((uint32_t)5000))/1023;
		
		 scale=((uint32_t)scale * 100)/75;
          //key1=0;

            }
			

     if(button2_is_pressed()) {key2=1;}

		  if(key2==1)
		  {
	 scale=(((uint32_t)t)*((uint32_t)5000))/1023;
     scale=((uint32_t)scale *150)/75;
	 // key2=0;
		   }
       //  }
        



	   




}


}






void ADC_init(void) // Initialization of ADC
{
ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
// Enable ADC and set Prescaler division factor as 128
}

unsigned int ADC_read(unsigned char ch)
{
  ch= ch & 0b00000111; // channel must be b/w 0 to 7
  ADMUX |= ch; // selecting channel
 
  ADCSRA|=(1<<ADSC); // start conversion
  while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
  ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
 
 return (ADC);
}
 


void init_Ex1(void)
{


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

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

}

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

}


int button1_is_pressed()
{

     if(!(PINA&(1<<PINA3))) 
   {

     _delay_ms(250);
    if(!(PINA&(1<<PINA3))) 
     return 1;
    }
  return 0;
}

int button2_is_pressed()
{

     if(!(PINA&(1<<PINA4))) 
   {

     _delay_ms(250);
    if(!(PINC&(1<<PINA4))) 
     return 1;
    }
  return 0;
}

ISR(TIMER0_OVF_vect) //ISR rutine for sevensegment

{
          static uint8_t show_digit;

		  	
		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 % 1000)/100;
	
        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 % 10000)/1000;
            
		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 /10000;
   SEVEN_SEGMENT_PORT=values[num4];			// Writing corresponding number on Tens place of minutes

	
	}

   else if (show_digit==4) 
   
   {
               
    PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=values[0];


	if(key1==1) 
{

  PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=values[10];

}


   
    else if(key2==1) 
{
PORTB=(1<<PB0)|(0<<PB1)|(0<<PB2)|(0<<PB3)|(0<<PB4);

	SEVEN_SEGMENT_PORT=values[11];

}
	 



	 
    }






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





  }



/*
ISR(TIMER2_OVF_vect) {


  

		//if(!(PINC&(1<<PINC1))&&(PINC&(1<<PINC2)))
      
	 	if(button1_is_pressed()) 

	 {
	   PORTB=(1<<PB0);

	SEVEN_SEGMENT_PORT=values[10];

	// _delay_us(150);

    

	 
      }

       else if(button2_is_pressed())
	   { 
	     
		 PORTB=(1<<PB0);

	     SEVEN_SEGMENT_PORT=values[11];
	//	 _delay_us(150);


        }



}*/

with this code i am getting only one char display it wont go to other switch conditon
 

hi alexan sir please help me to do finish this i just want to display char when switch is pressed. can you please guide me sir?
 
Last edited:

I'm not sure what is wrong in your code , you have added a fifth display and depending on the value of key1/key2 you show to it some character.

Before pressing a button you get values[0] , if you press button1 you get values[10] and with button2 values[11] , check that these represent correct values.

When you set key1 then you will always show values[10] even if the key2 becomes 1 because you never clear the key1 back to 0
 

    V

    Points: 2
    Helpful Answer Positive Rating
ya thnx alexan sir you are right i need to make key1/key2 back to zero i did that and problem is solved now. thank you so much
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top