Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

JY-LKM1638 TM1638 8 digit 8 LED 8 Button display

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Aug 26, 2012 8:16 am    Post subject: JY-LKM1638 TM1638 8 digit 8 LED 8 Button display Reply with quote

Ben posted some demo code to drive the JY-LKM1638 display some time back and I recently purchased some with other items.

I have started to change his code to make it useable as a driver for the displays so I thought I would start this blog to show the progress as I change and replace code. Also I hope to show how to reduce the amount of flash needed. In the code below there is still Ben's code but commented out I will remove it in the next post.
I have also added some data at the end that is the values to send to get numbers and letters on the 7 segment units I have lined up the elements in the data with the digits 0 to 9 then a ,b , c etc to make a lookup easy as lookup(2, Disply) when sent will show the number 2

Regards Paul

Update: Note the sub programs and functions following with some modification should work for other display chips like the MAX7219 and a display using 74HC595s the look-up data would need to be changed and the control codes (non existent with 74HC595)

Update: here is a link to the data sheet for the TM1638
https://docs.google.com/file/d/0B84N2SrJaybwZTgxYjM4ZmEtY2EyZi00YjVjLWIzOTctYTlhMjJkM2MxMTBl/edit?pli=1


Last edited by Paulvk on Tue Sep 04, 2012 10:49 am; edited 4 times in total
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Aug 26, 2012 10:59 am    Post subject: Reply with quote

Now with commented code removed. I have written as sub to send the full 16 bytes to the display which are stored as an array. Now that we have the bytes in an array we can do interesting things with them so now in this code we have scroll right where we move the digits/characters and LEDs one step to the right which makes a nice moving word.

Only using a mega48 and just got to 54% of flash so still a bit more room !


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Aug 26, 2012 1:15 pm    Post subject: Reply with quote

This next lot of code shows the reduction in flash use by using the arrays and sending 16 bytes a a time with the same result on the displays the code use has dropped to 43% from 54%

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Aug 28, 2012 8:05 am    Post subject: Reply with quote

We have put characters on the displays moved them left to right, turned on LEDs red and green.
Now we look at the buttons and for fun if we press button one on display one LED one on display three will go red then back to green when the button is not pressed and so with buttons 2 to 8, LEDs 2 to 8.

Note the buttons are read after the scroll right so holding the button down while scrolling and till the displays clear then when they come back on so will the display three LEDs show the button pressed.

UPDATE: The buttons on the board are connected to K3 , button 1 is KS1, 2 KS3, 3 KS5, 4 KS7, 5 KS2, 6 KS4, 7 KS6, 8 KS8
Also inspection of the board reveals that you can connect wires to pads provided to get K1, K2 & K3 so you can get another 16 buttons or use a keypad matrix of 3 X 8 this equates to two telephone style keypads of 3 X 4.

NOTE: Since I have not yet come close to filling the mega48 the free version of bascom works with all this code!

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Aug 30, 2012 12:09 pm    Post subject: Reply with quote

I thought it would be nice if to print a letter like "A" to the display that all we had to do was say which display, the position (segment) and then just give it the letter as we do with the "LCD" function in Bascom so I wrote a function Tm1638prn now to print the letter "A" to the forth segment on display one we just W = Tm1638prn(1 , 4 , "A") the function takes care of the rest. Its only one letter at the moment but I will increase it to 8 later.

Regards Paul
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 553

germany.gif
PostPosted: Thu Aug 30, 2012 1:05 pm    Post subject: Reply with quote

...looks like you have a lot of fun with those parts Very Happy
_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Fri Aug 31, 2012 7:44 am    Post subject: Reply with quote

Hello six1

Not just fun I have also learnt some more skills and since these displays are so cheap its good to have all the code ready to drive them so if a project needs buttons and a display its already done.

Now as I said I would do I have made the function handle up to 8 characters and it wraps around so if you start at 4 and give it 8 characters it will place the last four in 1 to 4. Next I will write a similar function to run the LEDs so it will be a simple matter of LED number, red/green, on/off


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Fri Aug 31, 2012 11:41 am    Post subject: Reply with quote

Now a function to turn LEDs red/green off/on and later to make them blink

W = Tm1638led(1 , 1 , 2) is module 1, led 1, red
W = Tm1638led(1 , 2 , 1) is module 1, led 2, green

With the functions it will be simple to send information to the displays using variables.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sat Sep 01, 2012 8:46 am    Post subject: Reply with quote

I have now turned the reading of the buttons into a function, Tm1638key(1) this will return a byte with its bits set to correspond to the pressed buttons for module one, thus if bit 0 is set then button 8 is pressed , if bit 7 is set then button 1 is pressed, for module 2 Tm1638key(2).

Note: I have gone to a m168 as I am using an LCD to display what is going on and there is code for multiple modules if this is removed so that we use only one module then the code will shrink maybe by 50%


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Sep 02, 2012 12:22 pm    Post subject: Reply with quote

Now more functions

Segment_scroll this scrolls the 7 segment displays left or right how many steps you tell it but leaves the LEDs alone

Clear_module this clears the particular module it is told to

Also made a change to Tm1638led function as red is "1" and green is "2" & off is "0" lined these up as it saves code

Now with the code, I will when I have all the subs/functions written, make a version that works only with one module this will remove all the select case statements to decide which module to address this will cause the code to shrink and fit in a small AVR . One module is what I can see being used most often.


Regards Paul
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Sun Sep 02, 2012 11:12 pm    Post subject: Thanks Reply with quote

Thanks Paul.
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Sep 03, 2012 2:07 pm    Post subject: Reply with quote

I have now implemented the flash led part of the Tm1638led function this took a bit of time to work out so as not to upset the other functions and subs. It is in the timer ISR but it would be good to get it into the main loop of a program I save the state of the select pins and the module number it appears to work fine. You can flash leds on off or red/green. Now the timer ISR is a one second tick so it can be used to run a clock but a crystal would be needed to get accuracy.
Note the flashing is implemented by using the high nibble of the LED bytes in the variables and swapping them each second as the display does nothing with the high nibble it works.
Also have a function to set the brightness of the displays Set_intensity(1 , 2) is module one level 2 it can be 0 to 8


Next I am looking into flashing the 7 segment displays but have no spare bits so will need 8 more variables to swap with.


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Sep 05, 2012 12:42 pm    Post subject: Reply with quote

I have now the flashing 7 segment display but as I wanted it to flash an alternate character as well as just off and on I had to re-write a lot of things the print function now takes a number of things the module number , position of the character , the text to be printed there , the flash type (0 = no flash, 1 = blank flash , 2 = alt flash ) , alternate characters to flash .This flashes the characters on module 3 EN <> AB starting a segment 5 W = Tm1638prn(3 , 5 , "EN" , 2 , "AB")

Now there is quite a bit of code in this but not all functions would be needed but I developed them to give myself a bunch of building blocks to use with these displays

Note when the display is scrolled the flashing alternate characters move with their partners.

Have one left to develop LED scroll

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Sep 06, 2012 12:29 pm    Post subject: Reply with quote

Now the LED scroll works the same as the 7segment scroll and is just a rewrite of it '
Also I put in another constant xtal2 for testing of the flash ISR by putting in 1/2 the CPU clock you get twice a second 1/4 4 times I found that everything still appears to work ok even at 8 times a second.

Next I am going to shrink the code to one module which I think will be what I will use the most.


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Fri Sep 07, 2012 2:36 pm    Post subject: Reply with quote

Here is the one module version.

It has two additional subs one to clear the 7 segment displays and one to clear the LEDs.

There is also an enhancement to the character look up with the print function it now looks up the decimal point in text and turns it on in the previous character then prints the next character directly after the decimal point so it handles "AMPS-22.5" by turning on the decimal point between the 2 and 5.

I have put the read key (button) into the ISR it is running at 8 times a second and printing the result to an LCD without problems Note the LCD print is for testing. This means that the variable that holds the state of the buttons is being updated 8 times a second.

If only numbers are needed to be displayed the arrangement of the lookup data is such that a simple lookup based on the number can be used as the elements 0 t 9 correspond to the numbers 0 to 9

So almost there I will look at doing something useful with the the building blocks'

Regards Paul
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum