Monday, 06 April 2020
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #204 - LED Drive Control Special Circuit TM1637 Print
TM1637 is a kind of LED (light-emitting diode display) drive control special circuit with keyboard scan interface and it's internally integrated with MCU digital interface, data latch, LED high pressure drive and keyboard scan.
Sample to show how to use 4 Digit LED Display from Catalex. Display is TM1637 based

Call TM1637_On  --> turns display on and sets brightness to PWM 25%
Call TM1637_Off --> turns display off
Call TM1637_Disp (data) --> puts data on display !! The display shows any number from 0 to 9999. Larger values will display only the 4 least digits.

The programm is based on info on 'kaktus-website' http://kaktusa.pl/tm1637-w-module-z-wyswietlaczem-led-7seg-4-cyfry/
The datasheet can be downloaded HERE

The communication with the display is NOT I2C since the device has no slave-address so you can use also 'non-I2C'-pins
However keep in mind to use pull-ups. Users of the Catalex-board don't have to worry, The pull-ups are mounted on this board.

Author: Peter Dams

Example code:


$regfile = "m2560def.dat"
$crystal = 12000000
$hwstack = 100
$swstack = 100
$framesize = 100

Config Portf.= Output                                     ' for TM1637 clock
Config Portf.= Output                                     ' for TM1637 data

Tm1637_clk Alias Portf.0
Tm1637_dout Alias Portf.1
Tm1637_din Alias Pinf.1

Declare Sub Tm1637_disp(byval Bdispdata As Word)            'The display can only show numbers
Declare Sub Tm1637_wrbyte(byval Bdata As Byte)
Declare Sub Tm1637_on()
Declare Sub Tm1637_off()
Declare Sub Tm1637_start()
Declare Sub Tm1637_stop()
Declare Sub Tm1637_ack()
'========================================================================
'
'     Start main
'
'========================================================================

Tm1637_on
Tm1637_disp 45
Wait 2
Tm1637_off

Do
Loop
End

'=========================================================================
'
'     Subroutines
'
'========================================================================

Sub Tm1637_ack()
   Reset Tm1637_clk
   Waitus 5
   Reset Tm1637_dout
   Bitwait Tm1637_din , Reset
   Set Tm1637_clk
   Waitus 2
   Reset Tm1637_clk
   Set Tm1637_dout
End Sub



Sub Tm1637_off()
   Tm1637_start
   Tm1637_wrbyte &H80                                       'Turn display off
   Tm1637_ack
   Tm1637_stop
End Sub



Sub Tm1637_on()
   Tm1637_start
   Tm1637_wrbyte &H8A                                       'Turn display on and set PWM for brightness to 25%
   Tm1637_ack
   Tm1637_stop
End Sub



Sub Tm1637_start()
   Set Tm1637_clk
   Set Tm1637_dout
   Waitus 2
   Reset Tm1637_dout
End Sub


Sub Tm1637_stop()
   Reset Tm1637_clk
   Waitus 2
   Reset Tm1637_dout
   Waitus 2
   Set Tm1637_clk
   Waitus 2
   Set Tm1637_dout
End Sub



Sub Tm1637_disp(byval Bdispdata As Word)
   Local Bcounter As Byte
   Local Strdisp As String * 5

   Strdisp = Str(bdispdata)
   Strdisp = Format(strdisp , "     ")

   Tm1637_start
   Tm1637_wrbyte &H40                                       'autoincrement adress mode
   Tm1637_ack
   Tm1637_stop
   Tm1637_start
   Tm1637_wrbyte &HC0                                       'startaddress first digit (HexC0) = MSB display
   Tm1637_ack

   For Bcounter = 2 To 5
      Select Case Asc(strdisp , Bcounter)
         Case "0" : Tm1637_wrbyte &B00111111
         Case "1" : Tm1637_wrbyte &B00000110
         Case "2" : Tm1637_wrbyte &B01011011
         Case "3" : Tm1637_wrbyte &B01001111
         Case "4" : Tm1637_wrbyte &B01100110
         Case "5" : Tm1637_wrbyte &B01101101
         Case "6" : Tm1637_wrbyte &B01111101
         Case "7" : Tm1637_wrbyte &B00000111
         Case "8" : Tm1637_wrbyte &B01111111
         Case "9" : Tm1637_wrbyte &B01101111
         Case Else : Tm1637_wrbyte &B00000000
      End Select
      Tm1637_ack
   Next
   Tm1637_stop
End Sub



Sub Tm1637_wrbyte(byval Bdata As Byte)
   Local Bbitcounter As Byte

   For Bbitcounter = 0 To 7                                 'LSB first
      Reset Tm1637_clk
      Tm1637_dout = Bdata.bbitcounter
      Waitus 3
      Set Tm1637_clk
      Waitus 3
   Next
End Sub