Seven Segment Display (SSD) is a classical display device for low end digital electronic equipment. The programming for is very simple. It could represent numbers and some English letters.
It come with two terminology, common cathode type and common anode type. But deciding which type to use depends on the application. In this example, I take only common cathode type.
single digit seven segments display |
Segment LED diagram |
Since it made of seven LED segment, we just turn on any LED to display digit or letter. For example, turning on LED segment B and C make digit "1" to display.
In programming, they commonly use hexadecimal equivalent to the SSD output.
For the common cathode type display the hex code represent the digit from 0 to 9 and from A to F is shown below:Each LED segment made of from LED, requiring around 2 V and ~10 mA of current. Typically, the digital output from microcontroller drives a voltage of +5V TTL. So we need to cut down the voltage from microcontroller to ~2 V via resistor.
Resistors are connected to cut down voltage output to common cathode SSD |
In this example, I use a digital input from PD0 to count the event, and output the counting to the presented SSD.
Circuit diagram uses for simulation |
#include <avr/io.h> #define F_CPU 16000000UL #include "util/delay.h" //SET THE INPUT BUTTON FOR COUNTING #define btnPressed ((PIND&0x01)==0) int main(void) { //SEVEN SEGMENT MAP FOR COMMON //CATHODE TYPE SEVEN SEGMENT DISPLAY unsigned char ssd[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D, 0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; unsigned char btnCount=0; DDRC=0xFF; //PORTC IS FOR OUTPUT TO SEVEN SEGMENT DDRD=0xFE; //PORTD PD0 IS USED FOR INPUT COUNTING PORTD=0x01; //SET PD0 TO HIGH FOR PULLING UP while (1) { if (btnPressed) //CHECK IF PD0 IS PRESSED { btnCount+=1; //Increase The Counter _delay_ms(250); if(btnCount>15) btnCount=0; //RESET COUNTER WHEN IT IS OVER 15 } PORTC=ssd[btnCount]; //OUTPUT TO SSD } }
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.
Click here to download this example.
If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.
No comments:
Post a Comment