bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
row = 0xFF;
for (j=0x00; j<=0x0F; j++)
{
E1=0;
E2=1;
P1 = j;
P2 = row;
/* Output to LED Port */
for (i = 0; i < 10000; i++)
{ /* Delay for 10000 Counts */
wait (); /* call wait function */
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 const unsigned char flash font_7_6 [60]= { 0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1 0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2 0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3 0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4 0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char. }; //assume we want to display 572 (if only three chars) unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time for (x=0;x<3;x++) //3 characters { for (y=0;y<6;y++ ) //each character contains 6 cols. { E1=0; E2=1; P1=(x*6)+y; a=(y*10)+display[x]; P2 = font[a]; delay_ms(1); //best refresh rate 50 Hz = 20 ms, so for each col = 20/18 ms //call delay function or make it by yourself }; };
you must have all complete character database and insert it to your program.
this is just for the example, you can modify it for your real application.
const unsigned char flash font_7_6 [60]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
//assume we want to display 572 (if only three chars)
unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time
for (x=0;x<3;x++) //3 characters
{
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
E1=0;
E2=1;
P1=(x*6)+y;
a=(y*10)+display[x];
P2 = font[a];
delay_ms(1); //best refresh rate 50 Hz = 20 ms, so for each col = 20/18 ms
//call delay function or make it by yourself
};
};
Hope it can help you.
you must have all complete character database and insert it to your program.
this is just for the example, you can modify it for your real application.
const unsigned char flash font_7_6 [60]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
//assume we want to display 572 (if only three chars)
unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time
for (x=0;x<3;x++) //3 characters
{
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
E1=0;
E2=1;
P1=(x*6)+y;
a=(y*10)+display[x];
P2 = font[a];
delay_ms(1); //best refresh rate 50 Hz = 20 ms, so for each col = 20/18 ms
//call delay function or make it by yourself
};
};
Hope it can help you.
you must have all complete character database and insert it to your program.
this is just for the example, you can modify it for your real application.
const unsigned char flash font_7_6 [60]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
//assume we want to display 572 (if only three chars)
unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time
for (x=0;x<3;x++) //3 characters
{
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
E1=0;
E2=1;
P1=(x*6)+y;
a=(y*10)+display[x];
P2 = font[a];
delay_ms(1); //best refresh rate 50 Hz = 20 ms, so for each col = 20/18 ms
//call delay function or make it by yourself
};
};
Hope it can help you.
Yes. i am sorry, i forget change variable name.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 const unsigned char flash font_7_6 [60]= { 0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1 0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2 0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3 0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4 0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char. }; unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time unsigned char a; for (x=0;x<3;x++) //3 characters { for (y=0;y<6;y++ ) //each character contains 6 cols. { a=(x*6)+y; if (a<16) //only for 16 condition (0-15) { E1=0; //CS1 and CS2 of 74HC154 chip P1=a; a=(y*10)+display[x]; P2 = font_7_6[a]; delay_ms(1); //or delay_us(500); try the best view } }; };
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 const unsigned char flash font_7_6 [60]= { 0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1 0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2 0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3 0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4 0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char. }; unsigned char display [6] = 5,7,2,1,3,4; // we can modify value of this variable in run time unsigned char a; for (x=0;x<6;x++) //6 characters { for (y=0;y<6;y++ ) //each character contains 6 cols. { a=(x*6)+y; if (a<16) //only for 16 condition (0-15) { E1=0; //CS1 and CS2 of 74HC154 chip 1 E2=1; //CS1 and CS2 of 74HC154 chip 2 P1=a; a=(y*10)+display[x]; P2 = font_7_6[a]; delay_ms(1); //or delay_us(500); try the best view } else { if (a<32) { E1=1; //CS1 and CS2 of 74HC154 chip 1 E2=0; //CS1 and CS2 of 74HC154 chip 2 P1=a; a=(y*10)+display[x]; P2 = font_7_6[a]; delay_ms(1); //or delay_us(500); try the best view }; }; }; };
I'm sorry, the mistake comes from when we want to use 18 cols since 74HC154 only can support 16 cols. Please try this.
const unsigned char flash font_7_6 [60]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
unsigned char display [3] = 5,7,2; // we can modify value of this variable in run time
unsigned char a;
for (x=0;x<3;x++) //3 characters
{
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
a=(x*6)+y;
if (a<16) //only for 16 condition (0-15)
{
E1=0; //CS1 and CS2 of 74HC154 chip
P1=a;
a=(y*10)+display[x];
P2 = font_7_6[a];
delay_ms(1); //or delay_us(500); try the best view
}
};
};
if the code above works, now we can use two 74HC154 chips to get 32 cols display. Please try this.
const unsigned char flash font_7_6 [60]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
unsigned char display [6] = 5,7,2,1,3,4; // we can modify value of this variable in run time
unsigned char a;
for (x=0;x<6;x++) //6 characters
{
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
a=(x*6)+y;
if (a<16) //only for 16 condition (0-15)
{
E1=0; //CS1 and CS2 of 74HC154 chip 1
E2=1; //CS1 and CS2 of 74HC154 chip 2
P1=a;
a=(y*10)+display[x];
P2 = font_7_6[a];
delay_ms(1); //or delay_us(500); try the best view
}
else
{
if (a<32)
{
E1=1; //CS1 and CS2 of 74HC154 chip 1
E2=0; //CS1 and CS2 of 74HC154 chip 2
P1=a;
a=(y*10)+display[x];
P2 = font_7_6[a];
delay_ms(1); //or delay_us(500); try the best view
};
};
};
};
replace code :
P1=a;
with :
P1= 15 -a;
or change direction of 74HC154 output cable connection (because i see you just make it on breadboard :smile: )
//0 1 2 3 4 5 6 7 8 9
0x3E, 0x00, 0x23, 0x42, 0x0C, 0x72, 0x1E, 0x40, 0x36, 0x31, //data for col 1
0x45, 0x21, 0x45, 0x41, 0x14, 0x51, 0x29, 0x47, 0x49, 0x49, //data for col 2
0x49, 0x7F, 0x49, 0x49, 0x24, 0x51, 0x49, 0x48, 0x49, 0x49, //data for col 3
0x51, 0x01, 0x49, 0x59, 0x7F, 0x51, 0x49, 0x50, 0x49, 0x4A, //data for col 4
0x3E, 0x00, 0x31, 0x66, 0x04, 0x4E, 0x46, 0x60, 0x36, 0x3C, //data for col 5
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //empty, space between each char.
0x23
0x45
0x49
0x49
0x31
23 45 49 49 31 (hex)
bit
7 0 0 0 0 0
6 0 1 1 1 0
5 1 0 0 0 1
4 0 0 0 0 1
3 0 0 1 1 0
2 0 1 0 0 0
1 1 0 0 0 0
0 1 1 1 1 1
0xFF
0x80
0x80
0xFE
0x03
0x03
0x03
0xFE
I mean, my post contains 7x5 format, but you can change it to 8x8 format and why number 2 is broken because you still use 16 cols program and to display 3rd character at least we have to use at least 18 cols, so use 32 cols program at my last post. Please try it.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 for (x=0;x<6;x++) //6 characters { for (y=0;y<6;y++ ) //each character contains 6 cols. { a=(x*6)+y; if (a<16) //only for 16 condition (0-15) { E1=0; //CS1 and CS2 of 74HC154 chip 1 E2=1; //CS1 and CS2 of 74HC154 chip 2 P1=a; a=(y*10)+display[x]; P2 = font_7_6[a]; delay_ms(1); //or delay_us(500); try the best view } else { if (a<32) { E1=1; //CS1 and CS2 of 74HC154 chip 1 E2=0; //CS1 and CS2 of 74HC154 chip 2 P1=a; a=(y*10)+display[x]; P2 = font_7_6[a]; delay_ms(1); //or delay_us(500); try the best view }; }; }; };
Finally, i make a simulation on proteus, and it works.
Here i attach compressed file. I use MikroC Pro 2.2 and proteus 7.8. If you don't have proteus, I also include it with schematic (pdf) and screenshot (gif).
View attachment 69566
If I want 8x8 i replace all the 6 to 8 ?
for (y=0;y<6;y++ ) //each character contains 6 cols.
{
a=(x*6)+y;
Yes. You're right. And you also need to build your own 8x8 font format. On my post, 7x6 format, only 6 lines at font array. So, you have make 8 lines at font array. Next, you have include all characters (letter, sign, number) to font array.
Good luck.
Must I complete 0-9 font in 8x8 to make it work ?Yes. You're right. And you also need to build your own 8x8 font format. On my post, 7x6 format, only 6 lines at font array. So, you have make 8 lines at font array. Next, you have include all characters (letter, sign, number) to font array.
Good luck.
code unsigned char font[80]=
{
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C, //data for col 5
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //data for col 6
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //data for col 7
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
for (x=0;x<3;x++) //3 characters
{
for (y=0;y<8;y++ ) //each character contains 8 cols.
{
a=(x*8)+y;
If you want to display only one character, change the lineI tried with character 5 only, but it didn't show up 5, only all on in two matrix may be I need to enter more than one character ?
Yes. But, if your font data only for five characters (0-4), you must change the lineMust I complete 0-9 font in 8x8 to make it work ?
can I do like this ?
....
I saw a strange result...
code unsigned char font[80]=
{
//0 1 2 3 4 5 6 7 8 9 10
0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31,0x00, //data for col 1
0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49,0x00, //data for col 2
0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49,0x00, //data for col 3
0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A,0x00, //data for col 4
0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C,0x00, //data for col 5
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, //data for col 6
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, //data for col 7
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char.
};
Ok, thanks for the advise..If you want to display only one character, change the line
for (x=0;x<3;x++) //3 characters
with
for (x=0;x<1;x++) //1 characters
Yes. But, if your font data only for five characters (0-4), you must change the line
a=(y*10)+display[x];
with
a=(y*5)+display[x];
or if you have complete font (ascii 0 to 127), you have to replace this line with
a=(y*128)+display[x];
Your code is fine, maybe the problem is when you add font col 6 and 7 with 0xFF, so there is two vertical lines after the each number.
Or maybe you need to inverse the output as you did : P3 = ~font[a];
Or maybe you forget to change array size to 3 or more : unsigned char display[3]={5,7,2};
By the way, have you tested my attachment? Does it work with your hardware? This step has to be success before we go to next step.
About displaying 1 char, 3 char or others, my suggestion, just fix your program to the max value (for your current hardware = 4 characters in 8x8 font) and add font data with space character.
Code:code unsigned char font[80]= { //0 1 2 3 4 5 6 7 8 9 10 0x3E,0x00,0x23,0x42,0x0C,0x72,0x1E,0x40,0x36,0x31,0x00, //data for col 1 0x45,0x21,0x45,0x41,0x14,0x51,0x29,0x47,0x49,0x49,0x00, //data for col 2 0x49,0x7F,0x49,0x49,0x24,0x51,0x49,0x48,0x49,0x49,0x00, //data for col 3 0x51,0x01,0x49,0x59,0x7F,0x51,0x49,0x50,0x49,0x4A,0x00, //data for col 4 0x3E,0x00,0x31,0x66,0x04,0x4E,0x46,0x60,0x36,0x3C,0x00, //data for col 5 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, //data for col 6 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, //data for col 7 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //empty, space between each char. };
When we want to display _ _ _ 8, we only need to fill the variable with 10, 10, 10, 8.
Change all 10 in the program with 11 (because now our font data contains 11 character, 0 - 10)
a=(y*10)+display[x]; >>> a=(y*11)+display[x];
code unsigned char font[32]=
{
0x3C , 0x3C , 0x3C , 0x3C
0x42 , 0x42 , 0x42 , 0x42
0x81 , 0x81 , 0x81 , 0x81
0x0E , 0x0E , 0x0E , 0x0E
0x10 , 0x10 , 0x10 , 0x10
0x60 , 0x60 , 0x60 , 0x60
0xFF , 0xFF , 0xFF , 0xFF
}
code unsigned char font[8]=
{
0xFF,
0x80,
0x80,
0xFE,
0x03,
0x03,
0x03,
0xFE
}; //character 2
unsigned char display [1] = {1}; // we can modify value of this variable in run time
for (x=0;x<1;x++) //1 characters
//for (x=0;x<3;x++) //3 characters
{
for (y=0;y<8;y++ ) //each character contains 8 cols.
//for (y=0;y<6;y++ ) //each character contains 6 cols.
{
//a=(x*6)+y;
a=(x*8)+y;
if (a<16) //only for 16 condition (0-15)
{
E1=0;
P1=15-a;
//a=(y*10)+display[x];
a=(y*1)+display[x];
P2 = ~font[a];
delay_100(); //best refresh rate 50 Hz = 20 ms, so for each col = 20/18 ms
//call delay function or make it by yourself
}
else
{
if (a<32)
{
E1=1; //CS1 and CS2 of 74HC154 chip 1
E2=0; //CS1 and CS2 of 74HC154 chip 2
P1=15-a;
//a=(y*10)+display[x];
a=(y*1)+display[x];
P2 = ~font[a];
delay_100(); //or delay_us(500); try the best view
};
};
};
};
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?