Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TTU_CSC1300.h
- Committer:
- jwbruce
- Date:
- 2020-06-28
- Revision:
- 0:1201a9a37799
- Child:
- 1:62c831ab7306
File content as of revision 0:1201a9a37799:
// macros, defines, globals,and prototypes for the TTU_F031 library
#ifndef TTU_CSC1300_H
#define TTU_CSC1300_H
#include "mbed.h"
/*************************************************************************
*
* DEFINES and MACROS
*
**************************************************************************/
#define FALSE 0
#define TRUE (~FALSE)
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define SEG_A 0xFE
#define SEG_B 0xFD
#define SEG_C 0xFB
#define SEG_D 0xF7
#define SEG_E 0xEF
#define SEG_F 0xDF
#define SEG_G 0xBF
#define SEG_DP 0x7F
#define PATTERN_BLANK 0xFF
#define PATTERN_0 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F)
#define PATTERN_1 (SEG_B & SEG_C)
#define PATTERN_2 (SEG_A & SEG_B & SEG_D & SEG_E & SEG_G)
#define PATTERN_3 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_G)
#define PATTERN_4 (SEG_B & SEG_C & SEG_F & SEG_G)
#define PATTERN_5 (SEG_A & SEG_C & SEG_D & SEG_F & SEG_G)
#define PATTERN_6 (SEG_A & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G)
#define PATTERN_7 (SEG_A & SEG_B & SEG_C)
#define PATTERN_8 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G)
#define PATTERN_9 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_F & SEG_G)
#define PATTERN_A (SEG_A & SEG_B & SEG_C & SEG_E & SEG_F & SEG_G)
#define PATTERN_B (SEG_C & SEG_D & SEG_E & SEG_F & SEG_G)
#define PATTERN_C (SEG_A & SEG_D & SEG_E & SEG_F)
#define PATTERN_D (SEG_B & SEG_C & SEG_D & SEG_E & SEG_G)
#define PATTERN_E (SEG_A & SEG_D & SEG_E & SEG_F & SEG_G)
#define PATTERN_F (SEG_A & SEG_E & SEG_F & SEG_G)
/*************************************************************************
*
* HW to peripheral pin mappings
*
**************************************************************************/
#define SCL_PIN PA_9
#define SDA_PIN PA_10
#define LED0_PIN PA_12
#define LED1_PIN PB_0
#define LED3_PIN PB_7
#define PWM1_PIN PB_1
#define LED2_PIN PF_0
#define CS_SD_PIN PF_1
#define SPK_PIN PA_8
#define CS_LCD_PIN PA_11
#define MOSI_PIN PB_5
#define MISO_PIN PB_4
#define SCLK_PIN PB_3
#define LGT_SENS_PIN PA_0
#define POT_PIN PA_1
#define TEMP_SENS_PIN PA_3
#define PWM2_PIN PA_4
#define SW4_PIN PA_5
#define SW5_PIN PA_6
#define CS_7SEG_PIN PA_7
#define TX_PIN PA_12
#define RX_PIN PA_15
/*************************************************************************
*
* Other useful defines
*
**************************************************************************/
#define I2C_SPEED_STD 100000
#define I2C_SPEED_FAST 400000
#define I2C_SPEED_FASTPLUS 1000000
#define SPI_SPEED_100KBPS 100000
#define SPI_SPEED_500KBPS 500000
#define SPI_SPEED_1MBPS 1000000
/*************************************************************************
*
* USEFUL MACROS
*
*************************************************************************/
/*************************************************************************
*
* G L O B A L V A R I A B L E S
*
*************************************************************************/
extern SPI spi;
//extern I2C i2c;
extern Serial pc;
// create the LEDs
extern DigitalOut led0;
extern DigitalOut led1;
extern DigitalOut led2;
/* only uncomment the following line if your Nucleo32 F031K6
** has removed the solder jumper SB18 on the underside
*/
extern DigitalOut led3;
// create the speaker
extern DigitalOut speaker;
//create the chip-selects
extern DigitalOut cs_sd;
extern DigitalOut cs_lcd;
extern DigitalOut cs_7seg;
// create the switches
extern DigitalIn sw4;
extern DigitalIn sw5;
// create the analog sensors
extern AnalogIn lightSensor;
extern AnalogIn pot;
extern AnalogIn tempSensor;
/*************************************************************************
*
* P R O T O T Y P E S
*
*************************************************************************/
void init_spi(int i_spiBaud);
//void init_i2c(int i_i2cBaud);
void init_serial(int i_serialBaud);
void init_leds(void);
void init_all(void);
/* TEXTLCD
*
* A TextLCD library targeted the F031K6 + Edubase-V2 combination
* implmements a 16x2 HD44780 LCD module using a 4-bit inteface
* connected via a 74HC595 using the chip's SPI
*
* This work is based upon the TextLCD mbed library by Simon Ford
* found at https://os.mbed.com/users/simon/code/TextLCD/
*
* Copyright (c) 2007-2010, sford, http://mbed.org
* Copyright (c) 2020, jwbruce (jwbruce@tntech.edu)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/** A TextLCD interface for driving 4-bit HD44780-based LCDs
*
* Supports only the 16x2 display on the EduBase-V2 board
*
* @code
* #include "mbed.h"
* #include "TextLCD.h"
*
* TextLCD lcd(TextLCD::LCD_CURSOR_ON_BLINKING_ON); // select your cursor style
*
* int main() {
* lcd.printf("Hello World!\n");
* }
* @endcode
*/
class TextLCD : public Stream {
public:
typedef enum {
LCD_CURSOR_OFF_BLINKING_OFF = 0,
LCD_CURSOR_OFF_BLINKING_ON = 0x01,
LCD_CURSOR_ON_BLINKING_OFF = 0x02,
LCD_CURSOR_ON_BLINKING_ON = 0x03,
LCD_CURSOR_DEFAULT = 0x03
} LCDCursor;
/** Declare a TextLCD interface */
TextLCD(LCDCursor cur); // default constructor
#if DOXYGEN_ONLY
/** Write a character to the LCD
*
* @param c The character to write to the display
*/
int putc(int c);
/** Write a formated string to the LCD
*
* @param format A printf-style format string, followed by the
* variables to use in formating the string.
*/
int printf(const char* format, ...);
#endif
/** Locate to a screen column and row
*
* @param column The horizontal position from the left, indexed from 0
* @param row The vertical position from the top, indexed from 0
*/
void setLocation(int column, int row);
/** Clear the screen and locate to 0,0 */
void cls();
/** low-level single character putter **/
void setCharacter(int row, int column, int c);
void setCursor(LCDCursor c);
protected:
// Stream implementation functions
virtual int _putc(int value);
virtual int _getc();
int address(int column, int row);
void writeNibble(char incoming, unsigned char rs);
void writeCommand(int command);
void writeData(int data);
int _column;
int _row;
int _maxColumns;
int _maxRows;
int _cursorState;
};
/* F031K6 + Edubase-V2 7-segment LED Library
* for the 4 seven-segment LEDs inteface connected via two 74HC595s using SPI
*
* Copyright (c) 2020, jwbruce (jwbruce@tntech.edu)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/** A 7-segment LED interface for driving 4 connected seven-segment LEDs
*
* @code
* #include "mbed.h"
* #include "TextLCD.h"
*
* TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
*
* int main() {
* lcd.printf("Hello World!\n");
* }
* @endcode
*/
class SSLED {
public:
typedef enum {
LED_PATTERN_0 = ~0x3F,
LED_PATTERN_1 = ~0x06,
LED_PATTERN_2 = ~0x5B,
LED_PATTERN_3 = ~0x4F,
LED_PATTERN_4 = ~0x66,
LED_PATTERN_5 = ~0x6D,
LED_PATTERN_6 = ~0x7D,
LED_PATTERN_7 = ~0x07,
LED_PATTERN_8 = ~0x7F,
LED_PATTERN_9 = ~0x6F,
LED_PATTERN_A = ~0x77,
LED_PATTERN_B = ~0x7C,
LED_PATTERN_C = ~0x39,
LED_PATTERN_D = ~0x5E,
LED_PATTERN_E = ~0x79,
LED_PATTERN_F = ~0x71,
LED_PATTERN_G = ~0x40,
LED_PATTERN_H = ~0x76,
LED_PATTERN_I = ~0x30,
LED_PATTERN_J = ~0x1E,
LED_PATTERN_L = ~0x38,
LED_PATTERN_N = ~0x54,
LED_PATTERN_O = ~0x3F,
LED_PATTERN_P = ~0x73,
LED_PATTERN_Q = ~0x67,
LED_PATTERN_R = ~0x50,
LED_PATTERN_S = LED_PATTERN_5,
LED_PATTERN_T = ~0x78,
LED_PATTERN_U = ~0x1C,
LED_PATTERN_V = ~0x2A,
LED_PATTERN_Y = ~0x6E,
LED_PATTERN_BLANK = ~0x00,
LED_PATTERN_SPACE = LED_PATTERN_BLANK,
LED_PATTERN_DASH = ~0x40,
LED_PATTERN_DEGREES = ~0xC3,
LED_PATTERN_DECIMALPT = ~0x80,
LED_PATTERN_QUESTION = ~0x53
} LEDPattern;
/** Declare a 7-segment LED interface */
// constructor
SSLED(int display, int pattern);
/** Write a pattern to a chosen display */
void setDisplay(int display, int pattern); // change patterns to blank and write the displays
};
#endif