|
|
View previous topic :: View next topic |
Author |
Message |
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
Tm1638 Library |
Posted: Wed Jan 02, 2019 10:18 am |
|
|
Hello everyone.
İ searched tm1638 Library on the internet but i couldn't find it. Could someone share it with me. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2019 10:46 am |
|
|
I'm guessing ??
https://os.mbed.com/components/TM1638-LED-controller-80-LEDs-max-Keyboa/
It'd really help if you posted a link to whatever a tm1638 actually is...
Quite often posters mean a 'module' and not a 'chip', so it's important to provide details !
There's LOTS of Arduino libraries for this module BUT you need to select the correct one ! Some modules have bicolor LEDs, some don't. At $4 a board it's a good deal for 8 7sd, 8 led, 8pb BUT takes a LOT of current if all LEDs are on.
Converting the Arduino library to a CCS driver is easy, maybe 1/2 night project. Quicker if you understand Arduino C !
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Thu Jan 03, 2019 5:10 am |
|
|
Though this is not complete, I've just put together a basic set of routines
to write data to the chip and read the key values. Lots of comments inline.
Some settings will depend on whether the matrix is wired as
common cathode or common anode.
Driving the chip itself is very basic. Just SPI:
Code: |
//Your setup fuses, clock etc..
#use spi(MODE=3, SPI1, BAUD=2MHz, STREAM=TM1638)
//adjust this to use different pins if you want software I2C
//chip supports 2.5MHz max SPI.
#define DISPLAYON 0x84
#define AUTOINC 0x40 //auto increment on write
#define MAX_BRIGHTNESS 0x8F
#define READKEY 0x42 //read key values
#define STB PIN_xx //set to the STB pin
#define ADDR_START 0xC0 //starting address
const unsigned int8 digitToSegment[] = {
// XGFEDCBA
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // b
0b00111001, // C
0b01011110, // d
0b01111001, // E
0b01110001 // F
};
void init_MS(void)
{
output_high(STB_PIN); //ensure chip is deselected
delay_us(1);
}
void display_block(int8 * disp_data, int8 brightness)
{
int8 icnt;
int8 dummy;
//write block of display data to chip
//all sixteen bytes sent
output_low(STB_PIN);
delay_us(1);
//now need to set to send command to autowrite data
spi_xfer(TM1638, AUTOINC, 8);
spi_xfer(TM1638, ADDRESS_START, 8);
//set to start at address 0xC0, and auto increment
for (icnt=0;icnt<16;icnt++)
{
dummy=spi_xfer(TM1638,*disp_data, 8); //send byte
//using the read ensure write will complete each time before
//returning.
disp_data++;
}
//Since I wait for the read each time, the STB can be raised immediately.
output_high(STB_PIN);
//16 bytes sent
delay_us(1); //minimum 1uSec
output_low(STB_PIN);
//now command for brightness
dummy=spi_xfer(TM1638, DISPLAY_ON | (brightness & 7), 8);
output_high(STB_PIN);
delayus(1);
}
void read_keys(int8 * key_data)
{
//read the keyboard data from the chip
output_low(STB_PIN);
delay_us(1);
//Now command to read data
spi_xfer(TM1638, READKEY, 8);
//Now read back keyboard
for (cnt=0;cnt<4;cnt++)
{
*key_data=spi_xfer(TM1638, 0, 8); //clock out dummy byte
key_data++;
}
output_high(STB_PIN);
delay_us(1);
output_low(STB_PIN);
//Now need to switch back to write mode
dummy=spi_xfer(TM1638, AUTOINC, 8);
output_high(STB_PIN);
delay_us(1);
}
void main(void)
{
int8 display_data[16]= {nn,nn.......nn,nn};
//whatever you want to send to the display
int8 key_data[4]; //key data returned
init_MS();
delay_ms(100); //just allow things to settle
while (TRUE)
{
display_block(display_data, 5);
//Now the display data will have been written to the display
//Last value here is brightness 0 to 7.
read_keys(key_data);
//Now 'key_data' will contain the key value read back. You
//need to look at this, decide what you are going to do, and
//update the data if required.
delay_ms(500);
}
}
|
Now the data values you put into the 'display_data' array are the digits.
'digitToSegment' contains constant values for the standard digits.
So if you put digitToSegment[0] into display_data[0], it'd display '0'
for the first digit.
The key values returned are in reverse bit order.
Edited - just realised I had left 'key_data' being sent to the display routine
was originally going to combine the routines, but decided against this
had updated the routine itself, but not the call.
Last edited by Ttelmah on Thu Jan 03, 2019 10:04 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Thu Jan 03, 2019 8:15 am |
|
|
Mr. T has given you a GREAT starting point ! Just be sure to read the datasheet for YOUR display module. There are several 'variations' of them so you'll need to setup the 'configuration' as YOUR datasheet says.
Jay |
|
|
Arsenic
Joined: 23 Sep 2016 Posts: 13
|
|
|
cobaltBlue
Joined: 21 Apr 2024 Posts: 4
|
|
Posted: Sun Apr 21, 2024 3:16 am |
|
|
Hi,
since a while, I'm using the TM1638 for controlling commen kathode quad 7-segments displays.
In case of common anode, I understand the hardware connections are different, ( have to 'reverse' grids and segments ) but do I need to change software?
Tnx in advance! Marcel |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Sun Apr 21, 2024 5:06 am |
|
|
yes, I took a quik look at the datasheet and they show how for the digit '0'. I think it was on page #6....
Use that as a guide to create the 'table',each digit needs 5 bytes.
you'll have to send 5 bytes to the device instead on just one though. |
|
|
cobaltBlue
Joined: 21 Apr 2024 Posts: 4
|
|
Posted: Mon Apr 22, 2024 5:23 am |
|
|
Tnx,
that makes sence and gives me enough convidence!
I'm using mikroE's mikroPascal for AVR.
The common-kathode's work fine, I 'extracted' some code from a C-language ( I know barely C ) and use it in my pascal.
Have a bunch of common-anode's, gonna use them too!
Kind regards. Marcel
Last edited by cobaltBlue on Mon Apr 22, 2024 5:27 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Mon Apr 22, 2024 5:26 am |
|
|
Er.
So why are you asking here then. This is a forum for CCS C on the PIC.
Not for Pascal, or the AVR. Go to a forum for these..... |
|
|
cobaltBlue
Joined: 21 Apr 2024 Posts: 4
|
|
Posted: Mon Apr 22, 2024 5:29 am |
|
|
Ttelmah wrote: | Er.
So why are you asking here then. This is a forum for CCS C on the PIC.
Not for Pascal, or the AVR. Go to a forum for these..... |
Sorry, I wasn't aware, it was just a common question, don't mind the details.
Kind regards. |
|
|
cobaltBlue
Joined: 21 Apr 2024 Posts: 4
|
|
Posted: Mon Apr 22, 2024 5:29 am |
|
|
Temtronic, thanks again! Kind regards! |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|