Friday, January 12, 2024

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8

Overview

TM1637 is a LED controller circuit with keyboard scan function. We can use it to drive LED, multiplexing display, and keypad input scanning. Its LED control output duty can be adjust by software. This chip is popular for Arduino users. It comes with a 7-segment display module, and keypad.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Proteus Simulation

Its communication interface is similar to Inter Integrated Circuit (I2C). But the LSB of data is sent first. This chip doesn't have slave address that the I2C does. What the controller send is command and data.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
TM1637 Features
Its supply voltage is typically +5VDC.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
TM1637 Pin Functions

Keypad scanning start at the end of display. It's a 6x2 keypad matrix.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Keypad Interface

Display Data Register has up to six addresses.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Display Register Address
Data command is used to set the display mode and the LED driver status.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
TM1637 Data Command
Command data setting is to set data write and data read. 
PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Address Command Setting
Address command setting is used to set the display register address. Its default or start address is 0xC0 plus 0 to 5 next addresses.

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Address Command Setting
Display Control command is used to set pulse duty cycle or LED brightness. Display OFF or display ON must add to turn the output driver OFF or ON.
 
PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
Display Control Command

The display ON command is 0x88. We must add pulse width value (ranges 0 to 7) to adjust display brightness for example 0x88+3. 

PIC16F887 TM1637 Six Digits 7-Segment Display Example Using XC8
TM1637 SRAM data writing mode

The controller may write data or command to this chip using auto increment 1, fixed address mode.

PIC16F887 MPLABX XC8 Programming

MPLABX IDE and XC8 C compiler is free to use. In this example, PIC16F887 send  7-Segment data to a six-digit display.

  1. /*
  2.  * File: main.c
  3.  * Author: Admin
  4.  *
  5.  * Created on January 12, 2024, 3:08 PM
  6.  */
  7.  
  8. #include <xc.h>
  9. #include "config.h"
  10. #include "tm1637.h"
  11.  
  12. #define _XTAL_FREQ 8000000UL
  13.  
  14. const char msg_1[]={0x76,0x79,0x38,0x38,0x3F};
  15.  
  16. void main(void) {
  17. char txt[7],count=0;
  18. OSCCONbits.IRCF=7;
  19. TM1637Init();
  20. for(uint8_t i=0;i<5;i++) display(i,msg_1[i]);
  21. __delay_ms(3000);
  22. clearDisplay();
  23. while(1){
  24. txt[6]=data_7[count];
  25. for(uint8_t i=0;i<6;i++) txt[i]=txt[i+1];
  26. /*
  27.   txt[6]=data_7[count];
  28.   txt[0]=txt[1];
  29.   txt[1]=txt[2];
  30.   txt[2]=txt[3];
  31.   txt[3]=txt[4];
  32.   txt[4]=txt[5];
  33.   txt[5]=txt[6];
  34.   */
  35. for(uint8_t i=0;i<6;i++) display(i,txt[i]);
  36. count++;
  37. __delay_ms(1000);
  38. if(count==16) count=0;
  39. }
  40. return;
  41. }
  42.  

I don't have a TM1637 nor an TM1637 display module. So I use Proteus VSM to simulate this program.


Click here to download its source file.


 

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)