Proteus design
we are working on more than one common cathode segment you need to latch data suitably otherwise data would be misinterpreted .that is why you should enable only one seven segment display at a time. PORTD is connected to seven segment and PC0 and PC1 is used to turn the transistor on or off. transistor can acts as switch. using this property of transistor we enable single 7-seg at a particular time while retrieving data from controller.after receiving data(character 'H') at unit place turn it off .our next step is to turn on second transistor to latch data(character 'R') to be displayed at tens place.
complete code1
#include<avr/io.h>
#include<util/delay.h>
#define segment PORTD
#define tansitor PORTC
#define unitcnt PC0
#define tenscnt PC1
unsigned char unit,tens;
void display();
void main()
{
DDRD=0xff;
DDRC=0x03;
unit=0Xf7; // character H
tens=0X76; // character R
while(1)
{
display();
}
}
void display()
{
segment=unit; // transistor1
tansitor=(1<<unitcnt)|(0<<tenscnt);
_delay_ms(1);
tansitor=(0<<unitcnt)|(0<<tenscnt);
segment=tens; // transistor2
tansitor=(0<<unitcnt)|(1<<tenscnt);
_delay_ms(1);
tansitor=(0<<unitcnt)|(0<<tenscnt);
}
complete code2
#include<avr/io.h>
#include<util/delay.h>
#define segment PORTD
unsigned char unit,tens;
void display();
void main()
{
DDRD=0xff;
DDRC=0x03;
unit=0Xf7;
tens=0X76;
while(1)
{
display();
}
}
void display()
{
segment=unit; // transistor1
PORTC=PORTC|0b00000001;
_delay_ms(1);
PORTC=PORTC&0b11111110;
segment=tens; // transistor2
PORTC=PORTC|0b00000010;
_delay_ms(1);
PORTC=PORTC&0b11111101;
}
VIDEO
Category: