7seg

/ @file main.c @author Gastón SALAZAR <gaston_salazar@yahoo.com> @brief Display a (hexadecimal-) number sequence on a display

  1. Interface #
    1. Physical connections Port Segment Color ---- ------- ----- PB0 A blue PB1 B red PB2 C yellow PB3 D green PB4 E orange PB5 F violet PB6 G gray
    2. LEDS on a 7-segment Display AAA F B F B F B GGG E C E C E C DDD
  • /
  1. include "mbed.h"

const unsigned long DELAY = 5000000UL; const unsigned short DISPLAY = 0x7F;

The programming language is C++, not C as previously done. DigitalOut led(LED1); PortOut myDisplay(PortC, DISPLAY); DigitalIn myButton(USER_BUTTON);

typedef enum { ZERO = 0x3f, ONE = 0x6, TWO = 0x5b, THREE = 0x4f, FOUR = 0x66, FIVE = 0x6d, SIX = 0x7d, SEVEN = 0x7, EIGHT = 0x7f, NINE = 0x6f, CA = 0x77, CB = 0x7c, CC = 0x39, CD = 0x5e, CE = 0x79, CF = 0x71 } digits;

This was handle in automation, some time ago, with a cam or "drum". And in electronics, it was implemented with a decoder in a ROM. Of course you could implemented it with logic gates. const unsigned short int segments[] = {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, CA, CB, CC, CD, CE, CF };

void setup() { myDisplay = ZERO; }

void loop() { static short unsigned display_count = 0; static long unsigned delay_count = DELAY;

if (!delay_count) { display_count++; display_count &= 0x0f; myDisplay = segments[display_count]; delay_count = DELAY; }

if (myButton == 1) User button NOT pressed delay_count; }

int main() { setup(); while(1) { loop(); } }


Please log in to post comments.