Git Product home page Git Product logo

tm1638's Introduction

TM1638 Library

Library for handling TM1638 LED display driver.

Library Features

  • Support for both Common Anode and Common Cathode Seven-segment displays
  • Support for dimming display
  • Support for scan Keypad

Hardware Support

It is easy to port this library to any platform. But now it is ready for use in:

  • AVR (ATmega32)
  • STM32 (HAL)
  • ESP32 (esp-idf)

How To Use

  1. Add TM1638.h, TM1638_config.h and TM1638.c files to your project. It is optional to use TM1638_platform.h and TM1638_platform.c files (open and config TM1638_platform.h file).
  2. Initialize platform-dependent part of handler.
  3. Call TM1638_Init().
  4. Call TM1638_ConfigDisplay() to config display.
  5. Call other functions and enjoy.

Example

Using TM1638_platform files
#include <stdio.h>
#include "TM1638.h"
#include "TM1638_platform.h"

int main(void)
{
  TM1638_Handler_t Handler;

  TM1638_Platform_Init(&Handler);
  TM1638_Init(&Handler, TM1638DisplayTypeComCathode);
  TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON);

  while (1)
  {
    // Display the number 8 and Decimal Point in the SEG1 
    TM1638_SetSingleDigit_HEX(&Handler, 8 | TM1638DecimalPoint, 0);
  }

  TM1638_DeInit(&Handler);
  return 0;
}
Without using TM1638_platform files (AVR)
#include <stdio.h>
#include <avr/io.h>
#define F_CPU 8000000
#include <util/delay.h>
#include "TM1638.h"

#define TM1638_DIO_DDR   DDRA
#define TM1638_DIO_PORT  PORTA
#define TM1638_DIO_PIN   PINA
#define TM1638_DIO_NUM   0

#define TM1638_CLK_DDR   DDRA
#define TM1638_CLK_PORT  PORTA
#define TM1638_CLK_NUM   1

#define TM1638_STB_DDR   DDRA
#define TM1638_STB_PORT  PORTA
#define TM1638_STB_NUM   2


static void
TM1638_PlatformInit(void)
{
  TM1638_CLK_DDR |= (1<<TM1638_CLK_NUM);
  TM1638_DIO_DDR |= (1<<TM1638_DIO_NUM);
  TM1638_STB_DDR |= (1<<TM1638_STB_NUM);
}

static void
TM1638_PlatformDeInit(void)
{
  TM1638_CLK_DDR &= ~(1<<TM1638_CLK_NUM);
  TM1638_CLK_PORT &= ~(1<<TM1638_CLK_NUM);
  TM1638_DIO_DDR &= ~(1<<TM1638_DIO_NUM);
  TM1638_DIO_PORT &= ~(1<<TM1638_DIO_NUM);
  TM1638_STB_DDR &= ~(1<<TM1638_STB_NUM);
  TM1638_STB_PORT &= ~(1<<TM1638_STB_NUM);
}

static void
TM1638_DioConfigOut(void)
{
  TM1638_DIO_DDR |= (1<<TM1638_DIO_NUM);
}

static void
TM1638_DioConfigIn(void)
{
  TM1638_DIO_DDR &= ~(1<<TM1638_DIO_NUM);
}

static void
TM1638_DioWrite(uint8_t Level)
{
  if (Level)
    TM1638_DIO_PORT |= (1<<TM1638_DIO_NUM);
  else
    TM1638_DIO_PORT &= ~(1<<TM1638_DIO_NUM);
}

static uint8_t
TM1638_DioRead(void)
{
  uint8_t Result = 1;
  Result = (TM1638_DIO_PIN & (1 << TM1638_DIO_NUM)) ? 1 : 0;
  return Result;
}

static void
TM1638_ClkWrite(uint8_t Level)
{
  if (Level)
    TM1638_CLK_PORT |= (1<<TM1638_CLK_NUM);
  else
    TM1638_CLK_PORT &= ~(1<<TM1638_CLK_NUM);
}

static void
TM1638_StbWrite(uint8_t Level)
{
  if (Level)
    TM1638_STB_PORT |= (1<<TM1638_STB_NUM);
  else
    TM1638_STB_PORT &= ~(1<<TM1638_STB_NUM);
}

static void
TM1638_DelayUs(uint8_t Delay)
{
  for (; Delay; --Delay)
    _delay_us(1);
}


int main(void)
{
  TM1638_Handler_t Handler;

  Handler.PlatformInit = TM1638_PlatformInit;
  Handler.PlatformDeInit = TM1638_PlatformDeInit;
  Handler.DioConfigOut = TM1638_DioConfigOut;
  Handler.DioConfigIn = TM1638_DioConfigIn;
  Handler.DioWrite = TM1638_DioWrite;
  Handler.DioRead = TM1638_DioRead;
  Handler.ClkWrite = TM1638_ClkWrite;
  Handler.StbWrite = TM1638_StbWrite;
  Handler.DelayUs = TM1638_DelayUs;

  TM1638_Init(&Handler, TM1638DisplayTypeComCathode);
  TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON);

  while (1)
  {
    // Display the number 8 and Decimal Point in the SEG1 
    TM1638_SetSingleDigit_HEX(&Handler, 8 | TM1638DecimalPoint, 0);
  }

  TM1638_DeInit(&Handler);
  return 0;
}

tm1638's People

Contributors

hossein-m98 avatar vinzenz82 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tm1638's Issues

STM32 undefined reference to `TM1638_STB_OUTPUT'

Hello.
There are errors in the libraries!
Can you view my project or post your working project?

image

c:\st\stm32cubeide_1.4.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: D:/ST_prog/tm1638my_pin/Debug/../Core/Src/TM1638_platform.c:135: undefined reference to `TM1638_STB_OUTPUT'

https://cloud.mail.ru/public/vb3r/BfCauUsco

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.