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.

AT90s2313:7 segment display using 74HC595 Shift Register

Status
Not open for further replies.

Amyth

Newbie level 3
Joined
May 22, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,390
Hi I'm trying to programme the microcontroller AT90S2313 to display counter from 99 to 00 using Shift Register.
Microcontroller: AT90S2313
Shift Register: 74HC595
Two PNP BC557 transistors and COMMON ANODE 7-SEGMENT DISPLAY.
Compiler:AVR Code Vision
Schematic Diagram:Schematic | Flickr - Photo Sharing!
I'm having trouble with the programming,basically confused about the steps on how to transmit bits serially to shift register to count from 99 to 00.
I know that the algorithm to load a latched shift-register is:

pull the latch pin low

pull the clock pin low
pull the data pin high or low to reflect bit 1
pull the clock pin high

<repeat for bits 2 through 8>

pull the latch pin high
Although,doesnt this make the code really really long shifting one bit after another?Any easier way?Sorry I have very basic knowledge of programming.
Thanks for your help!!:grin:
 

no its not long code for shifting byte into HC595

here is sample code: (in BASIC)

Code:
sub procedure shift595(dim data1 as byte)
dim dataout as sbit at RB5_bit               ' data input to HC595
dim clockout as sbit at RB6_bit              ' clock input to HC595
dim ddr_dataout as sbit at TRISB5_bit
dim ddr_clockout as sbit at TRISB6_bit
dim chip_select as sbit at RB7_bit          ' show the shifted byte 
dim Chip_Select_Direction as sbit at TRISB7_bit
dim i as byte

clockout = 0
dataout = 0
Chip_select = 0
for i = 7 to 0 step -1 'MSB first (if you want LSB first so change to for i = 0 to 7 step 1)
    dataout = data1.i
    clockout = 1
    clockout = 0
next i
Chip_select = 1
end sub
 

I'm trying to multiplex 2 7-segment display(common ANODE) with 2 PNP transistors and 74hc595 Shift register.I have made functions for the numbers 0-9 follwing the timing diagram of shift register datasheet.I dont know how to turn the 2 transistors off/on at the right time as they both display the same number or sometimes one turns off and other turns on,not fast enough.
Can someone please help me with the MAIN SECTION of my code,I'm using AVR Codevision.The 2 displays are basically meant to count from 99 to 00,thats it.Thank you for your help..
My code for now is:
// INCLUDES

#include <delay.h>
#include <90s2313.h>
#include <stdio.h>

// DEFINES
#define TRANS1 PORTD.2
#define TRANS2 PORTD.3
#define DATA PORTD.1
#define CLK PORTB.0
#define STORE PORTB.1
void number1();
void number2();
void number3();
void number4();
void number5();
void number6();
void number7();
void number8();
void number9();
void number0();

//interrupt[5] void count(void);

void main()
{
DDRB = 0b00000011;
DDRD = 0xFF;// DDRD = 0b00110010;

TRANS1 = 0;
TRANS2 = 1;
number9();
TRANS2 = 0;
TRANS1 = 0;
number8();
/* delay_ms (5000);

TRANS2 = 0;
number9();
TRANS2 = 1;
delay_ms (5000);


}


void number1()
{ STORE = 0; //pull the STORAGE pin LOW
CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}


void number2()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number3()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number4()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number5()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number6()
{
STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number7()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH

}
void number8()
{ STORE = 0; //pull the STORAGE pin LOW
// number1
CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH
}
void number9()
{ STORE = 0; //pull the STORAGE pin LOW

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 1; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH

CLK = 0; //pull the CLOCK pin LOW
DATA = 0; //SERIAL DATA IN
CLK = 1; //pull the CLOCK pin HIGH


STORE = 1; //pull the STORAGE pin HIGH

}
 

I dont know how to turn the 2 transistors off/on at the right time as they both display the same number or sometimes one turns off and other turns on,not fast enough.
If so, it's not a software problem. Multiplexing digits is an elementary digital design problem, you'll find dozens if contributions at edaboard doing the same.

You'll also find many examples of 7-segment decoders and software shift registers, so you don't need to code it the long winded way you did.
 

Hi!

74HC595 datasheet gives 35MHz >= fmax >= 6MHz, depending on the supply voltage and temperature. What is your MCU clock frequency? If bigger, then use some nop commands in between clocking. Also check that all other time related parameters are OK, like let's say holding times.

As for display switching frequency, try >100HZ. Then your eyes would no more notice the blinking.

Hope that helped.
 

to display 2 digit counter its easy here is pseudocode for multiplexing 7 segment:

while(1) {
shift the digit 1 data;
latch/store it;
turn on transistor 1;
some delay here;
turn off transistor 1;
shift the digit 2 data;
latch/store it;
turn on transistor 2;
some delay here;
turn off transistor 2;
some delay here;
}
and so on with digit 3,4,5.....

you can use "for statement" to simplify you code..

good luck
 
  • Like
Reactions: Amyth

    Amyth

    Points: 2
    Helpful Answer Positive Rating
Hi !!

My clock freq is 4Mhz.
How do u set the display switching frequency greater than 100Hz as mentioned above??
Now,using my code(with all number functions defined,the long way) I tested in my MAIN section the following:

void main()
{
DDRB = 0b00000011;//PORT B bit 0 and 1 Output
DDRD = 0xFF;//PORT D Output

TRANS1 = 0;//Transistor 1 ON
TRANS2 = 1;//Transistor 2 is OFF since if its ON,it will display the SAME number
number9();//Display number 9
delay_ms(100);// Delay of 100ms,I have played around this delay time a lot to get multiplexing but no success(right from 1ms to 500ms)
TRANS1 = 1;// Turn Transistor 1 OFF
//Repeating for displaying number 8 on the second display
TRANS2 = 0;
number8();
delay_ms(500);
TRANS2=1;
//Repeat till 97,96,95....
}
While I had success with this,its not whats desired since only one segment display is turned on at one time,so I get 9 then 8,9 then 7,so on.
Not both at the same time which is what multiplexing is.It's not got to do with the delay time I think. The transistor works only as a switch.Since if u look at my schematic,one segment is connected to the other so whichever number function I call,it will light up depending which transistor is ON.

Thanks!
 

It would propably be better if you try something simpler first. Do not try to decrease the displayed number. Instead try to print the same number over and over again (for example number 97).

Code:
while (1)
{
  //Drive display 0
  TRANS1 = 0; 
  TRANS2 = 1;
  number9();
  delay_ms(10);

  //Drive display 1
  TRANS2 = 0;
  TRANS1 = 1;
  number7();
  delay_ms(10);
}

However a 10ms timer triggered event would be much more preferable than software delay.

Hope that helped.
 

@Amyth: make your code small and effective so the processor can run your code fast to avoid flickering..this is important when dealing with multiplexed 7 segment or dot matrix display
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top