You are on page 1of 19

USING THE BANK OF 8

EEM4016

7-SEGMENT DISPLAYS

1
AVR BOARD

GLCD CS1
GLCD CS2
GLCD RW
GLCD A0

RS CLCD
HEX Switch

Enable
CLCD
Frequency Cinch
Analog

Cinch
GLCD Enable
DA OUT
S15 Graphics Character
S2 LEDs DAC
S3 LCD LCD
PA0

Poti1 PC0..7 PC0..3


Poti2
S1 Latch
PA1
Latch Enable
EEM4016

Port A Port C
PA2

Keypad LEDs

PA7 EE- Temp IO IO


GLCD CS1

GLCD CS2

RTC
GLCD RW

GLCD A0

PROM Sensor Expander Expander

PF0/ADC0 PB0/SDA
I2CINT
PF1/ADC1 PB1/SCLK
PF2/ADC2 PB2
PF3/ADC3 PB3
Enable CLCD RS CLCD
Port B
Port F

PF4 PB4
PF5 PB5/D
USB JTAG
PF6 PB6/CLK MAX 7219
PF7 PB7/LOAD

I2CINT PD0/INT0 PE0


PD1/INT1 PE1
PD2/RXD1 PE2/DAC
RS232
PD3/TXD1 PE3
Port D

Port E

PD4 PE4
GLCD Enable
Buzzer PD5 PE5

S13 PD6 PE6


PD7 PE7
Latch Enable

S4
2
Using the Bank of 8 7-Segment Displays

PHYSICAL CONNECTION

MAX7219 8
PB5 DIN
EEM4016

PB6 CLK

LOAD 8 1
PB7

AVR

3
Using the 7-Segment Displays

Include the file avr.h in order to access the following functions:

init_7seg(void)
To intialise the interface
EEM4016

dis_7seg(unsigned char address, unsigned char data)


To display a single digit

dis_7seg_num(unsigned char address, int num)


To display three digit number

4
Using the avrm.h Header File

USERS PROGRAM avrm.h


init_7seg( )
#include kamavr.h
void main(void)
EEM4016

{ dis_7seg( )
init_7seg( );
.......
dis_7seg_num( )
dis_7seg( ) ;
dis_7seg_num( ) ;
.........
}
dis_7seg( ) and dis_7seg_num( )
need parameters passed.
5
Library Function: init_7seg()
1. Configures interface pins as outputs
2. Configures the external MAX7219 driver chip

MAX7219 8
EEM4016

PB5 DIN 8

PB6 CLK

LOAD 8 1
PB7

AVR
6
Library Function: dis_7seg()
Used to output a single digit to a single 7-segment display
digit position ( 1 - 8 , left to right)

digit to be displayed
EEM4016

dis_7seg( d , n )
1 2 3 4 5 6 7 8 Segment positions
Examples
int pos = 8, num = 2 ;

dis_7seg( 1 , 5 ) ; // To display 5 on the left-hand 7 seg.display

dis_7seg( pos, num ) ; // displays 2 on right-hand display

7
Library Function: dis_7seg_num()

To display a three digit number on the display.

display start digit (1 - 8 , left to right)

A integer ( 0 - 255 )
EEM4016

dis_7seg_num( d , n )

Examples:
int position = 3 ; num = 123 ;
dis_7seg_num ( 1 , 213 ); // displays 213-----
dis_7seg_num (position , num); // displays --123---

8
7 Segment Display Programming Examples

7SEG1.C
7SEG1.C
Using
Using the
the algorithm
algorithm developed
developed below,
below,
write
write aa program
program toto continually
continually show
EEM4016

show
the
the following
following display:
display:
0011223344556677 with small delay
1122334455667788
2233445566778899 sufficient to see
etc...
etc... each line

9
Memory set up

digit position ( 1 - 8 , left to right)

RAM digit to be displayed

digit[0] 0
EEM4016

digit[1] 1 dis_7seg( d , n )
digit[2] 2
digit[3] 3
digit[4] 4
digit[5] 5
digit[6] 6
digit[7] 7

AVR

10
Algorithm

1.1. Define
Defineand andintialise
intialisean
anarray
arraynamed
nameddigitdigitto
tohold
holdthe
the
integer
integervalues
values0,1,2,3,4,5,6,7
0,1,2,3,4,5,6,7
2. Initialise
Initialisethe
the77segment
segmentdisplays
displaysusing
usingdig_int(
dig_int())
EEM4016

2.
3.
3. Set
Setaapointer
pointertotohold
holdthe
theaddress
addressof ofthe
thestart
startof
ofarray
array
4.
4. Send
Sendeacheachvalue
valueheld
heldininarray
arrayto
toaadisplay
displaysegment
segment
5.
5. Increment
Incrementeach eachof ofthe
thevalues
valuesininthe
thearray
array
6.
6. Delay
Delayto tosee
seecurrent
currentdisplay
displayoutput
output
7.
7. Loop
Loopto tostage
stage33

11
A:\7SEG1.C

#include avrm.h
#define TRUE 1

void delay(void); /* Function prototype */


EEM4016

void main(void)
{

int digit[8] = { 0,1,2,3,4,5,6,7 } ; /* array */


int *arrayptr ; /* pointer to hold address of array */
int count ; /* loop counter */

12
CONTINUED...

dig_int(); /* Initialise interface to display */


while ( TRUE )
{
/* Display current content of array */
EEM4016

arrayptr = &digit[0] ; /* Initialise the pointer */


for ( count = 1 ; count <=8 ; count++ )
{
dis(count , *arrayptr ) ; /* display current digit */
arrayptr++ ; /* Increment pointer */
}

13
CONTINUED...

/* Increment each value in the array */

ptr = &digit[0] ; /* Initialise pointer */


for ( count = 1 ; count <= 8 ; count++ )
{
EEM4016

(*ptr)++ ; /* Increment memory content */


ptr++ ; /* Increment the pointer */
}

/* Hold display for a set delay time */


delay( ) ;

} /* End of while loop */


} /* End of main function */

14
void delay(void)
{
unsigned int bigcount ;
EEM4016

for ( bigcount = 0 ; bigcount <= 40000 ; bigcount++ )


;

} /* End of function delay( ) */

15
7 Segment Display Programming Examples

7SEG2.C
7SEG2.C
Write
Write aa program
program to to read
read the
the state
state of
of the
the
EEM4016

bank
bank of
of 88 toggle
toggle switches
switches andand to
to display
display
the
the corresponding
corresponding decimal
decimal number
number on on
the
the bank
bank ofof 7-segment displays..
7-segment displays

16
7SEG2.C
#include avrm.h
#define TRUE 1

void main(void)
{
EEM4016

APORT = 0 ; /* Initialise port A */


while (TRUE)
dis_7seg_num(1, PINA) ; /* Display state of switches as 3
digit number starting at left-
hand side of bank of
displays*/
}

17
Tasks

1.1. Verify
Verifythe
theoperation
operationofof7SEG1.C
7SEG1.C
2.2. Verify
Verifythe
theoperation
operationofof7SEG2.C
EEM4016

7SEG2.C
3.3. Write
Writeaaprogram
programto todisplay
displayan
anincrementing
incrementingcount
count
(0
(0to
to100)
100)ononthe
theseven
sevensegment
segmentdisplays.
displays. Name
Name
the
thefile
file7SEG3.C
7SEG3.C

18
NOTES
EEM4016

19

You might also like