View previous topic :: View next topic |
Author |
Message |
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
how use printf with 7-segmets leds? |
Posted: Wed Oct 27, 2004 10:24 am |
|
|
how use printf with 7-segmets leds? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 27, 2004 10:41 am |
|
|
Write a function that outputs chars to the seven segment. Then use this function instead of the LCD_PUTC() function |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Wed Oct 27, 2004 10:59 am |
|
|
[code]
void LCD_puts(char *str)
{
while (*str)
{
//put the char to the LCD
str++;
}
}
void main()
{
char str[20];
sprintf(str, "hello world");
LCD_puts(str);
}
[\code]
Trampas |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 27, 2004 12:17 pm |
|
|
The printf also supports a function as the first parameter which can handle outputing the char. |
|
|
N Guest
|
|
Posted: Wed Oct 27, 2004 3:31 pm |
|
|
You don't understand me
I have 7-segments "LED" , not LCD and need decemical number to
print. |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Wed Oct 27, 2004 3:53 pm |
|
|
I think we were answering the questions but you were not asking the right question. Is the question you are asking is if someone has code which takes a decmial number and display it on a 7 segment display?
If that is your question then it involves using a table and turning on the segments. I do not recall the orintation of the 7 segements but you do something like this:
Code: |
// first assume the 7 segments are the 7 LSBits in a BYTE.
//Now create an array where the first item in the array is the
// bits for the 7 segments that need to be on for a '0'
// digits[0]=0, digits[1]=1, etc
UBYTE digits[10]={0x3F, ..... };
//Now we want to print a number to 7 segement.
// assume that your segements are connected to the LSBits of PortA
PORTA=digits[0]; //this would cause the 7 segements to show a '0'
//so if we want a function we would
//assume one 7 segement display
void LED_out(UBYTE value)
{
if (value>10)
return; //do some better error checking here
PORTA=digits[value];
}
|
Now I hope that kind of answered this latest question. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 27, 2004 9:35 pm |
|
|
Quote: | You don't understand me
I have 7-segments "LED" , not LCD and need decemical number to
print. |
Nope, I understood you just fine. I cannot give you a function to output the data since I have no idea what your hardware is. Now you said you want to use the printf function. The implies that you are outputing more than one char or it would be silly to use a printf. The examples given will do this but you must supply the necessary function that outputs the single char. You have to know the hardware for that! |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Ok |
Posted: Thu Oct 28, 2004 9:19 am |
|
|
Ok I use 9-digits of 7-segments LED
and this header file all fine work, but maybe I can do this better and
faster ?Ask how ?
Code: |
void digit_select(int8 d)
{
switch (d) {
case 1: PORTC=0b00000000; PORTE=4; break;
case 2: PORTC=0b00000000; PORTE=2; break;
case 3: PORTC=0b00000000; PORTE=1; break;
case 4: PORTC=0b00100000; PORTE=0; break;
case 5: PORTC=0b00010000; PORTE=0; break;
case 6: PORTC=0b00001000; PORTE=0; break;
case 7: PORTC=0b00000100; PORTE=0; break;
case 8: PORTC=0b00000010; PORTE=0; break;
case 9: PORTC=0b00000001; PORTE=0; break;
}
}
void segment_select(int8 s,boolean point)
{
int8 plus=0;
if(point==TRUE) plus=128;
switch (s) {
case 0: PORTD=0b00111111+plus; break;
case 1: PORTD=0b00000110+plus; break;
case 2: PORTD=0b01011011+plus; break;
case 3: PORTD=0b01001111+plus; break;
case 4: PORTD=0b01100110+plus; break;
case 5: PORTD=0b01101101+plus; break;
case 6: PORTD=0b01111101+plus; break;
case 7: PORTD=0b00000111+plus; break;
case 8: PORTD=0b01111111+plus; break;
case 9: PORTD=0b01101111+plus; break;
}
}
void output_int32_to_LED(unsigned int32 D1)
{
ñhar icount;
// *********************************** Send Hungreds
icount=0;
while(D1>99)
{
D1 = D1 - 100;
icount++;
}
digit_select(3);
segment_select(icount,FALSE);
delay_ms(delay);
// *********************************** Send Tens
icount=0;
while(D1>9)
{
D1 = D1 - 10;
icount++;
}
digit_select(2);
segment_select(icount,FALSE);
delay_ms(delay);
// *********************************** Send last Unit's
digit_select(1);
segment_select(D1,FALSE);
delay_ms(delay);
PORTC=0;PORTE=0;
}
|
This only up to 999 but maybe more bigger - up to 32bit |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Thu Oct 28, 2004 10:30 am |
|
|
Userr,
Lets start with what you have..
Code: |
unsigned char digits[9]={
0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111 };
void segment_select(int8 s, boolean point)
{
int8 plus=0;
if(point) plus=128;
PORTD=digits[s] | plus;
}
//now we need to output the digits...
void output_LED(unsigned int32 data)
{
int8 numDigits;
int32 temp;
int8 i;
//first count number of digits
temp=data;
numDigits=0;
while(temp>9)
{
temp=temp/10;
numDigits++;
}
//assume there is always at least one digit, even if zero
numDigits++;
//Now we know how many digits there are
temp=data;
for (i=1; i<=numDigits; i++)
{
unsigned int8 s;
digit_select(numDigits);
s=(unsigned int 8)(temp-((temp/10)*10));
temp=temp/10;
segment_select(s);
}
}
|
I am not sure if I have a bug or not but you get the idea... Note that you should add error checking to the digit_select, and segment_select in case you send an invaild number, say s or d is 20...
Trampas
void putc( |
|
|
|