/trunk/libraries/max7219/demo/max7219__demo.c |
---|
0,0 → 1,75 |
/**************************************************************************//** |
* \brief USART library - Demonstration program |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20090314 |
* |
* This file is part of the iDreamMicro library. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file demo_max7219.c |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <max7219/max7219.h> |
#include <util/delay.h> |
#include <stdbool.h> |
#include <stdlib.h> |
/****************************************************************************** |
* Main function. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn int main(void) |
* |
* \brief Main function. |
******************************************************************************/ |
int |
main |
( |
void |
){ |
// Initialize and configure MAX7219. |
max7219__initialize(); |
max7219__set_scan_limit(max7219__scan_limit__digit_0_to_7); |
max7219__set_intensity(max7219__intensity__level_15); |
max7219__set_decode_mode(max7219__decode_mode__all_digits); |
// Switch on MAX7219 display. |
max7219__set_shutdown_mode(max7219__shutdown_mode__normal_operation); |
// Write values on digits. |
max7219__write_char_on_digit(max7219__digit__0, max7219__character__zero, false); |
max7219__write_char_on_digit(max7219__digit__1, max7219__character__one, true); |
max7219__write_char_on_digit(max7219__digit__2, max7219__character__two, false); |
max7219__write_char_on_digit(max7219__digit__3, max7219__character__three, true); |
max7219__write_char_on_digit(max7219__digit__4, max7219__character__four, false); |
max7219__write_char_on_digit(max7219__digit__5, max7219__character__five, true); |
max7219__write_char_on_digit(max7219__digit__6, max7219__character__six, false); |
max7219__write_char_on_digit(max7219__digit__7, max7219__character__seven, true); |
for (;;); |
return 0; |
} |
/trunk/libraries/max7219/src/SConscript |
---|
0,0 → 1,13 |
# Import environment set for target. |
Import('env_target') |
# Define target name. |
TARGET = 'max7219' |
# Define source files. |
sources = [ |
'max7219.c' |
] |
# Build library. |
env_target.BuildLibrary(sources, TARGET) |
/trunk/libraries/max7219/src/max7219.c |
---|
0,0 → 1,269 |
/**************************************************************************//** |
* \brief MAX7219 library |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20110908 |
* |
* This file is part of the iDreamMicro library. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file max7219.c |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include "../max7219.h" |
#include <digital_io/digital_io.h> |
#include <spi/spi.h> |
#include <util/delay.h> |
#include <stdbool.h> |
#include <stdint.h> |
/****************************************************************************** |
* Private macros. |
******************************************************************************/ |
#define REG_NO_OP 0x00 |
#define REG_DIGIT_0 0x01 |
#define REG_DIGIT_1 0x02 |
#define REG_DIGIT_2 0x03 |
#define REG_DIGIT_3 0x04 |
#define REG_DIGIT_4 0x05 |
#define REG_DIGIT_5 0x06 |
#define REG_DIGIT_6 0x07 |
#define REG_DIGIT_7 0x08 |
#define REG_DECODE_MODE 0x09 |
#define REG_INTENSITY 0x0A |
#define REG_SCAN_LIMIT 0x0B |
#define REG_SHUTDOWN 0x0C |
#define REG_DISPLAY_TEST 0x0F |
/****************************************************************************** |
* Private constants. |
******************************************************************************/ |
static const digital_io__pin_position_t chip_select_pin = |
DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_2; |
/****************************************************************************** |
* Private function prototypes. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void max7219__write(uint8_t address, uin8_t value) |
* |
* \brief Write value into MAX7219 register. |
* |
* \param address Register address. |
* \param value Value to write. |
******************************************************************************/ |
void |
max7219__write |
( |
uint8_t address, |
uint8_t value |
); |
/****************************************************************************** |
* Public function definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void max7219__initialize(void) |
* |
* \brief Initialize SPI to drive MAX7219. |
******************************************************************************/ |
void |
max7219__initialize |
( |
void |
){ |
// Configure chip select pin as output. |
digital_io__configure_pin(chip_select_pin, DIGITAL_IO__DIRECTION__OUTPUT); |
digital_io__set_pin_level(chip_select_pin, DIGITAL_IO__LEVEL__HIGH); |
// Wait a little to allow MAX7219 to see a correct logic level on CS pin. |
_delay_ms(2); |
// Configure SPI. |
spi_master__initialize(); |
spi__set_data_order(SPI__DATA_ORDER__MSB_FIRST); |
spi__set_data_mode(SPI__DATA_MODE_0); |
spi__set_clock_rate(SPI__CLOCK_RATE__FOSC_OVER_4); |
} |
/**************************************************************************//** |
* \fn void max7219__set_decode_mode(max7219__decode_mode_t mode) |
* |
* \brief Set MAX7219 decode mode. |
* |
* \param mode Decode mode to set. |
******************************************************************************/ |
void |
max7219__set_decode_mode |
( |
max7219__decode_mode_t mode |
){ |
max7219__write(REG_DECODE_MODE, mode); |
} |
/**************************************************************************//** |
* \fn void max7219__set_intensity(max7219__intensity_t intensity) |
* |
* \brief Set MAX7219 intensity. |
* |
* \param intensity Intensity to set. |
******************************************************************************/ |
void |
max7219__set_intensity |
( |
max7219__intensity_t intensity |
){ |
max7219__write(REG_INTENSITY, intensity); |
} |
/**************************************************************************//** |
* \fn void max7219__set_scan_limit(max7219__scan_limit_t limit) |
* |
* \brief Set MAX7219 scan limit. |
* |
* \param limit Scan limit to set. |
******************************************************************************/ |
void |
max7219__set_scan_limit |
( |
max7219__scan_limit_t limit |
){ |
max7219__write(REG_SCAN_LIMIT, limit); |
} |
/**************************************************************************//** |
* \fn void max7219__set_shutdown_mode(max7219__shutdown_mode_t mode) |
* |
* \brief Set MAX7219 shutdown mode. |
* |
* \param mode Shutdown mode to set. |
******************************************************************************/ |
void |
max7219__set_shutdown_mode |
( |
max7219__shutdown_mode_t mode |
){ |
max7219__write(REG_SHUTDOWN, mode); |
} |
/**************************************************************************//** |
* \fn void max7219__set_display_test_mode(max7219__display_test_mode_t mode) |
* |
* \brief Set MAX7219 display test mode. |
* |
* \param mode Display test mode to set. |
*****************************************************************************/ |
void |
max7219__set_display_test_mode |
( |
max7219__display_test_mode_t mode |
){ |
max7219__write(REG_DISPLAY_TEST, mode); |
} |
/**************************************************************************//** |
* \fn void max7219__write_char_on_digit( |
* max7219__digit_t digit, |
* max7219__character_t character, |
* bool decimal_point) |
* |
* \brief Write character on digit. |
* |
* \param digit Digit to write. |
* \param character Character to write. |
* \param decimal_point Display decimal point. |
******************************************************************************/ |
void |
max7219__write_char_on_digit |
( |
max7219__digit_t digit, |
max7219__character_t character, |
bool decimal_point |
){ |
uint8_t value = character; |
if (decimal_point) |
{ |
// If decimal point must be switched on. |
value |= max7219__segment__DP; |
} |
max7219__write(digit, value); |
} |
/**************************************************************************//** |
* \fn void max7219__write_segments_on_digit( |
* max7219__digit_t digit, |
* max7219__segment_t segments) |
* |
* \brief Set segment(s) on digit. |
* |
* \param digit Digit to write. |
* \param segment Segment(s) to set. |
******************************************************************************/ |
void |
max7219__write_segments_on_digit |
( |
max7219__digit_t digit, |
max7219__segment_t segments |
){ |
max7219__write(digit, segments); |
} |
/****************************************************************************** |
* Private function definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void max7219__write(uint8_t address, uint8_t value) |
* |
* \brief Write value into MAX7219 register. |
* |
* \param address Register address. |
* \param value Value to write. |
******************************************************************************/ |
void |
max7219__write |
( |
uint8_t address, |
uint8_t value |
){ |
// Reset chip select pin to select the device. |
digital_io__set_pin_level(chip_select_pin, DIGITAL_IO__LEVEL__LOW); |
// tcss |
_delay_ms(1); |
// Transmit data to the device, register address and value. |
spi_master__transmit(address); |
spi_master__transmit(value); |
// Set chip select pin to valid data onto the device. |
digital_io__set_pin_level(chip_select_pin, DIGITAL_IO__LEVEL__HIGH); |
// tcsw |
_delay_ms(1); |
} |
/trunk/libraries/max7219/SConscript |
---|
0,0 → 1,16 |
# Import environment set for target. |
Import('env_target') |
# Define directories to process. |
directories = [ |
'src/' |
] |
# Process directories. |
for directory in directories: |
SConscript( |
directory + 'SConscript', |
variant_dir = '#build/' + '/libraries/max7219/' + env_target['NAME'], |
exports = { 'env_target' : env_target }, |
duplicate = 0 |
) |
/trunk/libraries/max7219/max7219.h |
---|
0,0 → 1,299 |
/**************************************************************************//** |
* \brief MAX7219 library |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20110908 |
* |
* This file is part of the iDreamMicro library. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \headerfile max7219.h |
******************************************************************************/ |
#ifndef H__IDREAMMICRO__MAX7219__H |
#define H__IDREAMMICRO__MAX7219__H |
#ifdef _cplusplus |
extern "C"{ |
#endif |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <stdbool.h> |
/****************************************************************************** |
* Public types. |
******************************************************************************/ |
/**************************************************************************//** |
* \enum max7219__decode_modes |
* \typedef max7219__decode_mode_t |
******************************************************************************/ |
typedef enum max7219__decode_modes |
{ |
max7219__decode_mode__none = 0x00, |
max7219__decode_mode__digit_0 = 0x01, |
max7219__decode_mode__digit_1 = 0x02, |
max7219__decode_mode__digit_2 = 0x04, |
max7219__decode_mode__digit_3 = 0x08, |
max7219__decode_mode__digit_4 = 0x10, |
max7219__decode_mode__digit_5 = 0x20, |
max7219__decode_mode__digit_6 = 0x40, |
max7219__decode_mode__digit_7 = 0x80, |
max7219__decode_mode__all_digits = 0xFF |
} max7219__decode_mode_t; |
/**************************************************************************//** |
* \enum max7219__intensities |
* \typedef max7219__intensity_t |
******************************************************************************/ |
typedef enum max7219__intensities |
{ |
max7219__intensity__level_0 = 0x00, |
max7219__intensity__level_1 = 0x01, |
max7219__intensity__level_2 = 0x02, |
max7219__intensity__level_3 = 0x03, |
max7219__intensity__level_4 = 0x04, |
max7219__intensity__level_5 = 0x05, |
max7219__intensity__level_6 = 0x06, |
max7219__intensity__level_7 = 0x07, |
max7219__intensity__level_8 = 0x08, |
max7219__intensity__level_9 = 0x09, |
max7219__intensity__level_10 = 0x0A, |
max7219__intensity__level_11 = 0x0B, |
max7219__intensity__level_12 = 0x0C, |
max7219__intensity__level_13 = 0x0D, |
max7219__intensity__level_14 = 0x0E, |
max7219__intensity__level_15 = 0x0F |
} max7219__intensity_t; |
/**************************************************************************//** |
* \enum max7219__scan_limits |
* \typedef max7219__scan_limit_t |
******************************************************************************/ |
typedef enum max7219__scan_limits |
{ |
max7219__scan_limit__digit_0 = 0x00, |
max7219__scan_limit__digit_0_to_1 = 0x01, |
max7219__scan_limit__digit_0_to_2 = 0x02, |
max7219__scan_limit__digit_0_to_3 = 0x03, |
max7219__scan_limit__digit_0_to_4 = 0x04, |
max7219__scan_limit__digit_0_to_5 = 0x05, |
max7219__scan_limit__digit_0_to_6 = 0x06, |
max7219__scan_limit__digit_0_to_7 = 0x07 |
} max7219__scan_limit_t; |
/**************************************************************************//** |
* \enum max7219__shutdown_modes |
* \typedef max7219__shutdown_mode_t |
******************************************************************************/ |
typedef enum max7219__shutdown_modes |
{ |
max7219__shutdown_mode__shutdown = 0x00, |
max7219__shutdown_mode__normal_operation = 0x01 |
} max7219__shutdown_mode_t; |
/**************************************************************************//** |
* \enum max7219__display_test_modes |
* \typedef max7219__display_test_mode_t |
******************************************************************************/ |
typedef enum max7219__display_test_modes |
{ |
max7219__display_test_mode__normal_operation = 0x00, |
max7219__display_test_mode__test_mode = 0x01 |
} max7219__display_test_mode_t; |
/**************************************************************************//** |
* \enum max7219__digits |
* \typedef max7219__digit_t |
******************************************************************************/ |
typedef enum max7219__digits |
{ |
max7219__digit__0 = 0x01, |
max7219__digit__1 = 0x02, |
max7219__digit__2 = 0x03, |
max7219__digit__3 = 0x04, |
max7219__digit__4 = 0x05, |
max7219__digit__5 = 0x06, |
max7219__digit__6 = 0x07, |
max7219__digit__7 = 0x08 |
} max7219__digit_t; |
/**************************************************************************//** |
* \enum max7219__characters |
* \typedef max7219__character_t |
******************************************************************************/ |
typedef enum max7219__characters |
{ |
max7219__character__zero = 0x00, |
max7219__character__one = 0x01, |
max7219__character__two = 0x02, |
max7219__character__three = 0x03, |
max7219__character__four = 0x04, |
max7219__character__five = 0x05, |
max7219__character__six = 0x06, |
max7219__character__seven = 0x07, |
max7219__character__eight = 0x08, |
max7219__character__nine = 0x09, |
max7219__character__dash = 0x0A, |
max7219__character__e = 0x0B, |
max7219__character__h = 0x0C, |
max7219__character__l = 0x0D, |
max7219__character__p = 0x0E, |
max7219__character__blank = 0x0F |
} max7219__character_t; |
/**************************************************************************//** |
* \enum max7219__segments |
* \typedef max7219__segment_t |
******************************************************************************/ |
typedef enum max7219__segments |
{ |
max7219__segment__DP = 0x80, |
max7219__segment__A = 0x40, |
max7219__segment__B = 0x20, |
max7219__segment__C = 0x10, |
max7219__segment__D = 0x08, |
max7219__segment__E = 0x04, |
max7219__segment__F = 0x02, |
max7219__segment__G = 0x01 |
} max7219__segment_t; |
/****************************************************************************** |
* Public function prototypes. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void max7219__initialize(void) |
* |
* \brief Initialize SPI to drive MAX7219. |
******************************************************************************/ |
void |
max7219__initialize |
( |
void |
); |
/**************************************************************************//** |
* \fn void max7219__set_decode_mode(max7219__decode_mode_t mode) |
* |
* \brief Set MAX7219 decode mode. |
* |
* \param mode Decode mode to set. |
******************************************************************************/ |
void |
max7219__set_decode_mode |
( |
max7219__decode_mode_t mode |
); |
/**************************************************************************//** |
* \fn void max7219__set_intensity(max7219__intensity_t intensity) |
* |
* \brief Set MAX7219 intensity. |
* |
* \param itensity Intensity to set. |
******************************************************************************/ |
void |
max7219__set_intensity |
( |
max7219__intensity_t intensity |
); |
/**************************************************************************//** |
* \fn void max7219__set_scan_limit(max7219__scan_limit_t limit) |
* |
* \brief Set MAX7219 scan limit. |
* |
* \param limit Scan limit to set. |
******************************************************************************/ |
void |
max7219__set_scan_limit |
( |
max7219__scan_limit_t limit |
); |
/**************************************************************************//** |
* \fn void max7219__set_shutdown_mode(max7219__shutdown_mode_t mode) |
* |
* \brief Set MAX7219 shutdown mode. |
* |
* \param mode Shutdown mode to set. |
******************************************************************************/ |
void |
max7219__set_shutdown_mode |
( |
max7219__shutdown_mode_t mode |
); |
/**************************************************************************//** |
* \fn void max7219__set_display_test_mode(max7219__display_test_mode_t mode) |
* |
* \brief Set MAX7219 display test mode. |
* |
* \param mode Display test mode to set. |
*****************************************************************************/ |
void |
max7219__set_display_test_mode |
( |
max7219__display_test_mode_t mode |
); |
/**************************************************************************//** |
* \fn void max7219__write_char_on_digit( |
* max7219__digit_t digit, |
* max7219__character_t character, |
* bool decimal_point) |
* |
* \brief Write character on digit. |
* |
* \param digit Digit to write. |
* \param character Character to write. |
* \param decimal_point Display decimal point. |
******************************************************************************/ |
void |
max7219__write_char_on_digit |
( |
max7219__digit_t digit, |
max7219__character_t character, |
bool decimal_point |
); |
/**************************************************************************//** |
* \fn void max7219__write_segments_on_digit( |
* max7219__digit_t digit, |
* max7219__segment_t segments) |
* |
* \brief Set segment(s) on digit. |
* |
* \param digit Digit to write. |
* \param segment Segment(s) to set. |
******************************************************************************/ |
void |
max7219__write_segments_on_digit |
( |
max7219__digit_t digit, |
max7219__segment_t segment |
); |
#ifdef _cplusplus |
} |
#endif |
#endif /* H__IDREAMMICRO__MAX7219__H */ |