areeckal
Member level 2
I am trying to display the value read from ADC in 7 segment display in Proteus.
The value is not correctly getting displayed in proteus. It is correct when simulated in avr studio.
Is there anything else to do while interfacing with 7 segment display?
Code is:
Schematic and entire project is attached.
**broken link removed**
Pls help..
The value is not correctly getting displayed in proteus. It is correct when simulated in avr studio.
Is there anything else to do while interfacing with 7 segment display?
Code is:
Code:
#include <avr/io.h>
#include <util/delay.h>
#define SEVEN_SEGMENT1_PORT PORTD
#define SEVEN_SEGMENT1_DDR DDRD
#define SEVEN_SEGMENT2_PORT PORTB
#define SEVEN_SEGMENT2_DDR DDRB
uint8_t digits[2]; //Holds the digits for 2 displays
void SevenSegment(uint8_t n1,uint8_t n2,uint8_t dp)
{
/*This function writes a digits given by n to the display*/
if((n1<10)&&(n2<10))
{
switch (n1)
{
case 0:
SEVEN_SEGMENT1_PORT=0x7E;
break;
case 1:
SEVEN_SEGMENT1_PORT=0x20;
break;
case 2:
SEVEN_SEGMENT1_PORT=0x5D;
break;
case 3:
SEVEN_SEGMENT1_PORT=0x79;
break;
case 4:
SEVEN_SEGMENT1_PORT=0x33;
break;
case 5:
SEVEN_SEGMENT1_PORT=0x5B;
break;
case 6:
SEVEN_SEGMENT1_PORT=0x5F;
break;
case 7:
SEVEN_SEGMENT1_PORT=0x70;
break;
case 8:
SEVEN_SEGMENT1_PORT=0x7F;
break;
case 9:
SEVEN_SEGMENT1_PORT=0x7B;
break;
}
switch (n2)
{
case 0:
SEVEN_SEGMENT2_PORT=0x7E;
break;
case 1:
SEVEN_SEGMENT2_PORT=0x20;
break;
case 2:
SEVEN_SEGMENT2_PORT=0x5D;
break;
case 3:
SEVEN_SEGMENT2_PORT=0x79;
break;
case 4:
SEVEN_SEGMENT2_PORT=0x33;
break;
case 5:
SEVEN_SEGMENT2_PORT=0x5B;
break;
case 6:
SEVEN_SEGMENT2_PORT=0x5F;
break;
case 7:
SEVEN_SEGMENT2_PORT=0x70;
break;
case 8:
SEVEN_SEGMENT2_PORT=0x7F;
break;
case 9:
SEVEN_SEGMENT2_PORT=0x7B;
break;
}
}
}
void Print(uint16_t num)
{
uint8_t i=0;
uint8_t j;
if(num>999) return;
while(num)
{
digits[i]=num%10;
i++;
num=num/10;
}
for(j=i;j<2;j++)
digits[j]=0;
}
/* Main function */
int main(void)
{
uint8_t val;
//Use prescale factor 64 -> ADC clock is 125kHz
ADCSR |= (1<<ADPS1) | (1<<ADPS2);
//AVCC with external capacitor at AREF pin
ADMUX |= (1<<REFS0);
//Enable the ADC
ADCSR |= (1<<ADEN);
//Port D
SEVEN_SEGMENT1_DDR=0xFF;
//Port B
SEVEN_SEGMENT2_DDR=0xFF;
while(1)
{
_delay_ms(1000);
ADMUX|=0x00;
//Start conversion
ADCSR |= (1<<ADSC);
while(!(ADCSRA &(1<<ADIF)));
ADCSRA|=(1<<ADIF);
val = ADC;
Print(val);
SevenSegment(digits[0],digits[1],0);
_delay_ms(1000);
}
}
Schematic and entire project is attached.
**broken link removed**
Pls help..
Attachments
Last edited: