-
Ordering information
Call us or mail us for inquiries & availability: info@mtronixtech.com
-
Search projects by Price
-
Project Categories
- Robots and Robotics
- GSM based Projects
- GPS based Projects
- RFID based Projects
- Energy Saving
- Wireless Communication
- DTMF based projects
- SMS based projects
- RF Remote
- Mobile Controlled
- Power Saver
- Sensor based Projects
- Alcohol Sensor
- heartbeat Sensor
- Humidity Sensor
- Infrared Sensor
- Level Sensor
- Light Sensor
- LPG Gas Sensor
- Moisture Sensor
- Temperature Sensor
- Vibration Sensor
- Weight Sensor
-
Search projects by Application
Project Videos:
Landrover Robot Operated by Cellphone
Industrial Automation using Cellphone
Password based door locking
Automatic room light controller
Temperature controlled fan
Electronic voting machine
Search by Components
89c51 89s51 89s52 89v51RD2 555 ADC0808 ADC0809 AT24c16 AT24c64 AT89s52 Battery BC547 Bulb Buzzer Darlington Pair DC motor Decoder EEPROM Fan GPS GSM IR LED Keypad L239D LCD Display LDR LED LM35 LM358 Matrix keypad MAX232 Motor Driver MQ6 PC Interface Relay RFID Card RFID Reader RFID Tags Sim300 sim900 SR86 SR87 Stepper Motor SYHS220 TSOP1738
Home
Two 7 Segment display
Embedded C code for Two 7 Segment displays
Sample code for Two 7 Segment displays using delay subroutine.
Following code can be using for AVR series ICs like: ATmega8, ATmega16, ATmega32.
#include <avr/io.h> #include <util/delay.h> #define DISPLAY_PORT PORTD #define DISPLAY_DDR DDRD #define DISPLAY_CTRL_PORT PORTB #define DISPLAY_CTRL_DDR DDRB #define ZERO 0x77 #define ONE 0x41 #define TWO 0x3B #define THREE 0x6B #define FOUR 0x4D #define FIVE 0x6E #define SIX 0x7E #define SEVEN 0x43 #define EIGHT 0x7F #define NINE 0x6F #define DOT 0x80 #define DIGIT1 4 //(left most) #define DIGIT2 5 #define DIGIT3 6 #define DIGIT4 7 //(right most) #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif int main(void) { int i=0; int d1,d2,d3; DISPLAY_DDR=0xFF; DISPLAY_PORT=0x00; DISPLAY_CTRL_DDR=0xff; DISPLAY_CTRL_PORT=0x00; _delay_ms(4000); while(1) { for(i=0;i<1000;i++) { sbi(DISPLAY_CTRL_PORT,DIGIT1); cbi(DISPLAY_CTRL_PORT,DIGIT2); cbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=d3; _delay_us(200); cbi(DISPLAY_CTRL_PORT,DIGIT1); sbi(DISPLAY_CTRL_PORT,DIGIT2); cbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=d2; _delay_us(200); cbi(DISPLAY_CTRL_PORT,DIGIT1); cbi(DISPLAY_CTRL_PORT,DIGIT2); sbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=d1; _delay_us(200); } for(i=0;i<1000;i++) { sbi(DISPLAY_CTRL_PORT,DIGIT1); cbi(DISPLAY_CTRL_PORT,DIGIT2); cbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=~SIX; _delay_us(200); cbi(DISPLAY_CTRL_PORT,DIGIT1); sbi(DISPLAY_CTRL_PORT,DIGIT2); cbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=~FIVE; _delay_us(200); cbi(DISPLAY_CTRL_PORT,DIGIT1); cbi(DISPLAY_CTRL_PORT,DIGIT2); sbi(DISPLAY_CTRL_PORT,DIGIT3); DISPLAY_PORT=~FOUR; _delay_us(200); } } return 0; }