Sunday, August 8, 2021

ATMega16 Interfaces To A Discrete 7-Segments Display

 

Overview

A 7-Segments display commonly found in a typical digital electronics equipment, a temperature controlled switch, a sign board, etc.

It made of segment-shaped of LED with seven light emitting diodes to creates a pattern of numbers, sign, or any characters with an optional dotting point (dp).

ATMega16 Interfaces To A Discrete 7-Segments Display
Some common anode 7-segments display type with the size of one inch. I use these stuffs for my serial display board.

Technical Data

A 7-Segments display varies in its display size, color and its common configurations. I have seen some available sizes of this type of display, 0.36″, 0.40″, 0.56″, 1″, 2.3″, 3″, 4″ and 5″.

Some Parameters

The size refers to the effective display size. Red in output color is a preferred one’s for most hobbyists. The common configuration are the Common Anode (CA) and the Common Cathode (CC). The designer may select between this two kind of configuration to work with the output of any digital IC or embedded controller.

ATMega16 Interfaces To A Discrete 7-Segments Display
The mechanical diagram and the internal circuit arrangement of a single one inch 7-Segments display.

Some hobbyists make this display by connecting multiple LED to make the segments and dotting point.

Each segment of this one inch size display typically supplied at 3.4V for the 20mA forward current. Some large display size above 2.3 inches have a typical forward current of 25mA with the nominal forward voltage of 9.25V.

Display Representation

A parallel output port of a digital IC or a microcontroller output data to this display. It’s 8-bit including the dotting point. However the dotting point is optional, and it usually bit-wise ORed within the output port.

Typically the programmer maps the segments to a corresponding value in a table. For the common anode display, we have a table below.



DisplaygfedcbaHEX
0OFFONONONONONON0xC0
1OFFOFFOFFOFFONONOFF0xF9
2ONOFFONONOFFONON0xA4
3ONOFFOFFONONONON0xB0
4ONONOFFOFFONONOFF0x99
5ONONOFFONONOFFON0x92
6ONONONONONOFFON0x82
7OFFOFFOFFOFFONONON0xF8
8ONONONONONONON0x80
9ONONOFFONONONON0x90
A minimum common anode type 7-Segments Data Table of decimal numbers between 0 and 9

For a common cathode type display, the 7-Segments data table lists below.

DisplaygfedcbaHEX
0OFFONONONONONON0x3F
1OFFOFFOFFOFFONONOFF0x06
2ONOFFONONOFFONON0x5B
3ONOFFOFFONONONON0x4F
4ONONOFFOFFONONOFF0x66
5ONONOFFONONOFFON0x6D
6ONONONONONOFFON0x7D
7OFFOFFOFFOFFONONON0x07
8ONONONONONONON0x7F
9ONONOFFONONONON0x6F
A minimum common cathode type 7-Segments Data Table of decimal numbers between 0 and 9

It’s not only decimal numbers, we can create some ASCII characters to show on this display – for example A, B, L, etc. Due to a limited content I don’t list them all here. We will see them in the programming section.

Interfacing And Programming

A parallel port output of a digital IC or a microcontroller/microprocessor connects to this display via current limiting resistors. These resistors divide the voltage between the LED segment to around 3.4V (1 inches size display), to get a nominal forward current 20mA.

Here I preferred a one inch common anode red display, I stock in my warehouse.

ATMega16 Interfaces To A Discrete 7-Segments Display
A single red common anode 7-Segments display – 7SR10012BS I stock.



Microcontroller To 7-Segments Interface

Port C of ATMega16 outputs 7-Segments data to this display via current limiting resistors. With a nominal forward current of 20mA, the voltage drop at each segment is 3.7V. We need to find the an appropriate value of resistor. The onboard devices including the ATMega16 supplies at 5V. So Port C digital output high to external devices must be 5V. Using the voltage divider rule, current limiting resistor is 63 Ohm. However, I only have a 68 Ohm one’s in my stock.

ATMega16 Interfaces To A Discrete 7-Segments Display

Schematic Diagram Of This Example

Atmel Studio 7 C Programming

Using C in Atmel Studio, we don’t need any hardware library to code within this simple example. It’s nothing more than a digital I/O programming. One important note is creating a 7-Segments data table that have shown in the table above.

Here we use a common anode type display. The display will show a decimal number from 0 to 9 and a character from A to F. The program just display the counting value from 0 to 15, then roll back to 0 and vice versa.

  1. /*
  2.  * discreteSsdCa.c
  3.  *
  4.  * Created: 11/14/2020 6:46:30 PM
  5.  * Author : Admin
  6.  */
  7.  
  8. #include <avr/io.h>
  9.  
  10. #define F_CPU 16000000UL
  11. #include <util/delay.h>
  12.  
  13. int main(void)
  14. {
  15. //7-Segment data table
  16. unsigned char cAnode[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,
  17. 0x83,0xC6,0xA1,0x86,0x8E};
  18. //counting parameter
  19. unsigned char cnt=0;
  20. //Port C As Output
  21. DDRC=0xFF;
  22. while (1)
  23. {
  24. //Display the 7-Segments Data
  25. PORTC=cAnode[cnt];
  26. //Increase the counter
  27. cnt++;
  28. //Reset when it reaches 16
  29. if(cnt>15) cnt=0;
  30. _delay_ms(1000);
  31. }
  32. }

 

On my development board I externally add a one inch 7-Segments display inserted on a bread board.



ATMega16 Interfaces To A Discrete 7-Segments Display
A program test using development board with some external add-on components.

 Click here to download a zip file of this programming example. Let see this video on YouTube.



No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)