BeRTOS
Functions
hw_led_7seg.h File Reference

led 7 segment display low-level More...

#include "cfg/cfg_led_7seg.h"

Go to the source code of this file.

Functions

void sseg_off (void)
 Clean the display.
void sseg_on (uint8_t dgt, uint8_t n_dgt)
 writes the character to the single digit of the display
void sseg_init (void)
 initalize the HW regsiters

Detailed Description

led 7 segment display low-level

This file has the functions that must be implemented to drive the 7 segments display by your hardware

Author:
Fabio Bizzi <fbizzi@bizzi.org>

Example implementation for AtMEGA 1280 (Arduino MEGA) with a 4 digit display. We use PORTA to connect the 8 pins of the 7 segments display and 4 bit of PORTC to select which digit of the display we have to write on.

  7 Seg LED Pin
  ----------------
  LED SEGMENT
  ----------------
  DP G F E D C B A
  7  6 5 4 3 2 1 0
  ----------------
  PORT A Pin
  ----------------

  7 Seg Display Selection
  ----------------
  Display Nr.
  ----------------
  N N N N 3 2 1 0
  7 6 5 4 3 2 1 0
  ----------------
  PORT C Pin
  ----------------

The implementation of the sseg_on procedure that set the PROPER PIN of PORT C to enable the requested digit of the display, after write the encoded character to PORT A

 INLINE void sseg_on(uint8_t dgt, uint8_t n_dgt)
 {
  switch (n_dgt)
  {
 //Common Cathode
 #ifdef CONFIG_LED_7SEG_CCAT

        case 0:
            PORTC &= ~(BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
            PORTC |= BV(PORTC0);
            break;
        case 1:
            PORTC &= ~(BV(PORTC0) | BV(PORTC2) | BV(PORTC3));
            PORTC |= BV(PORTC1);
            break;
        case 2:
            PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC3));
            PORTC |= BV(PORTC2);
            break;
        case 3:
            PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2));
            PORTC |= BV(PORTC3);
            break;

 //Common Anode
 #else

        case 0:
            PORTC |= (BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
            PORTC &= ~(BV(PORTC0));
            break;
        case 1:
            PORTC |= (BV(PORTC0) | BV(PORTC2) | BV(PORTC3));
            PORTC &= ~(BV(PORTC1));
            break;
        case 2:
            PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC3));
            PORTC &= ~(BV(PORTC2));
            break;
        case 3:
            PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2));
            PORTC &= ~(BV(PORTC3));
            break;

 #endif

    }
    //Write the charater
    PORTA = dgt;
 }

The implementation of the sseg_init procedure that set the DIRECTION of PORT C and PORT A to output

 INLINE void sseg_init(void)
 {
 //Initialize PIN Direction to OUTPUT
    DDRA = 0xFF;
    DDRC |= (BV(DDC0) | BV(DDC1) | BV(DDC2) | BV(DDC3));
    //Set the display OFF
    SSEG_OFF();
 }

The implementation of the sseg_off procedure that set the reset PORT A to clean the display and turn off all the pin of PORT C that drive the display's digits

 INLINE void sseg_off(void)
 {
 //Set the display OFF
 //Common Cathode
 #ifdef CONFIG_LED_7SEG_CCAT
    PORTA = 0x00;
    PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
 //Common Anode
 #else
    PORTA = 0xFF;
    PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3));
 #endif

 }

Definition in file hw_led_7seg.h.


Function Documentation

void sseg_init ( void  ) [inline]

initalize the HW regsiters

This is the procedure that initalize the HW regsiters. you have to write it according with your hardware and micro.

Definition at line 224 of file hw_led_7seg.h.

void sseg_off ( void  ) [inline]

Clean the display.

This is the procedure that clean the display in HW mode. you have to write it according with your hardware and micro.

Definition at line 184 of file hw_led_7seg.h.

void sseg_on ( uint8_t  dgt,
uint8_t  n_dgt 
) [inline]

writes the character to the single digit of the display

This is the procedure that writes the character to the single digit of the display, you have to write it according with your hardware and micro.

Parameters:
dgtthe character that has to be displayed
n_dgtthe digit where to disply the character of the display's digits.

Definition at line 205 of file hw_led_7seg.h.