Hier mal ein kleines Testprogramm für TM1637 Basierte 7 Segment Module. Auch wenn es den Anschein hat, der TM1637 ist kein kompatibler I2C chip. Als reiner LED Anzeigentreiber eignet sich der TM1637 aufgrund der händischen Ansteuerung meiner Meinung nach eher weniger, da ist der I2C Bruder HT16K33 und die SPI Schwester MAX7219 besser geeignet. Wobei der TM1637 und der HT16K33 auch Tasen einlesen können. doch das gehört in andere Treads.
Wie im Programm angegeben kommt das Programm nicht von mir, ich hab es nur einmal eingedampft und in Englisch kommentiert.
Alles anzeigen
Modul ist von Catalex; 4-Digit Display v1.0
Catalex.JPGCatalex_uno.JPG
Wie im Programm angegeben kommt das Programm nicht von mir, ich hab es nur einmal eingedampft und in Englisch kommentiert.
BASCOM-Quellcode
- ' Sample to show how to use 4 Digit LED Display from Catalex. Display is TM1637 based
- 'Programm is reduced to show basic code, for advanced funtions and Keypad Readout please use the original program from:
- 'http://kaktusa.pl/tm1637-w-module-z-wyswietlaczem-led-7seg-4-cyfry/
- $Regfile="m328pdef.dat"
- $Crystal=16000000
- $hwstack=40
- $swstack=16
- $framesize=32
- $baud = 9600
- config Portc.0 = output ' define output for clock signal
- config Portc.1 = output ' define output for Data signal
- Clk Alias Portc.0 'Define alias for outputs - If you are using the original program do this in the include file
- Dio_set Alias Portc.1
- Dio_out Alias Portc.1
- Dio_in Alias Pinc.1
- Declare Sub Tm1637_wrbyte(byval Bajt As Byte)
- Dim Variable_a as byte
- Dim temp as byte
- 'first we have to set the Display Brightness:
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&H8F ) 'Set display brightness; Hex 80=off; Hex 88= 1/16 brightness to Hex 8F = Maximun Brightness
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- Print "Brigtness set"
- Do
- 'We want to display 1234
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&H40) 'Data instruction set Hex44 write one byte to register (data write mode set) autoincrement adress mode
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- '
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&Hc0) 'addres instruction setting, first digit (HexC0) MSB display
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B00000110) 'Digit 1; showing:1
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B01011011) 'Digit 2; showing:2
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B01001111) 'Digit 3; showing:3
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B01100110) 'Digit 4; showing:4
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- print "Display shows 1234"
- wait 1
- 'We want to display (empty)008
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&H40) 'Data instruction set Hex44 write one byte to register (data write mode set) autoincrement adress mode
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- '
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&Hc0) 'addres instruction setting, first digit (HexC0) MSB display
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B00000000) 'Digit 1; showing:(empty)
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B00111111) 'Digit 2; showing:0
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(&B00111111) 'Digit 3; showing:0
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(127) 'Digit 4; showing:8
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- Print "Displays shows (empty)008"
- wait 1
- 'We want to display (empty)08.8
- Variable_a = 127 'define Variable to display a 8
- Variable_a = Variable_a + 128 'Add 128 to show the dezimal point of this Digit
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&H44) 'Data instruction set Hex44 write one byte to register (data write mode set) no autoincrement adress mode
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- Gosub Tm1637_start
- Call Tm1637_wrbyte(&Hc2) 'Addres instruction setting, third digit (HexC2) MSB display
- Gosub Tm1637_ack
- Call Tm1637_wrbyte(Variable_a) 'Write Variable to defined digit
- Gosub Tm1637_ack
- Gosub Tm1637_stop
- Print "Displays shows (empty)08.8"
- wait 1
- Loop
- End
- Tm1637_start: '1637 start transmission
- Set Clk
- Set Dio_out
- Waitus 2
- Reset Dio_out
- Return
- Tm1637_ack: '1637 responses transmission
- Reset Clk
- Waitus 5 'After the eighth clock falling edge delay 5us, start determination ACK signal
- Reset Dio_set
- Bitwait Dio_in , Reset
- Set Clk
- Waitus 2
- Reset Clk
- Set Dio_set
- Return
- Tm1637_stop: '1637 Stop transmission
- Reset Clk
- Waitus 2
- Reset Dio_out
- Waitus 2
- Set Clk
- Waitus 2
- Set Dio_out
- Return
- Sub Tm1637_wrbyte 'Write byte variable passed by the call (Bajt)
- For Temp = 0 To 7 'send bit, LSB first
- Reset Clk
- Dio_out = Bajt.temp
- Waitus 3
- Set Clk
- Waitus 3
- Next Temp
- End Sub
Catalex.JPGCatalex_uno.JPG