0% found this document useful (0 votes)
22 views2 pages

A

The document contains code for an Arduino program that will display counting from 0 to 99 on two 7-segment displays using ports B, C, and D, while also blinking an LED connected to port C using a defined pin. It sets the ports as outputs, defines the 7-segment display patterns as an array, extracts the tens and ones digits of the counter, displays each digit on the appropriate port, and adds delays between changes.

Uploaded by

Muneeb Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

A

The document contains code for an Arduino program that will display counting from 0 to 99 on two 7-segment displays using ports B, C, and D, while also blinking an LED connected to port C using a defined pin. It sets the ports as outputs, defines the 7-segment display patterns as an array, extracts the tens and ones digits of the counter, displays each digit on the appropriate port, and adds delays between changes.

Uploaded by

Muneeb Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <avr/io.

h>
#define F_CPU 16000000UL
#include <util/delay.h>

// Define the 7-segment display patterns for digits 0-9


const uint8_t seven_seg_array[] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

int main(void) {
// Set Port B and Port C as output for the 7-segment displays
DDRD = 0xFF; // Port D
DDRB = 0xFF; // Port B
DDRC = 0xFF; // Port C

while (1) {
for (int i = 0; i < 100; i++) {
int tens = i / 10; // Extract tens digit
int ones = i % 10; // Extract ones digit

// Display tens digit on the first 7-segment display (Port B)


PORTB = seven_seg_array[tens];
PORTC= seven_seg_array[] =
{0b00000000,0b00000000,0b10000000,0b10000000,0b10000000,0b10000000,0b10000000,0b000
00000,0b10000000,0b10000000};

// Delay for a short period (adjust as needed)


_delay_ms(100);

// Display ones digit on the second 7-segment display (Port C)


PORTD = seven_seg_array[ones];

// Delay for a short period (adjust as needed)


_delay_ms(100);
}
}

return 0;
}

#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>

// Define the 7-segment display patterns for digits 0-9


const uint8_t seven_seg_array[] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

// Define the pin you want to use for the LED in Port C
#define LED_PIN PC0

int main(void) {
// Set Port B and Port C as output for the 7-segment displays
DDRD = 0xFF; // Port D
DDRB = 0xFF; // Port B
DDRC |= (1 << LED_PIN); // Set LED_PIN as an output in Port C

while (1) {
for (int i = 0; i < 100; i++) {
int tens = i / 10; // Extract tens digit
int ones = i % 10; // Extract ones digit

PORTC &= ~(1 << LED_PIN); // Set the specific bit (LED_PIN) to 0
_delay_ms(10);
PORTC |= (1 << LED_PIN); // Set the specific bit (LED_PIN) to 1
_delay_ms(10);
PORTC &= ~(1 << LED_PIN); // Set the specific bit (LED_PIN) to 0
_delay_ms(10);
PORTC |= (1 << LED_PIN); // Set the specific bit (LED_PIN) to 1
_delay_ms(10);
PORTC &= ~(1 << LED_PIN); // Set the specific bit (LED_PIN) to 0
_delay_ms(10);
PORTC |= (1 << LED_PIN); // Set the specific bit (LED_PIN) to 1
_delay_ms(100);
PORTC &= ~(1 << LED_PIN); // Set the specific bit (LED_PIN) to 0
_delay_ms(10);
PORTC |= (1 << LED_PIN); // Set the specific bit (LED_PIN) to 1
_delay_ms(10);
PORTC &= ~(1 << LED_PIN); // Set the specific bit (LED_PIN) to 0
_delay_ms(10);
PORTC |= (1 << LED_PIN); // Set the specific bit (LED_PIN) to 1

// Display tens digit on the first 7-segment display (Port B)


PORTB = seven_seg_array[tens];

// Delay for a short period (adjust as needed)


_delay_ms(10);

// Display ones digit on the second 7-segment display (Port D)


PORTD = seven_seg_array[ones];

// Delay for a short period (adjust as needed)


_delay_ms(10);
}
}

return 0;
}

You might also like