Whats best way for a 10 bar bargraph on an LCD ?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All 8)

I've got a code that puts 10 ASCII blocks on display.
A counter goes from 0 - 99 (upcount) when reaching 10 the first block is shown on display, reaching 20 the next, etc. until 99 reached showing the 10th block. I can also use a table with the 10 bars (but not as blocks but as 0xff's, because 0xff is a block char)

incBar: ldi setPos, 16 ;start at digit 16
cpi bitCount, 10 ;if counter > 9,
brne up20
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up20: inc setPos ;up to next digit
cpi bitCount, 20 ;if counter > 19,
brne up30
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up30: inc setPos ;up to next digit
cpi bitCount, 30 ;if counter > 29,
brne up40
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up40: inc setPos ;up to next digit
cpi bitCount, 40 ;if counter > 39,
brne up50
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up50: inc setPos ;up to next digit
cpi bitCount, 50 ;if counter > 49,
brne up60
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up60: inc setPos ;up to next digit
cpi bitCount, 60 ;if counter > 59,
brne up70
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up70: inc setPos ;up to next digit
cpi bitCount, 70 ;if counter > 69,
brne up80
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up80: inc setPos ;up to next digit
cpi bitCount, 80 ;if counter > 79,
brne up90
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up90: inc setPos ;up to next digit
cpi bitCount, 90 ;if counter > 89,
brne up99
rcall ldSegDat ;load segment data
rcall updDig ;write segment
up99: inc setPos ;up to next digit
cpi bitCount, 99 ;if counter > 98,
brne exitInc
rcall ldSegDat ;load segment data
rcall updDig ;write segment
exitInc: ret

Does anyone know a better way ? Maybe one code which also can decrement the bargraph (now I use decBar, another routine for doing that)
Problem is every bar must be written in the right digit also, and when the bargraph goes down, it must remove a block, and put an empty on that position.
This works ok. What it easier, a routine or a table with the 10 bargraphs already stored in flash ? I've though about this, but reading from a table and compare takes the same time as a routine, I have to compare, I have to check the counter for 10, 20, 30 etc. No other way possible ?

Thanks 8)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Didja follow the suggestions I made to your 18 May posting about searching the Forum for "bargraph lee"? There was a simple loop posted about a year back for solid character bargraphs.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a repost of the code for a "stick" bargraph using user-definable characters for character LCDs. This gives 5 sticks per character resolution horizontally, and 7 sticks per character of resolution vertically. The program marches the bargraph every half second as written at the given clock speed.

It is written for CodeVision and uses CodeVision LCD routines.

/*********************************************
This program was produced by the
CodeWizardAVR V1.23.8 Standard
Automatic Program Generator
© Copyright 1998-2003 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro

Chip type           : ATmega8L
Program type        : Application
Clock frequency     : 7.372800 MHz
Memory model        : Small
Internal SRAM size  : 1024
External SRAM size  : 0
Data Stack size     : 256
*********************************************/

#include 

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x12
#endasm
#include 
#include 
#include 

bit tick;
bit bar_column;

unsigned char tock;
unsigned char dbuf[20];

// Timer 2 output compare interrupt service routine
interrupt [TIM2_COMP] void timer2_comp_isr(void)
{
// Place your code here
tick = 1;
}

flash unsigned char bar0[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000
};
flash unsigned char bar1[8] =
{
0b0000000,
0b0010000,
0b0010000,
0b0010000,
0b0010000,
0b0010000,
0b0010000,
0b0010000
};
flash unsigned char bar2[8] =
{
0b0000000,
0b0011000,
0b0011000,
0b0011000,
0b0011000,
0b0011000,
0b0011000,
0b0011000
};
flash unsigned char bar3[8] =
{
0b0000000,
0b0011100,
0b0011100,
0b0011100,
0b0011100,
0b0011100,
0b0011100,
0b0011100
};
flash unsigned char bar4[8] =
{
0b0000000,
0b0011110,
0b0011110,
0b0011110,
0b0011110,
0b0011110,
0b0011110,
0b0011110
};
flash unsigned char bar5[8] =
{
0b0000000,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char finger[8] =
{
0b0000100,
0b0000100,
0b0000100,
0b0000100,
0b0001111,
0b0001111,
0b0011111,
0b0011111
};

flash unsigned char column1[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0011111
};

flash unsigned char column2[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0011111,
0b0011111
};

flash unsigned char column3[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char column4[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0000000,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char column5[8] =
{
0b0000000,
0b0000000,
0b0000000,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char column6[8] =
{
0b0000000,
0b0000000,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char column7[8] =
{
0b0000000,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

flash unsigned char column8[8] =
{
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111,
0b0011111
};

void define_char (unsigned char flash * map, unsigned char code)
{
unsigned char command, looper;
command = (code<<3 | 0x40);	// write to CG ram
for (looper = 0; looper < 8; looper++)
	{
	lcd_write_byte (command++, *map++);
	}
return;
}

unsigned int i,j;
unsigned char looper;

void main(void)
{
// Some initialization of ports deleted

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 7.200 kHz (/1024) ==> 20ms.
// Mode: CTC top=OCR2
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x0F;
TCNT2=0x00;
OCR2=0x8F;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GICR=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x80;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;

// LCD module initialization
lcd_init(8);

// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/1024
WDTCR=0x1E;

WDTCR=0x0E;

// Global enable interrupts
#asm("sei")

lcd_gotoxy (0,0);
lcd_putsf ("Hello     world!");

define_char (bar0, 1);
define_char (bar1, 2);
define_char (bar2, 3);
define_char (bar3, 4);
define_char (bar4, 5);
define_char (bar5, 6);
define_char (finger, 7);

while (1)
      {
#asm("WDR");
	if (tick)
		{
		tick = 0;
		tock++;
		}

	if (tock > 1)  // 25 x 20ms. = 500ms.
		{
		tock = 0;

	if (bar_column)
		{
		// "column" bar graph
		lcd_gotoxy (0,1);
		sprintf (dbuf, "        ");

		j = i / 8;	// each block is 12.5% if 256
		for (looper = 0; looper < (unsigned char) j; looper++)
			{
			dbuf[looper] = 7;
			}
		j = i % 8;
		if (j)
			{
			dbuf[looper] = (unsigned char)j + 1;
			}
		lcd_puts (dbuf);
		i += 1;
		if (i > 63)
			{
			i = 0;

			define_char (bar0, 1);
			define_char (bar1, 2);
			define_char (bar2, 3);
			define_char (bar3, 4);
			define_char (bar4, 5);
			define_char (bar5, 6);

			bar_column = 0;
			}
		}
	else
		{
		lcd_gotoxy (0,1);
		sprintf (dbuf, "        ");
		if (i < 30)
			{
			dbuf[0] = 2;
			}
		else
			{
			j = i / 125; // each block is 12.5%
			for (looper = 0; looper < (unsigned char) j; looper++)
				{
				dbuf[looper] = 6;
				}
			j = ((i % 125) + 37) / 25;
			dbuf[looper] = j;
			}
		lcd_puts (dbuf);
		i += 10;
		if (i > 1000)
			{
			i = 0;

			define_char (column1, 0);
			define_char (column2, 1);
			define_char (column3, 2);
			define_char (column4, 3);
			define_char (column5, 4);
			define_char (column6, 5);
			define_char (column7, 6);
			define_char (column8, 7);

			lcd_gotoxy (0,1);
			sprintf (dbuf, "        ");
			lcd_puts (dbuf);

			bar_column = 1;
			}
		}

		} // end of "if (tock > xxx)"

      };
}

[Are attachments broken? How can I attach the file???]
Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Was it one of the allowed file types? See http://www.avrfreaks.net/phpBB2/attach_rules.php?f=3

-Colin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

c_oflynn wrote:
Was it one of the allowed file types? See http://www.avrfreaks.net/phpBB2/attach_rules.php?f=3

-Colin

Not that symptom. When I "Reply" as I am doing to your post I do not even get a spot to specify an attachment--just this text box.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Lee,

Maybe try another theme. I had problems with features not available and was told to try another theme. It worked. Not sure if this is the case this time though. Just a thought.

Regards,
Steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, yes, Steve--

I switched from subsilver to AVRFreaks format and the Add an Attachment box is below. I am attaching bargraph.c as posted above.

Lee

Attachment(s): 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bargraph's working (on a 1x16, and 2x16 LCD) 8)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does the 'flash' instruction do? Is it to keep constants in flash? How do I use it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wileur

Please start off a seperate thread as that is a seperate issue. If you are using the GCC please use the forum dedicated to the GCC.
Mike

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ohhhh. The bar goes sideways. I thought the bar was 1 to 7 rows of 5 dots in a char box....

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Ohhhh. The bar goes sideways. I thought the bar was 1 to 7 rows of 5 dots in a char box....

The program that I posted above does both horizontal & vertical using the user-defined characters & "rows of dots" for a little more res. if desired.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Ohhhh. The bar goes sideways. I thought the bar was 1 to 7 rows of 5 dots in a char box....

:idea:

Good idea, I can make a spectrum analizer making the bargraphs go up and down 5x8 pixels and 16 bands. (1x16 LCD as spectrum analizer)
But 8 pixels is not much..... 8 audio levels (or frequency levels)
I think you can even make one digit as a very tiny spectrum analizer.
5 band x 8 amplitudes :wink:

Ok, lets try a graphic LCD now :P
(after all I didn't use the code in the first post, but using 11 banks of 16 bytes (10 bargraph ASCII, 0xff=block or 0x20=empty)
Counter from 0 - 99, at 10, 20 , 30 , 40 etc. make the code update the display, with a much smaller routine.