PDA

View Full Version : LCD BARgraphs

Darrel Taylor
- 9th September 2005, 02:15
LCD BARgraphs
LCDbar_INC.bas
is an Include file that makes it easy to create BARgraphs on your LCD display.

Features:
Can be placed anywhere on the screen. Can be any width (whole characters) Can be scaled anywhere between 0 and 32768. Three styles to choose from.&nbsp; {lines, boxed, blocks} Just 1 Command does it all. (Well, sort of)

@ BARgraph Value, Row, Col, Width, Range, Style

Value: The Value of the BARgraph (0 to Range).If Range = 100 and Value is 50, then
half of the BARgraph will be filled in. Value MUST be a WORD sized variable¹

Row: LCD Row to place the BARgraph (1 to 4) can be either a constant or a
variable¹.

Col: LCD Column to place the BARgraph (0 to LCDsize² - 1) can be either a constant
or a variable¹.

Width: Width of the BARgraph in charaters. (1 to LCDsize²) can be either a constant
or a variable¹.

Range: The "full-scale" range of the BARgraph (0 to 32768) MUST be a constant.
Variables will not work here.

Style: Selects which Style will be used for the BARgraph (lines, boxed, blocks) can
be either a constant or a variable¹.

Note ¹ - Variables must be preceeded with a
underscore. ie. _Temperature
Note ² - LCDsize is the number of Chars in 1 line of
the LCD, for "4x16" it's 16

Added 10/18/05 - If using a 4x20 display, you can use this define to let the program know the addressing is different. &nbsp; Thanks, CocaColaKid!
DEFINE LCD4X20 1

Darrel Taylor
- 9th September 2005, 02:44
This is so simple to use. :)

Here's an example of a BARgraph that follows an A/D input.
http://www.darreltaylor.com/files/BAR_Example1.gif

; Initialize your hardware and LCD first.

INCLUDE &quot;LCDbar_INC.bas&quot; ' Include the BARgraph routines

Value VAR WORD ' Must be a WORD even though AD is 8bit

LCDOUT $FE, 1 ' Clear Screen Loop1: ADCIN 0, Value LCDOUT$FE,2,&quot;Value=&quot;,DEC Value,&quot; &quot;
; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 2, 0, 16, 255, lines
GOTO Loop1

Darrel Taylor
- 9th September 2005, 03:45
This is just like the previous example except that it places both the Value and the BAR on the same line.
http://www.darreltaylor.com/files/BAR_Example2.gif

; Initialize your hardware and LCD first.

INCLUDE &quot;LCDbar_INC.bas&quot; ' Include the BARgraph routines

Value VAR WORD ' Must be a WORD even though AD is 8bit

LCDOUT $FE, 1 ' Clear Screen Loop1: ADCIN 0, Value LCDOUT$FE,2,DEC Value,&quot; &quot;
; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 1, 4, 12, 255, lines
GOTO Loop1

Don Mario
- 3rd October 2005, 15:47
Very good job, Darrel ! I like very much ! But you forget the "vertical bargraph" !

Don Mario

Acetronics2
- 3rd October 2005, 17:10
Very good job, Darrel ! I like very much ! But you forget the "vertical bargraph" !

Don Mario

Hi, DON

Just turn your LCD 90° cckw !!!

hi,hi,hi ...

Alain

Don Mario
- 3rd October 2005, 17:36
Thanks ! It's a very good advice ! But I'm seriuos ! Don't forget the vertical bar !

Don Mario

Acetronics2
- 3rd October 2005, 17:58
Here, a Graphic LCD might be necessary ... ( I've tried a 4x20 : result is not so good due to space between the lines )

And do not forget the processor to drive the graphic LCD, to have a simple handling like LINE x1,y1,x2,y2 ... BOX x1,y1,x2,y2 CIRCLE x,y,r .... etc,etc

not so easy ... even with 8k memory , 20 Mhz and Assembler !!!

Alain

ta1dr
- 4th October 2005, 15:22
hi Darrel
thanks for very nice projects
I want to use but I use Proton Suit (crownhill I am registered user) I can convert it but I didn't understand this row how can I convert PDS

BARtemp = BAR_value * BAR_width is ok
BARtemp = DIV32 BAR_range is ok
'*************************************************
Remainder = R2 but not ok how can I calculate
remender from div32 command

regards
ahmet/TURKEY

Darrel Taylor
- 6th October 2005, 20:36
ta1dr

Don Mario

Attaboys followed by wantittodo's cancel each other out.
And, this is the Code Examples forum. Not the Please make your program do what I want forum.

I hate being rude, but come on, use the brain a little. I've given everything you need to be able to easily create your own vertical bargraph's. All you need to do is think and apply.
<br>

Don Mario
- 7th October 2005, 11:03
DARREL TAYLOR,

I don't say "Make me a program" !
I say "You forget vertical bargraph" for a coplete "demo software"
That's my opinion. I don't need your software ! I make my own !

Don Mario

Darrel Taylor
- 7th October 2005, 19:32
I make my own !
Perfect!

That's what we do here. Offer examples and assistance, so that others can write thier own programs. But the real question is, What will you do with your program when you're finished.

Will you look at it and say, Hey that's pretty good, I'm not giving it out to anyone for free. Or, will you post it here for others to look at and say it's not good enough.

I guess time will tell.
<br>

CocaColaKid
- 18th October 2005, 20:39
Darrel,

I just modified you include file by replacing the word "LCDOut" with "debug" and it almost appears to work. The problem though is that I'm using a 4x20 LCD and it appears the program thinks there is a 16 character LCD pluggeding in because it starts line 2 at postion 17 and starts line 4 at position 17 on line 2. Any thoughts one this?

Darrel Taylor
- 19th October 2005, 03:28
I knew that was going to come back and bite me in the assparagus.

With 4x20 displays, line 3 and 4 start at $94 and$D4. I was going to add an option that made the change for you, but forgot about it.

In the ShowBAR: routine, you can change this line ...
<pre><b> LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp</b></pre>to this ... <pre><b> LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp</b></pre>and it should work better. Sorry!
<br>

Darrel Taylor
- 19th October 2005, 04:08
Or, better yet ... there's this
@ ifdef LCD4X20
LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp @ else LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
@ endif

Then in your main program you can just do this when using a 4x20 LCD
DEFINE LCD4X20 1

I've also made the change to the original attachment above.

Thanks for pointing it out CocaColaKid!
<br>

CocaColaKid
- 19th October 2005, 15:28
Glad I could be of service since you've done such a nice job with the code the least I could do was help debug it :)

crematory
- 11th January 2006, 01:40
Hi Darrel

Can you please make Vertical_LCDBar.INC like that Horizontal_LCDBar.INC.

Darrel Taylor
- 11th January 2006, 04:55
Like Alain said way up there.

Due to the spaces between the characters landing on an Odd number, vertical bargraphs on LCD displays don't work very well.

Bummer!
<br>

Acetronics2
- 11th January 2006, 12:53
Hi, Darrel

Could you explain those lines to me :

ASM
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM

(From LCD_Bar.inc ) ...

My MPLAB 7.30 seems not to understand it ( comes in red ) ... nor me !!!

Alain

Darrel Taylor
- 11th January 2006, 19:37
Hi Alain,

Those just assign some unique ID's to the words lines, boxed and blocks.

I used numbers outside the 16-bit range of PBP just to minimize confusion for myself. Then when PBP uses the number, all it sees is 1, 2 or 3.

I haven't bothered downloading the latest MPLAB so I hadn't seen any problem yet. But it should be ok to just make them 1, 2 and 3

ASM
lines = 1 ; Define the Styles
boxed = 2
blocks = 3
ENDASM

<br>

crematory
- 14th January 2006, 17:20
Hi Acetronics

I had the same problem, when you use the macro, be careful about the letters upper and lower case thingy, I mean Blocks and blocks are different when you use MPASM. Darrel wrote blocks in LCDbar_INC file in the difintions, so you have to use blocks, not Blocks in the macro, the same applies for lines and boxed. This worked fine for me.

For example:

' In LCDbar_INC file you will find the following definitions that darrel wrote:
ASM
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM
' No need to change them nay way...

In your code, you will use this macro:
; BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _VOL_L, 2, 0, 20, 255, Blocks ' Doesn't work

; BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _VOL_L, 2, 0, 20, 255, blocks ' Works fine

In order to change to Blocks, Lines, and Boxed. Instead of block, lines, and boxed, you have to change the following in LCDBar_INC file:

ASM
Lines = 0x10000001 ; Define the Styles
Boxed = 0x10000002
Blocks = 0x10000003
ENDASM

And this too:

if ((Style >= Lines) & (Style <= Blocks)) ; Is Style a valid constant ?
MOVE?CB Style, _BAR_style
else ; NO, treat it like a variable
MOVE?BB Style, _BAR_style
endif

After that you can use Blocks, Lines, and Boxed in your code macro.

Darrel Taylor
- 14th January 2006, 19:47
Seems like a lot of work to rewrite a program to use a different Case, when you can just turn off case sensitivity for MPASM, and use any case.

For MicroCode Studio Plus:

From View | Picbasic Options... | Assembler Tab and Options tab
uncheck the "Case sensitive" Checkbox
Press OK

The Microchip MPASM checkbox must be checked to see the Case option.

For other editors, or dos:

Add -c to the MPASM command line.
<br>

crematory
- 14th January 2006, 20:43
Hi darrel

I could have said that, as a matter of fact, being careful about letter cases while writing a code, prevented me of throwing that note about "uncheck the Case sensitive Checkbox", thats all darrel,

Christopher4187
- 10th July 2006, 03:32
I have never used an include file other than the ones provided with PBP. I am getting an error trying to load the include file from Darrel. The only thing I can think of is that I have it in the wrong place. Can someone tell me where I have to put it?

Thanks,

Chris

Darrel Taylor
- 10th July 2006, 03:37
What does the error say?
<br>

Christopher4187
- 10th July 2006, 03:39
The message says:

"WARNING: Unable to open INCLUDE file LCDBAR_INC.BAS."

Darrel Taylor
- 10th July 2006, 03:45
The file above is renamed with an extension of .txt, because the forum won't let you upload .bas files. So make sure you rename it to just LCDBAR_INC.BAS

Place the file in the same folder as the main program, and you should be good to go.
<br>

Christopher4187
- 10th July 2006, 03:52
I tried everything and it still doesn't work. I have it in the same folder as the main program. I'm stumped.

mister_e
- 10th July 2006, 04:34
can you post a whole screenshot?

It's working for me.

EDIT: i don't know if it's revelant but be sure your program path is short I.e C:\PBPprog\Project1

Melanie
- 10th July 2006, 08:51
I thought PBP (especially when run through a DOS window) couldn't handle filenames greater than 8 characters...

Example 1...

PBP -p16F628 12345678 -v

The above WILL comple, the example below will NOT...

PBP -p16F628 a12345678 -v

Further... here's a gotcha...

Example 2.

PBP -p16F628 12345678 -v

Will compile the file 12345678.bas happilly...

Example 3.

PBP -p16F628 123456789 -v

Will NOT compile the expected file 123456789.bas but instead will access the file at Example 2 and compile that instead!

Darrel Taylor
- 10th July 2006, 09:47
Then you would use...

<pre>PBPW -p16F628 123456789AndAFewMore.bas -v</pre>or use MCSP, it does it automatically.

But since you bring up the command line option, there's a few things that could be a possible problem. Path settings, current directory ...

Christopher,
Are you compiling by command line, or an IDE?
<br>

Christopher4187
- 10th July 2006, 10:24
Here is a screenshot of my error. I took out the LCD stuff just to make sure that wasn't causing the problem.

Darrel,

I'm not sure how to answer your question as I still new to PBP. In the screenshot is how I complie programs.

Chris

Darrel Taylor
- 10th July 2006, 10:37
If you click on the Include file in the Code Explorer on the left side of the screen, does it pull up the file? Or does it create a new file?

If it creates a new file, then the Include file is in the wrong folder.

It should be in the same folder as "Bar Graph.bas".
<br>

Christopher4187
- 11th July 2006, 01:15
Darrel,

I got it, thanks for the help. The problem was that both files were saved as .pbp files. All of my programs are saved the same way and I have never had an issue.....until now. So, that part works but now I have another problem.

I have a 2X16 LCD set up on a development board. I have one simple LCD program and that works fine. I put the same LCD commands into the bargraph program and it doesn't work. I can see weird charecters displayed on the first line but nothing on the second line. Within those charecters I do see numbers every now and again and when I turn the pot, I can see the value change so I know it's functional but just not displaying correctly. Here is the program:

; Initialize your hardware and LCD first.
define osc 20

' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 2
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 3
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 100
'This setup will tell PBP a 2-line LCD is connected in 4-bit mode with the data bus on the
'top 4 bits of PORTB, Register Select on PORTB.1, and Enable on PORTB.0.

INCLUDE "LCDbar_INC.bas" ' Include the BARgraph routines

Value VAR WORD ' Must be a WORD even though AD is 8bit

LCDOUT $FE, 1 ' Clear Screen pause 500 Loop1: ADCIN 2, Value LCDOUT$FE,2,"Value = ",DEC Value," "

; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 2, 0, 16, 255, lines

GOTO Loop1

Like I said, these LCD commands were copied word for word from another known program. Any ideas?

Thanks again for the help.

Chris

Darrel Taylor
- 11th July 2006, 01:32
The DEFINEs don't match the comments. Might be the prob.

Defines show RS on PORTB.2, and Enable on PORTB.3

<pre>'This setup will tell PBP a 2-line LCD is connected in 4-bit mode with the data bus on the<br>'top 4 bits of PORTB, Register Select on PORTB.1, and Enable on PORTB.0.</pre>

Christopher4187
- 11th July 2006, 01:56
Now, I am really confused. How come this program worked but the other one didn't?

DEFINE OSC 20
INCLUDE "LCDbar_INC.bas" ' Include the BARgraph routines
' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 2
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 3
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 100.

Value VAR WORD ' Must be a WORD even though AD is 8bit
pause 1000
LCDOUT $FE, 1, " " loop1: adcin 2,value LCDOUT$FE,2,"Value = ",DEC Value," "

; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 2, 0, 16, 255, lines

goto loop1

The only thing I adjusted was the pause commands and I moved the include file to the top of the program. I'm happy that it's working but I'd like to know for future reference incase it happens again. Thanks for the help Darrel.

Darrel Taylor
- 11th July 2006, 02:13
You probably have an LCD that is very slow starting up and requires more than 500 ms before receiving it's first command.

Being that you also have DEFINE LCD_DATAUS 100, it's seems reasonable.
Most LCD's are happy with LCD_DATAUS 50, and only 250 ms power-up delay. But there are some that aren't.

Try leaving the INCLUDE where it was, with the longer pauses. Just to see what happens.
<br>

Christopher4187
- 11th July 2006, 03:17
Well, after searching for a while, I found the problem and it's strange. At the tops of both programs, look at the OSC commands. One is in CAPS and the other isn't. I guess it has to be in CAPS or PBP won't know what it is. I wonder why it doesn't give you an error when compling?

mister_e
- 11th July 2006, 03:38
It's been already mentioned a lot of time since the Forum birth.

DEFINEs must be WRITTEN AS STATED in the manual. Case not, they will never be considered by the compiler

Darrel Taylor
- 11th July 2006, 03:42
:) Ha, that's funny. Didn't even see it. :)

>> I wonder why it doesn't give you an error when compling? <<

You can DEFINE almost anything you want

<pre>DEFINE GreatGoogly Moogly</pre>But it only has an effect if it matches up with something the program is expecting to see.
And, when using MPASM the case has to match too.

Well, now that you've got things going, I hope the BarGraphs work out for you.
<br>

mister_e
- 11th July 2006, 03:45
Yup, i guess the MPASM AND PM IFDEF can't be bypassed like Variable and Labels.

vbcoder
- 8th December 2006, 19:11
Thanks Darrel. It gives me an amazing look for my project. Can you tell me if I use 2x16 Alpha LCD. How many bars that I can get per line?

Darrel Taylor
- 8th December 2006, 19:25
Hi vbcoder,

You're welcome.

There are 3 bars per character, so you can get 48 per line on a 2x16.
<br>

zaferakbay
- 20th June 2007, 20:33
gerçekten güzel uygulama teşekkür ediyorum.

zaferakbay@hotmail.com

TÜRKİYE

mister_e
- 20th June 2007, 23:00
http://www.picbasic.co.uk/forum/showpost.php?p=40298&postcount=9

Darrel Taylor
- 20th June 2007, 23:47
Me neither!

But I did catch the "Thank" part.
So in case that's what it was...

You're welcome zaferakbay.
Hope you get good use out of it.
<br>

mister_e
- 21st June 2007, 00:07
Ok let's try in split words..
gerçekten = Actually, honestly,indeed, literrally, positively,properly,really,simply, truly

güzel = attractive beautiful, bonny, bracing, cherub,comely,dreamy,elegant,enjoyable,fair,fine,g allant,glorious,graceful,grand,handsome,lovely,nic e...

uygulama = application, execution,implementation,practice

teşekkür = *** can't be found *****

ediyorum = *** can't be found ****

Darrel Taylor
- 21st June 2007, 02:21
hmmm,

positively glorious application
properly elegant implementation
honestly beautiful execution
really dreamy practice

Hey, works for me :D

As long as those last 2 words aren't
Stink, Pile or S___ :eek:
<br>

Pic_User
- 21st June 2007, 03:03
Not quite “teşekkür ediyorum”

teşekkür ederim = thank you
http://cali.arizona.edu/maxnet/tur/nalan1/foo00005.htm

WordReference.com Language Forums
"Teşekkür ederim" (= I thank you) is still widely used in Turkey

Language Forums, maybe we could post PICBasic in their forum and they could come looking for us!:D

Darrel Taylor
- 21st June 2007, 06:36
Great. Thanks P.U.

Now that we know what he said, I can give a better reply ...

zaferakbay,

&nbsp; Rica ederim. :)
&nbsp; (You're Welcome)
<br>

Acetronics2
- 21st June 2007, 08:57
Hi vbcoder,

You're welcome.

There are 3 bars per character, so you can get 48 per line on a 2x16.
<br>

Hi, Darrel

I know it's YOUR Bargraph example ... but 5 bars can be used with "general programming" ...

May be a Typo from yours ???

Translated and modified from a Stamp application :

' This program generates a horizontal bargraph
' with a 2x16 Intelligent LCD Display HD 44780 / KS 0062.

DEFINE OSC 20
DEFINE LCD_EBIT 1

Led var Portb.5
Scale var Portb.2

' ** Variables **

BarVal Var Word ' Value to be graphed.
Bars Var Byte ' Number of full |||/||||| bars to draw.
Balance Var Byte ' Balance left after all |||/|||||s are drawn.
Padding Var Byte ' Number of spaces to fill width.
Balf Var Byte ' Is a 'Balance' character needed? (1=yes, 0=no).
Temp Var Byte
Fullbar Var Byte
Maxbar Var Byte

' ** Constants **

BWdth Con 16
Basebar Con 0 ' ASCII value of 0 bar (blank).

IF NOT Scale THEN

Fullbar = 3
ELSE
Fullbar = 5

ENDIF

Maxbar = BWdth*Fullbar ' Max bar counts.

' Transfer the bit patterns that make up the bars into the LCD's CGRAM.
' The vertical bars are made up of 8 identical bit patterns

' A | bar consists of 0, 5 times $10, 0 ' A || bar consists of 0, 5 times$14, 0
' A ||| bar consists of 0, 5 times $15, 0 ' We repeat each pattern 8 times. IF Fullbar = 3 THEN Lcdout$FE,64,0,0,0,0,0,0,0,0 'Motif 0
Lcdout $0,$10,$10,$10,$10,$10,$10,$0 'Motif 1
Lcdout $0,$14,$14,$14,$14,$14,$14,$0 'Motif 2
Lcdout $0,$15,$15,$15,$15,$15,$15,$0 'Motif 3

ELSE

Lcdout $FE,64,0,0,0,0,0,0,0,0 'Motif 0 Lcdout$0,$10,$10,$10,$10,$10,$10,$0 'Motif 1 Lcdout$0,$18,$18,$18,$18,$18,$18,$0 'Motif 2 Lcdout$0,$1C,$1C,$1C,$1C,$1C,$1C,$0 'Motif 3 Lcdout$0,$1E,$1E,$1E,$1E,$1E,$1E,$0 'Motif 4 Lcdout$0,$1F,$1F,$1F,$1F,$1F,$1F,$0 'Motif 5 ENDIF Goto OverBargraph ' The value in 'Bar_Val' is displayed as a horizontal bar graph ' from the current cursor location with a total width (in characters) set by the WIDTH constant. ' Each character position can represent a maximum value of 3/5 using the Fullbar character |||. ' The routine calculates how many full bars to use by dividing by 3/5. ' If there is a remainder after dividing by 3/5, the routine joins on a partial-bar character ' ( | or || or ||| or |||| or ||||| ) to represent the balance. ' Then it pads out the remainder of the bar width with spaces to erase any leftover bars Bargraph: Bars = (BarVal min MaxBar) / Fullbar ' One full bar for each 3/5 graph units. Balance = (BarVal min Maxbar) //Fullbar ' Balance is the remainder after a division by 3/5. Balf = Balance min 1 Padding = BWdth - (Bars + Balf) ' Number of spaces to fill bar width. LCDOut Rep Fullbar\Bars,Rep (Balance + Basebar)\Balf,Rep " " \Padding Return OverBargraph: For BarVal = 0 to Maxbar Lcdout$FE,$80 Gosub Bargraph Lcdout$FE, $C0, #BarVal," " Pause 300 Next BarVal Alain Ioannis - 21st June 2007, 09:06 By the way, talking about the great piece of code. I am trying to make it work on a logarithmic scale, to measure audio levels from -40 to +6dbm (-40db=20mV, 0db=0,775V rms at 600 ohm and +6db=2V). As it can be seen it is a very large dynamic region. For a few steps it's OK to do it with a lookdown, but if the display is 20 characters wide and with 3 bars each, total 60 steps, a table is slow. So a computational method is to be found. Testing the suggestions of Tracy Allens at www.emesys.com. I do not fully understand what he is doing there though. Any other ideas welcome. Ioannis Darrel Taylor - 21st June 2007, 09:46 Hi Alain, Cool, more examples. I tried using all 5 bars when I wrote it, but was never happy with the results. There seemed to be pauses, jumping or something missing (depending on which way I tried to do it). All due to those darn spaces between the characters. Had the same problem trying Vertical Bars. But I'll fire up your example and see if it looks any better. If it works better, I'm going to hate myself for losing to a Basic Stamp program. :D <br> Acetronics2 - 21st June 2007, 09:54 Hi, Ioannis I just wrote a 255 values lookup table ( convert a LOG pot to lin response ) ... for Malc-c electric train control. did not take more than 3 minutes to load it ... I use a small old Casio FX-880P personnal Computer ... programmed in BASIC ... WOW !!! You also can use a GWBasic little program on your computer ( on the W98 CD Goldies ...) Other solution is to create an Excel application writing in a window the LOOKUP values, separated by their commas ... and just paste it into the editor. like this one : http://www.electronic-engineering.ch/microchip/software/tablegenerator.html The third solution is to create a "Lookup file" with Excel ... and INCLUDE it at the place pointed at by PbP ... You'll discover here PbP really wastes a lot of room ... ( no, no ...Darrel, not on the head ... ) much,much better ( and really simple ) to write it in assembler !!! ( if you need an ASM example ... no Pb !!! ) Regards Alain Darrel Taylor - 21st June 2007, 09:55 Ioannis, Interesting problem. I looked at the emesys site, and the idea of using NCD/DCD for the log function is really interesting (and I think, workable). I'll see what me and Excel can come up with. (might take a few days, so don't wait if you're in a hurry). Are those voltages what the PIC is seeing? -40db = 20mv etc. Or is that before an RMS-DC conversion? And if not, what does the PIC see? <br> Ioannis - 21st June 2007, 10:30 Hi, Ioannis I just wrote a 255 values lookup table ( convert a LOG pot to lin response ) ... ... I use a small old Casio FX-880P personnal Computer ... programmed in BASIC ... WOW !!! Alain Hmm, a log pot to table? Interesting idea! I have such a Casio too (the PB-410 model). It helped a lot in the past! Ioannis, Interesting problem. I looked at the emesys site, and the idea of using NCD/DCD for the log function is really interesting (and I think, workable). ... Are those voltages what the PIC is seeing? -40db = 20mv etc. Or is that before an RMS-DC conversion? And if not, what does the PIC see? <br> Thanks Darrel. No, I am not in a hurry. I am trying to make it as fast as possible in response. The program is doing other things too so cannot affort delays in tables to choose one of 60. Yes the NCD/DCD is clever idea. Trying to comprehand... The 0db as seen on most old cassete recorder is the standard audio level of 1mW at 600ohm. That is about 0,775V rms. If a real VU-meter is checked, the dynamic range is more than 40db. On good ones, it extends even more. So, a log scaling has to be utilized, in order to make good use of the LCDBargraph. Just ADC and displaying makes for nearly 16-19db range! The -40db is 7.75mV rms or 22mVp-p. These voltages have to scaled and converted with rms converter or active rectifier. Max range would be +6dbm. That is 1.55Vrms or 4.36Vp-p. I intend to scale the 1.55Vrms to 4Vdc max (or somthing near) for the PIC to be happy. Ioannis Darrel Taylor - 21st June 2007, 10:53 I am trying to make it as fast as possible in response. The program is doing other things too so cannot affort delays in tables to choose one of 60. Ouch. I think tying to calculate it is going to take a lot longer than a Table Lookup. (I do mean A LOT) Maybe Alain's way might be better. Up to you, if you want to try. <br> Acetronics2 - 21st June 2007, 11:01 Hi, Ioannis Nothing Quicker than a lookup table ... ( PbP lookup not slower than ASM ... cause it's written quite the same !!! ) That's the way used for automobile ignitions ... where we count the µs ... Alain Ioannis - 21st June 2007, 11:02 Thanks. I will see which way I am going to choose. After all precision is not important when displaying audio levels, isn't it? So a table might be better. Ioannis Edit: That post was meant as an answer to Darrel, but it came 1 min after yours Alain. But it fit both! Mysterious ways this forum works! Darrel Taylor - 21st June 2007, 11:26 Sorry, just another Shameless Plug. Here's a way you might be able to implement the Lookup Table. http://www.picbasic.co.uk/forum/showthread.php?t=3891#LAB Quietly blushing, Ioannis - 21st June 2007, 11:35 Hmm, thats very clever. I think is faster too! Hands on experiment! Thanks Darrel. Ioannis Acetronics2 - 21st June 2007, 12:57 Hi, Ioannis this will be smaller ... but not faster. ( operations are still the same ...) Smaller ??? not sure ... still need 14 bits per value ... BUT ... as only 6 bits used per value, could try Value.Highbyte and Value.lowbyte to place 2 values in 1 location ... just an idea ... but really fun a table loading !!! mmmm, stupid idea: if you have 60 ( ? ) free locations in the RAM ( You did not tell us about the processor ...), you could download from the EEPROM to the RAM at each power-up ... and use a "simple" 60 values Array. no faster way !!! If you want to get a bit more precision ... you can linearize between two points ( "ax+b" line ) doesn't use much CPU ... that will be "less false" ... LOL Alain mister_e - 21st June 2007, 15:00 mmm, kinda mix with embedded strings in your code space and lookup table... So the Excel sheet would have to pack it in 14Bit and later you use DA. How's that sound? pretty bad to me as the unpacking method will certainely be slightly longer to execute than reading a single Byte for a DT, DW table ... Acetronics2 - 21st June 2007, 15:59 Hi, Steve Yess ... the packing method could work great if we had a 1 value to 1 Value "translation" I think the problem is a bit more complicated than we think at first ... we have to convert a 256 values log scale ( I do not want to think to 10 bits !!! ) to a 60 values lin scale ... so, many input values have the same output result ... Much,much room left !!! What's the ADC resolution needed if we want a 1 dB precision output, even @ - 40 dB ??? Much,much,much,much,much,much room left !!! ... 255 values limit fully exploded !!! Could we think to a BIG Select Case statement with 59 times " Case is <$xx or $xxxx" ... I do not know about the CPU time used ... but it seems a lot easier to write and calculate. Alain Darrel Taylor - 22nd June 2007, 04:18 I've been playing with the NCD/DCD with excel, and there's something I can't seem to work in there. Granted, I'm relying on 30 year old memories from when I was working on microwave radios in the air force. But if memory serves me right, then a change of 3 db is double the power, and -3 db is half the power. And since the impedance is constant, it also means the voltage is either doubled or halved. So let's assume the signal is scaled so that the (maximum A/D reading +1) corresponds to +7 dbm. Then half of that would be 512 or +4 dbm. If you keep dividing that down, since there's only 10 bit's, you end up with a minimum of -23 dbm with an A/D input of 1. And it appears that it would take a resolution of 16-bits to be able to get down to -40 dbm. http://www.pbpgroup.com/files/AD_DB.gif I think this applies to however you do it. Lookup, calculate, ... ADDED: And any noise or offset voltages will Obliterate the low end. But then, maybe I've got it all wrong? ?? <br> savnik - 22nd June 2007, 07:44 But if memory serves me right, then a change of 3 db is double the power, and -3 db is half the power. And since the impedance is constant, it also means the voltage is either doubled or halved. 3 db is for watts , not for volts(6 db). Acetronics2 - 22nd June 2007, 07:48 Hi, Darrel Looks you're perfectly right ... the PIC ADC does not have the 60 dB dynamics(? ... I meant range !!!) our friend Ioannis looks for. IF you were involved in radios ... may be the ref. "CA3089" will remind you some Vu-meter designs ... ( Use of pin 13 ...) So, If we used such a Log amplifier to translate from Log to lin scale ... we could easily get this 60 dB Scale ... may be more !!! Of course ... the drawing is in my Dataroom ... and I still must have a PCB somewhere !!! ( Was a very old Elektor application for an Audio Level-meter ( Sonometer) ... as the CA3089 can work with audio frequencies ... ) Read you soon Alain PS: found another with a NE604 Chip ...70 dB covered !!! ... heeuuuuuu file weights ... 325 kB DAMNED !!! Hi, Savnik + 3 dB means the double ... for whatever you want. but + 6 dB for Power means +3 dB for corresponding voltage savnik - 22nd June 2007, 08:31 Hi, Darrel Looks you're perfectly right ... the PIC ADC does not have the 60 dB dynamics(? ... I meant range !!!) our friend Ioannis looks for. IF you were involved in radios ... may be the ref. "CA3089" will remind you some Vu-meter designs ... ( Use of pin 13 ...) So, If we used such a Log amplifier to translate from Log to lin scale ... we could easily get this 60 dB Scale ... may be more !!! Of course ... the drawing is in my Dataroom ... and I still must have a PCB somewhere !!! ( Was a very old Elektor application for an Audio Level-meter ( Sonometer) ... as the CA3089 can work with audio frequencies ... ) Read you soon Alain PS: found another with a NE604 Chip ...70 dB covered !!! ... heeuuuuuu file weights ... 325 kB DAMNED !!! Hi, Savnik + 3 dB means the double ... for whatever you want. but + 6 dB for Power means +3 dB for corresponding voltage CA3089 is a monolithic integrated circuit that provides all the functions of a comprehensive FM-IF system, which include a three-stage FM-IF amplifier/limiter ,a doubly-balanced quadrature FM detector. Ioannis - 22nd June 2007, 10:34 Thanks Alain for the ideas. I suppose one has to do it in practice and check the response of the circuit. The PIC is not yet defined. I will choose one after we will end with the spec's (memory needed etc). mmm, kinda mix with embedded strings in your code space and lookup table... So the Excel sheet would have to pack it in 14Bit and later you use DA. How's that sound? pretty bad to me as the unpacking method will certainely be slightly longer to execute than reading a single Byte for a DT, DW table ... Steve, I agree that I have to pay for the extraction in terms of speed. But then, I guess, somewhere in the program there will be a point needing mcu power as it seems. Now, Darrel, as Nikos (Savnik) stated, 3db is indeed a double or half the power. But as for voltage, you need 6db. db(Watts)=10*LOG*(P1/P2) db(Volts)=20*LOG*(V1/V2) For the case we discuss, replace the V2 with 0.775Volts or the P2 with 1mW. If you make the maths you can prove it. Relative to the dynamic range, well I have to measure from 7.75mV up to 1.55 RMS or from 11mVpk up to 2.19Vpk. Lets make it easier and the MAX be 2Vpk. I will Scale it to max 5Volt (x2.5), so the minimum will be 11mV*2.5=27.5mV. For a 10-bit ADC the LSB will be 4.88mV, so a 10-bit ADC will be enough for a 46db dynamic range. If I am wrong please correct me. Now, about the CA3089 or the better one that I used long ago, CA3189. Where does this chip fit here? A big thank you to all responded. Ioannis P.S. The idea of Select Case may also be a nice alternative since for every BAR in the Bargraph there are alo of values to fit. It will be a long Select case of course... I have to try it. Acetronics2 - 22nd June 2007, 10:37 CA3089 is a monolithic integrated circuit that provides all the functions of a comprehensive FM-IF system, which include a three-stage FM-IF amplifier/limiter ,a doubly-balanced quadrature FM detector. AND a level detector output at pin 13 .... AND it works down to audio frequencies too ... AND NE604 an CA3089 show same functionnal blocks ( of interest here ...) inside Alain Acetronics2 - 22nd June 2007, 10:41 Hi, Ioannis could you PM me a mail adress for sending the scheme... ( and explanations of the NE 604 use ... if you can read French ( sorry ...)) Alain Darrel Taylor - 24th June 2007, 12:33 Alain, Finally got a chance to run your bargraph. (it works) But I'm still not crazy about the 5-bars. Here's what it looks like <script type="text/javascript"src="http://www.pbpgroup.com/DT_INTS-14/V-LCD_Disp.js"></script> <script type="text/javascript"src="http://www.pbpgroup.com/js/AceBargraph.js"></script> It's not as noticable when it moves fast, but that jump is still there. And while it compiles to about 100 words less than mine, it doesn't have all those features like placing it anywhere on the screen, making it any width of characters, scaling the input values to any range up to 32768, multiple bars on the screen and 3 different styles. :) But it definately does a 1-line 3/5-bar graph. Ioannis - 24th June 2007, 19:01 AND a level detector output at pin 13 .... AND it works down to audio frequencies too ... AND NE604 an CA3089 show same functionnal blocks ( of interest here ...) inside Alain Well, I tested NE604 and was amazed at Audio freqs. A nearly 65dB range was obtainable on a breadborad! Incredible! So the LCD_Bargraph has now a friend for audio signals making great VU-meter. One catch is that NE604 is expensive one. Here about 10 Euros in small qts. Thanks Alain for the tip. C/O Darrel: While trying to develop my project using your interrupts, I stuck on, I think for sure, stupid one. The attached sample code does not respond to PORTB.0 interrupt. Is there any mistake I 've made and can't see? Ioannis Acetronics2 - 24th June 2007, 20:04 Hi, Darrel Yes, ... I know the big problem at "high speed" is unequal calculating times upon the place pointed at ... but we must remember it's not a GLCD ... "some holes in the somewhere" ... Your picture's really nice !!! ... By the way ... I have a beautiful 122x32 GLCD here ... hmmmmmm, I might give a look to that !!! read you soon Alain skimask - 24th June 2007, 20:22 By the way ... I have a beautiful 122x32 GLCD here ... hmmmmmm, I might give a look to that !!! Alain I've got some 'pre-fab' code for the 122x32 types. Nothing wild, just the basic setup/configure routines, some basic 'x,y' plotting, and some text output routines. But it works great for me... EDIT: I just started a new thread with the code described above attached. Again, nothing fancy, but I've been using the same block of code for a couple of years now... Darrel Taylor - 24th June 2007, 22:41 C/O Darrel: While trying to develop my project using your interrupts, I stuck on, I think for sure, stupid one. The attached sample code does not respond to PORTB.0 interrupt. Is there any mistake I 've made and can't see? Ioannis Possibly... OPTION_REG =$81 ; Set TMR0 Prescaler to /2, RBPU on

The comment says RBPU on, but it's actually leaving the pull-ups turned off.
<br>

Ioannis
- 25th June 2007, 07:01
Thanks Darrel, but it really doesn't matter since there is a real resistor for Pull-up on the pcb (Picdem2+).

Ioannis

Darrel Taylor
- 26th June 2007, 02:02
Ioannis,

I can't see any other problems with the program. Or, any reason why it wouldn't work with the PICDEM2+.

Which PIC are you using with the PICDEM?
<br>

Ioannis
- 26th June 2007, 06:48
Currently the 16F877. I have handy also other to try. Maybe a 18F452.

To be sure that Portb.0 is OK, I tested with a simple loop of the kind:

while portb.0=1
wend
high LED1

and worked OK. So electrically there is no problem.

PICDEM2+ is connected to ICD2 working in programmer mode only. So, there is for sure no other source of interference.

Ioannis

Acetronics2
- 26th June 2007, 09:57

Ioannis

Hi, Ioannis

<< While trying to develop my project using your interrupts, I stuck on, I think for sure, stupid one. The attached sample code does not respond to PORTB.0 interrupt. Is there any mistake I 've made and can't see? >>

Thanks to PbP ... TRISB = 255 and led on PORTB.2 will work ...

BUT does your PORTB.0 change state when button ( ?) pushed ... in other words, is the pullup or pulldown resistor the OTHER side of the Pushbutton ... ( yes, I know it's a really stupid mistake ...but ...)

have a nice day

Alain

Ioannis
- 26th June 2007, 10:22

About the portb I did not really understood what you meant.

I test the portb.0 independently from the Interrupts and when pressed the program really see it. Like that:

while portb.0=1
wend
high led1

If button on Portb.0 is NOT pressed the program loops in the While-wend. If pressed then the LED1 lights, showing that there is no problem in the Setup or connections.

But when trying the Interrupts nothing happens. Really annoying...

Ioannis

Acetronics2
- 26th June 2007, 11:04
Hi,

For Portb.1 ...

you've declared it as an Input ... and drive a led with it ... so, it's an OUTPUT !!!

...

I think the Interrupt problem could be here ... I remember a thread explainining a Change in the I/Os disabled the Pullups ...

YESS it is !!! ... just over Fig 3.3 of the Datasheet ...

Tadaaaaaaa ..... one RTFM for you !!!

Alain

Ioannis
- 26th June 2007, 11:11
The LED is on portb.2. Portb is set as all outputs except bit 1. See the trisb=1

So, where is the ... Tadaaa?? :-)

Ioannis

Acetronics2
- 26th June 2007, 12:21
The LED is on portb.2. Portb is set as all outputs except bit 1. See the trisb=1

So, where is the ... Tadaaa?? :-)

Ioannis

No tadaaaaaa ... just read a bit too quickly ( TRISx = %00000001 is so much easier to look at ...)

Strange ... i tried DT interrupts quite the same way ... no problems.

Ioannis
- 26th June 2007, 12:30
I think I am,

trisb=1 is equal to:

trisb=%00000001

Isn't this bit 0 of port b set as input?

Ioannis

Acetronics2
- 26th June 2007, 13:00
Hi,

Looks good ...

I tried THAT in MPSIM ... Works Great ...

INCLUDE "C:\PBP\MODEDEFS.BAS"
DEFINE OSC 4

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

LED1 VAR PORTB.2

trisa=1:trisb=1:trisc=0:trisd=0:trise=0
PORTA=0:PORTB=0:PORTC=0:PORTD=0:PORTE=0

OPTION_REG = %00100001 ; Set TMR0 Prescaler to /2, RBPU on

adcon1=%10001110 'Right Justify, RA0 Analog, rest Digital I/O

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE INT_INT ; enable external (INT) interrupts
ENDASM

Main:
pause 1
GOTO Main

'---[INT - interrupt handler]--------------------------------------------------
ToggleLED1:
high LED1: pause 100:low led1
@ INT_RETURN

I just modified OPTION_REG value cause little things seemed strange to me ...

try it ... huuu ... is processor a 16F877 ????

Alain

Ioannis
- 26th June 2007, 13:28
Yes Alain, MCU is 16F877, but this is minor.

Do you mean that with OPTION_REG=$81 does not work also at your test? I have not the board with me at work now. I will test it late today. Ioannis Acetronics2 - 26th June 2007, 13:44 I have an old 877 here... I'll breaboard it ... We'll see !!! Alain Acetronics2 - 26th June 2007, 14:03 Hi, Ioannis YOUR code has passed the Breadboard test ... Works as expected ... ( little flash when PORTB.0 tied to ground ) Alain Darrel Taylor - 26th June 2007, 22:36 Looking at the PICDEM2+ schematic some more, it seems that there might be a conflict with PORTB.0 <img src=http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1794&stc=1&d=1182893641> With J6 installed (has to be for the LED on PORTB.2), the LED on PORTB.0 may not allow the voltage to rise far enough to register a HIGH level. <br> Sean_Goddard - 26th June 2007, 22:43 I joined in this quite late, but on the original bargraph code posted by Darrel (and also the interrupt code posted elsewhere) I have one thing to say....WOW Darrel. GENIUS.. BOTH of these snippets have saved me hours of work on a project I'm working on. I needed to poll an array of front panel switches every few milliseconds AND service a bargraph update AND change the frequency of a HPWM signal all at set times, I was in the process of writing an RTOS for the PIC to allow me to use queued commands executed on a priority/time basis, then these two pieces of code went live. OK, you killed my six months of work on the RTOS, but I'm not complaining. Everytime I see a new posting by you I just KNOW it's gonna be soething that makes my life that little bit easier. A huge thanks and keep up the excellent work. Darrel Taylor - 27th June 2007, 00:18 That's Great Sean! Always nice to know it's not going to waste. Hope it makes you money, or Impresses the boss, or Get's you an A+ on the project, or simply presserves the hair, so it can fall out naturally later. :) Best regards, Darrel Taylor - 27th June 2007, 02:06 Ioannis, Just in case you're still thinking, It can't be that (Post #89) because this works ... while portb.0=1 wend high led1 If you look at the PORTB.0 diagram. You can see that it uses a TTL input buffer when reading PORTB as digital inputs. So, the High and Low voltage levels are 2.0V and 0.8V. With the circuit on the PICDEM2+ you'll get around 2.25V with the switch open (depending on the forward voltage of the LED). So it works fine with the digital Inputs. <img src=http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1800&stc=1&d=1182906237> But the signal for the INT interrupt, goes thru a Schmitt Trigger. And it's levels are .8VDD (4V) High, and .2VDD(1V)Low. The circuits on PORTB.0 of the PICDEM2+ don't produce enough voltage to trigger the interrupt. (when the LED's are engaged) HTH Ioannis - 27th June 2007, 12:33 Darrel, your suspicion of PICDEM2+ were confirmed! Damn, so many ours wasted over a stupid LED! Thanks for the help guys! Finally I decided to use the hardware direction about the log conversion to bargraph display. Faster, cleaner, wide dynamic, expensive! Thanks again. Ioannis Acetronics2 - 27th June 2007, 13:07 Hi, Ioannis Have a look here ... http://pdf1.alldatasheet.com/datasheet-pdf/view/89792/ETC/SSM-2110.html nice, but may be difficult to find ... and expensive. but worth it. I've also found an AOP and linearizing diodes solution, but won't give the dynamics and precision you look for ... Alain mister_e - 28th June 2007, 00:25 ;) for non-french user, AOP= Op Amp ;) Ioannis - 28th June 2007, 06:21 Hi, Ioannis Have a look here ... http://pdf1.alldatasheet.com/datasheet-pdf/view/89792/ETC/SSM-2110.html ... Alain Thanks Alain. I 'll stick to NE604, although more expensive than CA3089, because is operating on 5V directly and is great! ;) for non-french user, AOP= Op Amp ;) I was wondering what AOP was! Thanks! Ioannis savnik - 28th June 2007, 06:35 Thanks Alain. I 'll stick to NE604, although more expensive than CA3089, because is operating on 5V directly and is great! You can use the SA605 (is more newer model than NE604) , and this is operating on 5-8V. Ioannis - 28th June 2007, 08:58 You can use the SA605 (is more newer model than NE604) , and this is operating on 5-8V. Thanks Nik. And a bit cheaper too! Ioannis Sean_Goddard - 22nd July 2007, 03:21 I've been playing with the NCD/DCD with excel, and there's something I can't seem to work in there. Granted, I'm relying on 30 year old memories from when I was working on microwave radios in the air force. But if memory serves me right, then a change of 3 db is double the power, and -3 db is half the power. And since the impedance is constant, it also means the voltage is either doubled or halved. So let's assume the signal is scaled so that the (maximum A/D reading +1) corresponds to +7 dbm. Then half of that would be 512 or +4 dbm. If you keep dividing that down, since there's only 10 bit's, you end up with a minimum of -23 dbm with an A/D input of 1. And it appears that it would take a resolution of 16-bits to be able to get down to -40 dbm. http://www.pbpgroup.com/files/AD_DB.gif I think this applies to however you do it. Lookup, calculate, ... ADDED: And any noise or offset voltages will Obliterate the low end. But then, maybe I've got it all wrong? ?? <br> I was always taught (having worked in the audo industry on digital mixin consoles, and having spent years designing synthesisers and samplers as a hobby) that the actual figure is around 6dB per bit, so 10 bits gives you 60dB, but in reality it's more like 4.5dB. I might be wrong but this is what I've always been told. Surely all you have to do is shift the levels? Ioannis - 23rd July 2007, 20:24 I was always taught (having worked in the audo industry on digital mixin consoles, and having spent years designing synthesisers and samplers as a hobby) that the actual figure is around 6dB per bit, so 10 bits gives you 60dB, but in reality it's more like 4.5dB. I might be wrong but this is what I've always been told. Surely all you have to do is shift the levels? Look at http://www.picbasic.co.uk/forum/showpost.php?p=40381&postcount=68. That one was solved! Ioannis Marin - 7th August 2007, 23:09 Hello! I've try to get some bar from this and I've got problem as usual ;-) So this is little code from me: INCLUDE "LCDbar_INC.bas" ' Include the BARgraph routines DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 4 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 1 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 0 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 INPUT PORTA.0 i var word LCDOUT$FE, 1 'clean screen

while PORTA.0 = 0
i = i+1
LCDOUT $FE,2,"Value = ",DEC i," " ' syntax- BARgraph Value, Row, Col, Width, Range, Style @ BARgraph _Value, 2, 0, 16, 255, lines Pause 100 wend As You can see in picture I've got problem when compiling with LCDbar_INC.bas...and get'+s lot lines of syntax error in INCLUDE file......off course I didn't make anything to this file...just copy -> paste.... Do You know what couses this problem? Darrel Taylor - 8th August 2007, 01:39 ' syntax- BARgraph Value, Row, Col, Width, Range, Style @ BARgraph _Value, 2, 0, 16, 255, lines _Value should be _i in this case. The comments a little confusing at first, but once you figure it out, it just seems natural. <br> Archangel - 8th August 2007, 02:19 Hi Marin, To use Darrel's tidy little include files, you must place a copy of his file in the same directory as your code's file is in, and you must use MPASM as the assembler, not PM. JS Oh, and do they ever work sweet too! Marin - 8th August 2007, 07:21 OK! Joe, is they any way to this be compiled in PM with some changes in .INCLUDE file? Ioannis - 8th August 2007, 10:40 If Darrel would make major changes it might! But then again why would he? MPASM is much better assembler! You still have your beloved compiler to write your code. Let Microchip do the job that knows better than anyone third. Ioannis Marin - 8th August 2007, 16:25 GOnna go to MPLAB now..... Can somebody explain me using MPSAM with mine MicroCode Stuio PicBasic Pro? With that I still gona write code in code studio or? Ioannis - 8th August 2007, 19:31 No additional code. Just set up the Microcode Studio to use MPASM from View/Compile and Program Options/Assembler and check the Use MPASM checkbox. On your programmer set the fuses accordingly to your program/xtal Ioannis Marin - 8th August 2007, 22:13 NOW, I download latest version of microcode studio and I'm using MPASM...and still have same problem.... With other mine code MPASM works great without any mistake.....but when I try to put bar code rutine as INCLUDE it gives me many errors.... Like YOu can saw on picture!!!! Only one strange thing occured: Everytime when I start CodeStudio.exe give me this message: The procedure entry point ThunkConnect32 could not be located in the dynamic link library KERNEL32.dll BUt, like I said...everthink wrks good with mine codes...... Darrel Taylor - 9th August 2007, 00:26 At this point, we can only guess. If you want to send the .LST file to me, I can take a closer look. Email to darrel at PBPgroup.com. It'll probably be too big to post in the forum. Marin - 9th August 2007, 08:34 The problem is I don't have LST file......Ionly have LST file for code which is corectly assembled...for this no...when I try to assembled it it give me errors and stops., And this is screenshot i forgot to send: Ioannis - 9th August 2007, 09:07 It seems like the MPASM is not selected or not found. Have you installed MPLAB or at least the assembler? Can you send the program? Ioannis Marin - 9th August 2007, 11:11 I did install MPASM and when I buil other code it works perfect and MPASM window pops up while compiling......so I think that's ok.... Gonna try reinstall PICBASIC OR mpasM AND GONNA SEE..... Darrel Taylor - 9th August 2007, 17:19 You might try downloading the LCDbar_INC.bas file again. I've heard a couple people say they got incomplete files on the first try. After downloading again it worked. The compiler is flagging errors, that should not be errors. A semicolon is the comment character. It should be ignored, not an error. What version of PicBasic Pro do you have? It is PicBasic Pro, right? Not PicBasic. <br> Acetronics2 - 9th August 2007, 19:32 Just a detail ... When installing MPLAB+ PbP ... some special instructions to care with !!! did you declare Paths to PbP AND to MPLAB, as specified ??? Alain Marin - 10th August 2007, 00:20 I downloaded code many times and always same problem remaining! Mecanique Micro Code Studio Plus Version 2.2.1.1 Compiler Version is PicBasic Pro 2.30 Yes....and MPASM is checked in complier options...and MPASM functioning ok with other codes! Darrel Taylor - 10th August 2007, 04:29 PicBasic Pro 2.30 ?? Well there's the problem. That's waaaaaayyy too old. Must have been at least 8 years ago. Time to buy a new version. <br> ruijc - 7th November 2007, 20:33 Hi guys, does this work with a pic 16F84A ?? I get many strange errors ! . Darrel Taylor - 7th November 2007, 21:18 Does it say something like "... Least significant bits used" ? If not, What errors are you getting? <br> ruijc - 7th November 2007, 22:12 i've imported the folowing code from this thread: DEFINE OSC 4 INCLUDE "lcdbarIN.bas" ' Set LCD Data port DEFINE LCD_DREG PORTB ' Set starting Data bit (0 or 4) if 4-bit bus DEFINE LCD_DBIT 4 ' Set LCD Register Select port DEFINE LCD_RSREG PORTB ' Set LCD Register Select bit DEFINE LCD_RSBIT 2 ' Set LCD Enable port DEFINE LCD_EREG PORTB ' Set LCD Enable bit DEFINE LCD_EBIT 3 ' Set LCD bus size (4 or 8 bits) DEFINE LCD_BITS 4 ' Set number of lines on LCD DEFINE LCD_LINES 2 ' Set command delay time in us DEFINE LCD_COMMANDUS 2000 ' Set data delay time in us DEFINE LCD_DATAUS 100. DEFINE ADC_BITS 8 ' Number of bits in ADCIN result ADCON1.7 = 1 ' Right Justify AD result Value VAR WORD ' Must be a WORD even though AD is 8bit pause 1000 LCDOUT$FE, 1, " "
loop1:

LCDOUT $FE,2,"Value = ",DEC Value," " 'syntax- BARgraph Value, Row, Col, Width, Range, Style @ BARgraph _Value, 2, 0, 16, 255, lines then i get : Error line 14: syntax error - this one i believe it's the ADCON1.7 = 1 command Warning Line 15: Bad token ";" bad expression Warning Line 16: Bad token ";" bad expression Warning Line 17: Bad token ";" bad expression Warning Line 18: Bad token ";" bad expression Note: The INCLUDE "lcdbarIN.bas" line where the name of the bas file is different because i also had to change to a smaller name due to "cannot include...etc" error . mister_e - 7th November 2007, 22:16 mmm, as far as i know... grandpa 16F84 have no A/D converter :eek: ... so ADCIN will never ever works with... hence why you have some strange error... i missed that forum ;) ruijc - 7th November 2007, 22:20 Hi mister_e, you are right...but... i tryed to comment the lines : 'DEFINE ADC_BITS 8 ' Number of bits in ADCIN result 'ADCON1.7 = 1 ' Right Justify AD result and 'adcin 2,value and still the same errors . mister_e - 7th November 2007, 22:30 mm, i don't remind to already have this problem... token and line # mmmm which compiler and which version are you using? Darrel Taylor - 7th November 2007, 22:34 Yup, it's probably the version. In Post #110 there is an image from Marin that also has the same "Bad Token" errors. 1922 The problem was PBP version 2.30 (it's just too old) HeHe: Beat him by a minute :) <br> mister_e - 7th November 2007, 22:35 @ post 110, i think i found 1 solution... or at least some tips... configuration fuse does not seems to be the one for an 16F877 anyways, and the comment should use ; instead of ' for this one... i don't know :( .. still thinking of the version ! ruijc - 8th November 2007, 19:06 yeah...i guess it's the version as my version is old as well. thanks anyway . ChrisMicro - 9th January 2008, 13:49 This is my version of the bar graph. '************************************************* *************** '* Name : Bargraph.BAS * '* Author : Chris Bezuidenhout * '* Notice : Copyright (c) 2005 Micro Developments * '* : All Rights Reserved * '* Date : 2005/07/19 * '* Version : 1.0 * '* URL : http://www.patenttrade.net * '* E-mail : chris@patenttrade.net * '* Mobile : +27-72-795-0107 * '* Notes : This is a bargraph demo for a 2X20 LCD Display * '* : it is free to use and distribute by any one * '* : as long as this Copyright note is not altered or * '* : removed, can be used as an analog meter. * '* Device : PIC16F877 can be altered to work on other devices * '************************************************* *************** INCLUDE "Modedefs.Bas" DEFINE OSC 4 ' Set Xtal Frequency DEFINE LCD_DREG PORTA ' Set LCD Data port DEFINE LCD_DBIT 0 ' Set starting Data BIT (0 OR 4) IF 4-BIT bus DEFINE LCD_RSREG PORTA ' Set LCD Register Select port DEFINE LCD_RSBIT 4 ' Set LCD Register Select BIT DEFINE LCD_EREG PORTE ' Set LCD Enable port, for other devices, use PORT A or B DEFINE LCD_EBIT 0 ' Set LCD Enable BIT DEFINE LCD_BITS 4 ' Set LCD bus side (4 OR 8 bits) DEFINE LCD_LINES 2 ' Set number of lines ON LCD ' md Declare the Variables md counter VAR BYTE Text VAR BYTE[20] X VAR BYTE Y VAR BYTE PAUSE 500 Main: '*********Modefy first 5 characters in LCD character generator to display bargraph********** LCDOut$fe,%1000000 'SET CG RAM ADD.
FOR X =1 TO 8
LCDOUT %10000
next x
FOR X=1 TO 8
LCDOUT %11000
NEXT X
FOR X=1 TO 8
LCDOUT %11100
NEXT X
FOR X=1 TO 8
LCDOUT %11110
NEXT X
FOR X=1 TO 8
LCDOUT %11111
NEXT X
LCDOut $fe,%10000000 'SET DD RAM ADD. ' FOR X = 0 TO 255 ' LCDOUT$FE,1,#X,X
' PAUSE 100
' NEXT X
LOOP1: LCDOUT $FE,1,"This is a test" LCDOUT$FE,$C0 'clear second line and display bar graph LCDOUT 0 'print first character for X= 0 TO 19 'change 19 to 15 for 16 character display PAUSE 100 LCDOUT$FE,$10,1 'move curser back and overprint previous character PAUSE 100 LCDOUT$FE,$10,2 'move curser back and overprint previous character PAUSE 100 LCDOUT$FE,$10,3 'move curser back and overprint previous character PAUSE 100 LCDOUT$FE,$10,4 'move curser back and overprint previous character PAUSE 100 LCDOUT$FE,$14 'print next character LCDOUT$FE,0
NEXT X

GOTO LOOP1

END

Darrel Taylor
- 9th January 2008, 22:32
Chris,

The Note says "can be used as an analog meter".

How would you do that?
<br>

tenaja
- 9th January 2008, 22:44
It's a slight variation of Les Johnson's bargraph routine, which is in his PBP book. You load the "graphics" of the bar graph into lcd memory, then print solid bars (or blocks) until the final one which is printed as the mod of 3. The above bar graphs use a resolution of five, which has the disadvantage of a space between each five. Les' uses three, because it makes the space between the characters an unnoticed and integral part of the graph. If you don't have Les' book, then look for one of the Proton samples, because they ship with it.

ChrisMicro
- 22nd January 2008, 12:25
Chris,

The Note says "can be used as an analog meter".

How would you do that?
<br>

You have to use a chip with AD channels like the 16F818/819 then say for 1 volt you send your 5th character and for 1.4 volt you will send the 5th and the second character for 2.2 volt you will send the 5th character twice and then your first character so your 5th character is your integer and the first four is your decimals after the point, it give you a .2 resolution .2, .4, .6, .8

ChrisMicro
- 22nd January 2008, 12:59
You can even draw little 5X7 sprites, like a walking man or any 5X7 picture. I have a small basic compiler with some handy tools, where you can create the picture and get the data for your picture. there is also a seven segment tool, it is free to download from my site, but you can only use the compiler with the programmer from Mikro Elektronika, but the tools is handy. look in the right border for free downloads it is the first item

earltyso
- 3rd February 2008, 00:07
DT,
Really nice work! I will be using this on several of my A2D projects!!

Darrel Taylor
- 3rd February 2008, 21:22
Hope they work out for you.

You might also want to check out this one ...

http://www.pbpgroup.com/modules/newbb/viewtopic.php?topic_id=37&forum=2
<br>

karamastik
- 4th April 2008, 15:24
Hello ! :)
First of all , thanks for the LCD codes.
I applied the code below , it works fine ; but at the first row ; " Value= XXX " always flickering ; like something is writing over the " Value = XXXX " and it's always flickering.
What is the problem ?

@ DEVICE pic16F877
@ DEVICE pic16F877, WDT_on
@ DEVICE pic16F877, PWRT_ON
@ DEVICE pic16F877, PROTECT_OFF
@ DEVICE pic16F877, HS_OSC

TRISA=%00000001
TRISB=0
TRISE=0
INCLUDE "LCDbar_INC.bas"

ham var word

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 0
DEFINE LCD_RWREG PORTE
DEFINE LCD_RWBIT 2
DEFINE LCD_BITS 8
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1000
DEFINE LCD_DATAUS 225

LOW PORTE.2

LCDOUT $FE,1 PAUSE 200 Loop1: ADCIN 0, ham ham=1023-ham LCDOUT$FE,2,"Value = ",DEC ham," "
; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _ham, 2, 0, 16, 1023, lines
PAUSE 50
Goto Loop1

END

- 4th April 2008, 16:12
" Value= XXX " always flickering ; like something is writing over the " Value = XXXX " and it's always flickering.

Loop1:
ham=1023-ham
LCDOUT $FE,2,"Value = ",DEC ham," " ; syntax- BARgraph Value, Row, Col, Width, Range, Style @ BARgraph _ham, 2, 0, 16, 1023, lines PAUSE 50 Goto Loop1 That's because something is always overwriting Value = XXXX. VALUE = XXXX is always overwriting VALUE = XXXX. Try ONLY overwriting just the value not the whole string. mister_e - 4th April 2008, 16:27 Pause 50 is a bit low, try to increase it a little bit more. Darrel Taylor - 4th April 2008, 20:26 karamastik, LCD_COMMANDUS 1000 seems a little low. On most displays, the Home command ($FE,2) takes 1.6ms or 1600us.
Try increasing it to 2000, some displays need even more than that.

LCD_DATAUS 225 is pretty High. Should be around 50.
If this one is too high, it won't cause a problem. It'll just slow things down unnecessarily.
<br>

karenhornby
- 9th April 2008, 21:13
Can I pick someone's brain please?
I'm at the moment trying to make an auto switchover gadget to change from running on Diesel to Veg Oil once certain temperatures have been reached, and to try and work this out I'm using the easypic5 development board.
So far: I have a 16f877A programmed so it will switch certain outputs when certain inputs go high all and well
It even displays what it's doing on the LCD display

What I'd like to incorporate if its possible is this? or a variation of it the Bargraph but use it as a fuel level sensor, i.e. changing position depending on the level of the fuel in the tank (variable resistor)

Does anyone know any code that will do that or give me a starting place to play with?
I know I've got 2 A/D converter inputs on the developement board I can play with that have a 10K pot connected and are configured so I can change the input on either of the RA0, RA1, RA2, RA3, RA4, or RA5 pins and measure the voltage on them ( unfortunatly I'm only just learning about Pic's at the moment and know nothing about A/D and how to use it, I am learning by trying and experimenting But I am a quick learner), so IF anyone has any code they could share with me to show me how to get started with this I'd be grateful :) Thanks

mister_e
- 9th April 2008, 21:33
well, once you have the lcd working.. it's just a matter to have few IF-THEN conditions with your ADC value and few HIGH/LOW lines, and you should be in business... maybe i've misundertood something?

mackrackit
- 9th April 2008, 21:45
Does anyone know any code that will do that or give me a starting place to play with?
I like this one. http://www.rentron.com/PICX2.htm

It is a little more complicated than ADCIN, but it is still the method I use.
Follow the code with the data sheet and it should become clear how the ADC works. Complete control.

karenhornby
- 9th April 2008, 21:55
well, once you have the lcd working.. it's just a matter to have few IF-THEN conditions with your ADC value and few HIGH/LOW lines, and you should be in business... maybe i've misundertood something?

Your forgetting im a Pseudo Blonde :)
I've no idea how to start off with ADC values or how to use them (at the moment) I've found the easiest way to learn something is by following examples that show you how to get started and then playing from there thats how I got the LCD working in the first place, and then the bargraph, then inputs and outputs... learning.. slowly!

mister_e
- 9th April 2008, 22:10
No i didn't forget :D

let's see first example in this thread

; Initialize your hardware and LCD first.

INCLUDE "LCDbar_INC.bas" ' Include the BARgraph routines

Value VAR WORD ' Must be a WORD even though AD is 8bit

LCDOUT $FE, 1 ' Clear Screen Loop1: ADCIN 0, Value LCDOUT$FE,2,"Value = ",DEC Value," "
; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 2, 0, 16, 255, lines
GOTO Loop1

You just need to monitor Value variable with some IF-THEN statements after ADCIN line

IF Value>200 then
LCDOUT $FE,2,"VALUE>200 " endif karenhornby - 9th April 2008, 23:05 Thanks I think I'm starting to get parts of it I'll try tomorrow properly when my head isn't so tired however i do have one question, how do you tell the pic what port the input is on? ie if the pot was connected to portA.0 how would you tell the pic to measure and display the value of that port? Hope I've said that clearly enough, sometimes I'm better about thinking about things than trying to explain what I mean mister_e - 9th April 2008, 23:20 ADCIN 0, Value check the datasheet, PORTA.0 is AN0 greatpic - 30th April 2008, 10:18 I will use it to cell voltage indicator project ChrisMicro - 4th July 2008, 05:10 Can I pick someone's brain please? I'm at the moment trying to make an auto switchover gadget to change from running on Diesel to Veg Oil once certain temperatures have been reached, and to try and work this out I'm using the easypic5 development board. So far: I have a 16f877A programmed so it will switch certain outputs when certain inputs go high all and well It even displays what it's doing on the LCD display What I'd like to incorporate if its possible is this? or a variation of it the Bargraph but use it as a fuel level sensor, i.e. changing position depending on the level of the fuel in the tank (variable resistor) Does anyone know any code that will do that or give me a starting place to play with? I know I've got 2 A/D converter inputs on the developement board I can play with that have a 10K pot connected and are configured so I can change the input on either of the RA0, RA1, RA2, RA3, RA4, or RA5 pins and measure the voltage on them ( unfortunatly I'm only just learning about Pic's at the moment and know nothing about A/D and how to use it, I am learning by trying and experimenting But I am a quick learner), so IF anyone has any code they could share with me to show me how to get started with this I'd be grateful :) Thanks Here is my code for monitoring the sensors in a car. Note: this method is more accurate than ADCIN '************************************************* *************** '* Name : CarMonitor.PBP * '* Author : Chris Bezuidenhout * '* Notice : Copyright (c) 2007 Micro Developments * '* : All Rights Reserved * '* Date : 2007/10/23 * '* Version : 1.1.1 * '* URL :http://www.patenttrade.net * '* : * '************************************************* *************** INCLUDE "Modedefs.Bas" OSCCON = %01100000 'set the intrc osc change bit 4 to logic 1 for 8 MHz OSCTUNE = %000000 DEFINE OSC 4 ' Set IRC Frequency DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 1 ' Set clock source (rc = 3) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds IgnIn var word Altin var word Oilin var word TempIn var word ResIn var word 'Reserve input IgnOut var portb.0 AltOut var portb.1 OilOut var portb.2 TempOut var portb.3 Buzzer var portb.4 ComO var portb.5 SigOut var portb.6 sp2 var portb.7 Spin1 var porta.6 Spin2 var porta.7 X var byte Y var byte TRISA = %11111111 'Porta 0-4 all analog 5 input only pull high TRISB = %00000000 ADCON0 = %11000001 Pause 2000 ' Wait .5 second ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result OPTION_REG =$7f ' Enable PORTB pullups

pause 500
portb = 0
low Buzzer

Main:
gosub CIgn
gosub CAlt
gosub COil
gosub CTemp
gosub Send

Ignition:
if ignin = 0 then
high Ignout
gosub Send
goto main
endif
if ignin > 300 then
low ignout
goto Alternator
endif
' if ignin > 0 and ignin < 300 then
for y = 1 to 3
gosub CIgn
gosub Send
if ignin > 300 then Alternator

for x = 1 to 2
high Ignout
high buzzer
pause 200
low buzzer
pause 200
next x
pause 1000
next y

' endif
Alternator:
if ignin = 0 then goto main
low ignout
if Altin > 1020 then
high altout '?????????Kalibreer
for y = 1 to 3
gosub CAlt
gosub Send
if altin < 1020 then Oil
for x = 1 to 4
high buzzer
pause 200
low buzzer
pause 200
next x
pause 1000
next y
endif

Oil:
if ignin = 0 then goto main
low altout
if Oilin > 10 then 'This variable have to be calibrated to sensor unit
high Oilout 'for a plain on/of it must be set to 0, the pot at minimum
for y = 1 to 3 'if there is some contact resistance it can be calibrated acordingly
gosub COil 'For a analog (resistive) sensor it have to be calibrated to
gosub Send 'the sensor
if oilin < 10 then Temperature 'So is this one
for x = 1 to 6
high buzzer
pause 200
low buzzer
pause 200
next x
pause 1000
next y
endif

Temperature:
if ignin = 0 then goto main
low Oilout
if tempin < 85 then
high tempout
for y = 1 to 3
gosub CTemp
gosub Send
if tempin > 85 then main
for x = 1 to 8
high buzzer
pause 200
low buzzer
pause 200
next x
pause 1000
next y
endif
low tempout
goto main
CIgn:
gosub notdone
write 0,ignin.highbyte
write 1,ignin.lowbyte
return
CAlt:
gosub notdone
write 2,Altin.highbyte
write 3,Altin.lowbyte
return
COil:
gosub notdone
write 4,oilin.highbyte
write 5,oilin.lowbyte
return
CTemp:
gosub notdone
write 6,tempin.highbyte
write 7,tempin.lowbyte
return
CRes:
gosub notdone
Return
Send:
serout SigOut, N2400,["A",IgnIn.highbyte,IgnIn.lowbyte,altin.highbyte,altin .lowbyte,Oilin.highbyte,Oilin.lowbyte,Tempin.highb yte,Tempin.lowbyte,resin.highbyte,resin.lowbyte]
return
notdone: Pause 5
If ADCON0.2 = 1 Then notdone' Wait for low on bit-2 of ADCON0, conversion finished
return
end

mehmetOzdemir
- 1st September 2008, 10:41
hi darrel...

i m using pbp 2.50b compiler and using pbpl.

how can i use your include file with pbpl?

Darrel Taylor
- 1st September 2008, 22:17
For each DIV32, change it to a normal divide ...

Was: Limit1 = DIV32 10

&nbsp; To:&nbsp; Limit1 = Limit1 / 10

or you can combine them with the previous statements

Limit1 = (BAR_range * 3) / 10

for all the occurances.

And change the WORD vars to LONG.
<br>

tekniker_erhan
- 7th September 2008, 15:12
hi friends
I am a new member I can little speak english maybe my errors I am sorry
My problem is LCD bargraph How I can on pictures project. on pictures LCD 2x16 char , LCD has 32 bars per char has two bars project has two buttons minus and plus I need this projects pic basic code Can you help me. Already tahnks

mehmetOzdemir
- 8th September 2008, 13:13
I TRIED YOUR INCLUDE FILE FOR PBPL AND MADE WHAT U SAID.

IT'S WORKING GOOD THANKS.

'************************************************* ***************
'* Creates a variable sized BAR-graph anywhere on the screen *
'************************************************* ***************
'* Name : LCDbar_INC.bas *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2005 *
'* Date : 9/8/2005 *
'* Version : 1.0 *
'* Notes : Maximum Range is 32768 *
'* : Range must always be a Constant *
'* : Value must always be a WORD variable *
'* : *
'************************************************* ***************
; default
BAR_width VAR BYTE : BAR_width = 16 ; Width of the BARgraph 16
BAR_range VAR LONG : BAR_range = 100 ; Range of Values (0-100) 100 ;;;;;;;;;;;
BAR_row VAR BYTE : BAR_row = 1 ; Row location (1-4) 1
BAR_col VAR BYTE : BAR_col = 0 ; Column location (0-15) 0
BAR_value VAR LONG : BAR_value = 0 ; Current BAR value 0 ;;;;;;;;;;;
BAR_style VAR BYTE : BAR_style = 1 ; 1=lines, 2=boxed, 3=blocks 1

; --- Temporary vars ----
BARtemp VAR LONG ;;;;;;;;
Remainder VAR LONG ;;;;;;;;
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
Limit1 VAR LONG ;;;;;;;;

GOTO overBAR ; Skip over Subroutines

ThreeBARS CON 0 ; Identify the Custom Characters
TwoBARS CON 1
OneBAR CON 2

ASM
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM

; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,$40,REP $15\8 ; Custom char 0 - 3 lines ||| LCDOut$FE,$48,REP$14\8 ; Custom char 1 - 2 lines ||
LCDOut $FE,$50,REP $10\8 ; Custom char 2 - 1 line | RETURN ; --- boxed Style custom chars ---- CharsetBoxed: LCDOut$FE,$40,$1F,REP $15\6,$1F ; III
LCDOut $FE,$48,$1C,REP$14\6,$1C ; II LCDOut$FE,$50,REP$10\8 ; I
RETURN

; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,$40,REP $1F\8 LCDOut$FE,$48,REP$1C\8
LCDOut $FE,$50,REP $10\8 RETURN ; ----- Show the BAR graph ----------------------------------------------------- ShowBAR: IF BAR_width = 0 then BARdone if LastCharset <> BAR_style then ; If the Style has changed ? LastCharset = BAR_style SELECT CASE BAR_style ; Load the new custom chars CASE 1 : GOSUB CharsetLines CASE 2 : GOSUB CharsetBoxed CASE 3 : GOSUB CharsetBlocks END SELECT endif @ ifdef LCD4X20 LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp
@ else
LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp @ endif LCDOUT$FE, BARtemp + BAR_col ; Move cursor to start of the BAR

;;;;;;;;BARtemp = BAR_value * BAR_width ; calc the char position
;;;;;;;;BARtemp = DIV32 BAR_range

BARtemp = (BAR_value * BAR_width)/BAR_range ; CHANGED

Remainder = R2

For BARloop = 0 to BAR_width -1
SELECT CASE BARtemp
CASE IS > BARloop
LCDOUT ThreeBARS ; send 3 bars |||
CASE IS < BARloop
LCDOUT " " ; clear to end of BARwidth
CASE IS = BARloop

;;;;Limit1 = BAR_range * 6
;;;;Limit1 = DIV32 10

Limit1 = (BAR_range * 6)/10 ; CHANGED

if Remainder >= Limit1 then
LCDOUT TwoBARS ; send 2 bars ||
else
;;;;Limit1 = BAR_range * 3
;;;;Limit1 = DIV32 10

Limit1 = (BAR_range * 3)/10 ; CHANGED

if Remainder >= Limit1 then ; 30%
LCDOUT OneBAR ; send 1 bar |
else
LCDOUT " " ; no bars
endif
endif
END SELECT
NEXT BARloop
BARdone:
RETURN

ASM
; --- The main macro for creating BARgraphs ------------------------------------
BARgraph macro Value, Row, Col, Width, Range, Style
MOVE?CW Range, _BAR_range ; Range MUST be a constant
MOVE?WW Value, _BAR_value ; Value MUST be a WORD variable
if (Row < 5) ; Row is a constant
MOVE?CB Row, _BAR_row
else ; Row is a variable
MOVE?BB Row, _BAR_row
endif
if (Col < 16) ; Is Col a constant ?
MOVE?CB Col, _BAR_col
else ; NO, it's a variable
MOVE?BB Col, _BAR_col
endif
if (Width <= 40)
MOVE?CB Width, _BAR_width
else
MOVE?BB Width, _BAR_width
endif
if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ?
MOVE?CB Style, _BAR_style
else ; NO, treat it like a variable
MOVE?BB Style, _BAR_style
endif
L?CALL _ShowBAR
endm

ENDASM

overBAR:

but there is a problem ; when i want to use different bar type on lcd for different rows bar types are mixing.

example:

row1 blocks
row2 lines
row3 boxed
row4 blocks

when use it like this all rows are one type bar.

Darrel Taylor
- 8th September 2008, 18:12
Great! Glad you got it working, and thanks for the updated code. http://www.picbasic.co.uk/forum/images/icons/icon14.gif

There's only 1 area for custom characters in the LCD.
So you can only have one Style at a time. Sorry.
<br>

tekniker_erhan
- 9th September 2008, 06:22
I TRIED YOUR INCLUDE FILE FOR PBPL AND MADE WHAT U SAID.

IT'S WORKING GOOD THANKS.

'************************************************* ***************
'* Creates a variable sized BAR-graph anywhere on the screen *
'************************************************* ***************
'* Name : LCDbar_INC.bas *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2005 *
'* Date : 9/8/2005 *
'* Version : 1.0 *
'* Notes : Maximum Range is 32768 *
'* : Range must always be a Constant *
'* : Value must always be a WORD variable *
'* : *
'************************************************* ***************
; default
BAR_width VAR BYTE : BAR_width = 16 ; Width of the BARgraph 16
BAR_range VAR LONG : BAR_range = 100 ; Range of Values (0-100) 100 ;;;;;;;;;;;
BAR_row VAR BYTE : BAR_row = 1 ; Row location (1-4) 1
BAR_col VAR BYTE : BAR_col = 0 ; Column location (0-15) 0
BAR_value VAR LONG : BAR_value = 0 ; Current BAR value 0 ;;;;;;;;;;;
BAR_style VAR BYTE : BAR_style = 1 ; 1=lines, 2=boxed, 3=blocks 1

; --- Temporary vars ----
BARtemp VAR LONG ;;;;;;;;
Remainder VAR LONG ;;;;;;;;
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
Limit1 VAR LONG ;;;;;;;;

GOTO overBAR ; Skip over Subroutines

ThreeBARS CON 0 ; Identify the Custom Characters
TwoBARS CON 1
OneBAR CON 2

ASM
lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM

; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,$40,REP $15\8 ; Custom char 0 - 3 lines ||| LCDOut$FE,$48,REP$14\8 ; Custom char 1 - 2 lines ||
LCDOut $FE,$50,REP $10\8 ; Custom char 2 - 1 line | RETURN ; --- boxed Style custom chars ---- CharsetBoxed: LCDOut$FE,$40,$1F,REP $15\6,$1F ; III
LCDOut $FE,$48,$1C,REP$14\6,$1C ; II LCDOut$FE,$50,REP$10\8 ; I
RETURN

; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,$40,REP $1F\8 LCDOut$FE,$48,REP$1C\8
LCDOut $FE,$50,REP $10\8 RETURN ; ----- Show the BAR graph ----------------------------------------------------- ShowBAR: IF BAR_width = 0 then BARdone if LastCharset <> BAR_style then ; If the Style has changed ? LastCharset = BAR_style SELECT CASE BAR_style ; Load the new custom chars CASE 1 : GOSUB CharsetLines CASE 2 : GOSUB CharsetBoxed CASE 3 : GOSUB CharsetBlocks END SELECT endif @ ifdef LCD4X20 LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp
@ else
LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp @ endif LCDOUT$FE, BARtemp + BAR_col ; Move cursor to start of the BAR

;;;;;;;;BARtemp = BAR_value * BAR_width ; calc the char position
;;;;;;;;BARtemp = DIV32 BAR_range

BARtemp = (BAR_value * BAR_width)/BAR_range ; CHANGED

Remainder = R2

For BARloop = 0 to BAR_width -1
SELECT CASE BARtemp
CASE IS > BARloop
LCDOUT ThreeBARS ; send 3 bars |||
CASE IS < BARloop
LCDOUT " " ; clear to end of BARwidth
CASE IS = BARloop

;;;;Limit1 = BAR_range * 6
;;;;Limit1 = DIV32 10

Limit1 = (BAR_range * 6)/10 ; CHANGED

if Remainder >= Limit1 then
LCDOUT TwoBARS ; send 2 bars ||
else
;;;;Limit1 = BAR_range * 3
;;;;Limit1 = DIV32 10

Limit1 = (BAR_range * 3)/10 ; CHANGED

if Remainder >= Limit1 then ; 30%
LCDOUT OneBAR ; send 1 bar |
else
LCDOUT " " ; no bars
endif
endif
END SELECT
NEXT BARloop
BARdone:
RETURN

ASM
; --- The main macro for creating BARgraphs ------------------------------------
BARgraph macro Value, Row, Col, Width, Range, Style
MOVE?CW Range, _BAR_range ; Range MUST be a constant
MOVE?WW Value, _BAR_value ; Value MUST be a WORD variable
if (Row < 5) ; Row is a constant
MOVE?CB Row, _BAR_row
else ; Row is a variable
MOVE?BB Row, _BAR_row
endif
if (Col < 16) ; Is Col a constant ?
MOVE?CB Col, _BAR_col
else ; NO, it's a variable
MOVE?BB Col, _BAR_col
endif
if (Width <= 40)
MOVE?CB Width, _BAR_width
else
MOVE?BB Width, _BAR_width
endif
if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ?
MOVE?CB Style, _BAR_style
else ; NO, treat it like a variable
MOVE?BB Style, _BAR_style
endif
L?CALL _ShowBAR
endm

ENDASM

overBAR:

but there is a problem ; when i want to use different bar type on lcd for different rows bar types are mixing.

example:

row1 blocks
row2 lines
row3 boxed
row4 blocks

when use it like this all rows are one type bar.
turkish mean
özdemir dostum bu program nasıl çalışıyor uygulama şemasını ekleye bilirmisin banada resimdeki 2 butonlu bargraph uygulaması lazım yukarıda resimleri ekledim bu programı 2 butonlu şekilde düzenleyebilirmiyiz. şimdiden teşekkürler bide ingilizce yazmaya çalışım ayıp olmasın

english mean ,maybe my errors, Im sorry
özdemir my friend,how is run this program can you attach application circuit I need on picture bargraph application with two buttons How I can make this project can you helpme already thanks

Glenn
- 8th January 2009, 21:49
Great stuff :)

Worked on the first try in my latest program, which I didn't really expected :)

I started to write something own, until I remembered that I had a vague memory of seeing something like this on the forum, and here it was, ready to be used :)

Would be really nice to have a logarithmic scale too, I didn't really understood everything people wrote about logarithmic, did anyone come up with a quick software-only solution ?

Ioannis
- 9th January 2009, 07:27
In software you need a lot of maths. So better use a hardware solution. Faster and wide dynamics (up to 64db).

Ioannis

Glenn
- 10th January 2009, 00:51
But how do I do that ? a logarithmic filter ?

Ioannis
- 10th January 2009, 11:22
If you mean in hardware, please look at previous post:

http://www.picbasic.co.uk/forum/showpost.php?p=40371&postcount=66

The chips include a logarithmic amplifier. So you take the output of this amplifier and feed it in the analog converter of the PIC. At the input you feed the analog signal either directly or through an active rectifier.

Ioannis

ronsimpson
- 10th January 2009, 21:28
Several times in this thread people have mentioned log amplifiers for audio signals.
See thatcorp.com THAT2252
http://thatcorp.com/datashts/2252data.pdf
The output is +0.3 to –0.3 volts over a 100db range. A simple op-amp will amplify the 0.6 volt signal and add an offset to get 0 to 5 volts.

Ioannis
- 11th January 2009, 09:46
Nice chip, but I believe the other three (3089, 3189 and NE604) are more convienient since they work with single supply and are much wider in freq. range.

Ioannis

ciberman37
- 20th March 2009, 09:49
The compiler signalise error in line 29, no is alabel?

:rolleyes:

Darrel Taylor
- 20th March 2009, 21:05
Line 29 is GOTO overBAR, and overBAR: is the last line in the include file.

<br>

Glenn
- 14th October 2009, 22:49
What kind of licence did u put on your code Darrel ?

I currently making a little project for a contest in a swedish electronics forum, and I really would like to use a LCD bargraph, and the rules states that I only can use includes that are "GPL or more free.", can I use this, or do I have to write something much more ugly myself ? :)

Darrel Taylor
- 14th October 2009, 22:55
What kind of licence did u put on your code Darrel ?
As long as you don't say you wrote it ... you can do whatever you want with it.

<br>

solidus
- 6th November 2009, 21:30
Hi darrel.. Really nice work.Congrats.
I intend to write lcd bar vu-meter and bar voltmeter codes. I did for voltmeter but not for bar vu-meter. And I need help for this. MCU is 16f876 and 2x16 lcd.. I need some help to convert reading from frequency to the bars. Can you help me ?

Darrel Taylor
- 6th November 2009, 22:17
For VU-Meter, I think you'll need an external LOG convertor such as one of these op-amp circuits ...
http://en.wikipedia.org/wiki/Operational_amplifier_applications#Logarithmic_out put
http://www.st-andrews.ac.uk/~www_pa/Scots_Guide/audio/part8/Page3.html

Without the LOG convertor, you'll only see big peaks in the bargraph and none of the lower level signals.

I need some help to convert reading from frequency to the barsIf you're thinking of a Spectrum Analyzer, then nope, can't help there.
<br>

Ioannis
- 7th November 2009, 10:51
Also thanks to Alain, the CA3089 and NE604 can do the job very nice!

Ioannis

savnik
- 7th November 2009, 10:55
I use the Bargraphs(lines) to show on lcd the volt from 0 to 5 volt with adc 10 bit.
How to change the code to show always at first Col the first character.
Like this : from ||||| to show only | if the volt is 0.

savnik
- 7th November 2009, 10:57
Also thanks to Alain, the CA3089 and NE604 can do the job very nice!

Ioannis
Hi Ioannis. (Γεια σου Γιάννη)
Can you post the shematic of ca3089 which you used?

savnik
- 12th November 2009, 06:33
I use the Bargraphs(lines) to show on lcd the volt from 0 to 5 volt with adc 10 bit.
How to change the code to show always at first Col the first character.
Like this : from ||||| to show only | if the volt is 0.
Someone to help;

Darrel Taylor
- 12th November 2009, 09:43
If I understand the question, maybe ...

That will limit the value to a minimum of 18, which should always leave 1 line showing.
Assuming a 20 character bargraph, with a range of 1023.

hth,

savnik
- 12th November 2009, 09:59
I want if the value is 0 (0-1023) to show like this picture:

Ioannis
- 12th November 2009, 10:06
I forgot to send the diagram for the CA3089. Sorry... I will soon.

Now about the bar at 0, why not put an IF-THEN statement after ADC subroutine to test if the ADC result is 0.

Or the more elegant Darrel's solution. Same result.

Ioannis

Glenn
- 7th February 2010, 00:04
Unfortunatly CA3089 seem to be discontinued, and hard to get, well, tehre are a few on ebay, but more common places seem to be out of stock ?

I would love to see the schematics you used anyway Ioannis.

Ioannis
- 7th February 2010, 12:19
On the attached check page 8-29 the up left schematic. Output is on pin 13 and there is no need for coils etc as that part is not needed. In fact no components are needed on the pins 5,6,7,8,9,10,12 and 15.

On 13 there must be a load resistor to get the output voltage and on input pin 1 the capaciotors from .01 and .02 should be large enough for the audio spectrum as the values shown are for 10,7MHz IF. Put 10 or even 100 uF to get decent low freq. response. The chip works from almost 0 Hz!

Ioannis

SKOLS1
- 28th January 2011, 09:14
I have a problem with this program.I made everything,put the .bas file in the same folder where the program is.But when I compile it,it says that I have a WARNING: Unable to open INCLUDE file LCDBAR_INC.BAS. I made a extension .bas file for the Include file and it's not working:( any sugestion?

HenrikOlsson
- 28th January 2011, 10:09
Hi,
It works perfectly fine here. Make sure you have the file in the correct folder (either in the same folder as your source file or in the PBP folder). Also make sure that the actual filename, including extension, matches exactly what it says in the code.

INCLUDE "LCDBar_INC.bas"

The filename should be LCDBar_INC.bas but when you download it from the first post in this thread it's LCDBar_INC.bas.txt and you need to remove the .txt from the end.

/Henrik.

SKOLS1
- 28th January 2011, 10:36
I did that,but it's not working.When I make an extension of the .txt file in .bas file I go File> Save as.. and File name:LCDbar_INC.bas.bas Save as type:All files Encoding:ANSI
Is there a problem?Am I Ок?

HenrikOlsson
- 28th January 2011, 11:15
There's no need to open that file. Just right-click on it, select rename and remove the .txt extension - don't add another .bas extension.

Make sure that the filename is LCDBar_INC.bas Not LCDBAR_INC.bas.txt or LCD_Bar_Inc.bas.bas or anything else - just LCDBar_INC.bas

5113

SKOLS1
- 17th February 2011, 16:35
I have a problem when i compile the code.It says this:
WARNING Line 1: Bad token "ï".
WARNING Line 1: Bad token "»".
WARNING Line 1: Bad token "¿".

HenrikOlsson
- 17th February 2011, 16:46
What code exactly is it you're trying to compile? I've tried compiling LCDBar_INC.bas by itself as well as INCLUDED from another program and it compiles just fine.

Post the code you're trying to compile and we'll take a look.

SKOLS1
- 17th February 2011, 16:50
I compile the first code: LCDbar_AD_Demo.bas.txt and when I save as I save it in a new folder,the include file I save at in the folder where the first code is.Where I get wrong?

HenrikOlsson
- 17th February 2011, 17:12

The code tries to set the CONFIG bits so for now, try commenting out or deleting the very first line:

' @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H ' <-- Comment this line. Set oscillator to (HS)

I don't think this is the problem but I hope so because if it's not I have no idea :-(

SKOLS1
- 17th February 2011, 17:39
I'am so angry cause I can't compile the code.Can somebody compile it and put the hex file on the forum,then I can download it and program the PIC with it.I use 2*16 LCD display.

HenrikOlsson
- 17th February 2011, 17:46
Hi,
In order to compile it for you we must at least know which PIC you're using and what you're oscillator speed is.

Which version of PBP are you trying to compile this with and for which PIC?

ChrisMicro
- 2nd March 2011, 00:28
I'am so angry cause I can't compile the code.Can somebody compile it and put the hex file on the forum,then I can download it and program the PIC with it.I use 2*16 LCD display.
Did you try the bar graph code that I have posted at the beginning of this thread? it is standalone and no include files to worry about, no need to download just copy the code and paste it.

SKOLS1
- 29th May 2011, 12:41
I fix the problem with the extension of the file LCDbar_INC.bas, but now I have this problem I compile the code but can I use 2*16 LCD display?I use PIC16F887 @ 20MHz

mister_e
- 29th May 2011, 18:36
Sure you can.

SKOLS1
- 30th May 2011, 13:16
But now it's working,baragraph isn't showing on the LCD display,just Value: 1,2 etc.
I use 2*16 LCD display.Should I change the code in LCDbar_INC.bas

mister_e
- 30th May 2011, 15:33
Must be intranet interference, my crystal ball refuse to give me your code, could you post your code here and PIC model, so we could see what's wrong with? ;)

SKOLS1
- 30th May 2011, 19:58
define OSC 20
CLEAR

INCLUDE "LCDbar_INC.bas" ' Include the BARgraph routines

' Define LCD connections
DEFINE LCD_DREG PORTB ' LCD Data Port
DEFINE LCD_DBIT 0 ' Starting Data Bit
DEFINE LCD_RSREG PORTB ' Register Select Port
DEFINE LCD_RSBIT 4 ' Register Select Bit
DEFINE LCD_EREG PORTB ' Enable Port
DEFINE LCD_EBIT 5 ' Enable Bit
DEFINE LCD_BITS 4 ' Data Bus Size
DEFINE LCD_LINES 2 ' Number of Lines on LCD

Value VAR WORD ' Must be a WORD even though AD is 8bit

LCDOUT $FE, 1 ' Clear Screen PAUSE 200 Loop1: ADCIN 0, Value LCDOUT$FE,2,"Value = ",DEC Value," "
; syntax- BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _Value, 2, 0, 16, 255, lines

Goto Loop1

END

I use PIC16F877 @ 20MHz(I use 8 MHz,too) I delete the frist line because there is an error in compiling

Christopher4187
- 20th November 2012, 14:55
Hopefully someone smarter than me can figure this out. Darrel, this program is awesome by the way!

I'm using an OLED screen and Darrel's anypin LCD program. The OLED screen works perfectly with the data displayed but not with bargraph program. Anyhow, have a for-next loop counting to 512. It runs perfectly up until 32 or so and then displays strange stuff until it hits 99 then it's good again until about 155 then bad again until about 222 then good again until 272 then bad until about 342 then good until about 388 then bad until about 462 and then it goes to 512 and loops back around. The program looks like this:

DEFINE OSC 48

include "LCDBAR_INC.PBP"
'================================================= ==============================
' OLED CHANGE
'================================================= ==============================
'===============================ENABLE FOR CAR PROGRAM=========================='
LCD_DB4 VAR PORTE.0
LCD_DB5 VAR PORTE.1
LCD_DB6 VAR PORTE.2
LCD_DB7 VAR PORTA.4
LCD_RS VAR PORTB.6
LCD_E VAR PORTB.7
'================================================= ===============================

LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
LCD_DATAUS CON 50 ' Data delay time in us
LCD_COMMANDUS CON 2000 ' Command delay time in us
INCLUDE "LCD_AnyPin.PBP" ; *** Include MUST be AFTER LCD Pin assignments ****

' ================================================== ============================
' CONFIGS
'================================================= ==============================

@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_OFF_2L & _BORV_3_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32768_2H
@ __CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_ON_4L & _XINST_OFF_4L

'================================================= =============================
' SETTINGS
' ================================================== ============================
'76543210 '76543210
TRISA = %00100110: PORTA = %00000000
TRISB = %00010001: PORTB = %00010000
TRISC = %00000000: PORTC = %00000001
TRISD = %11011100: PORTD = %00000000
TRISE = %00010000: PORTE = %00010000

CMCON = 7
SSPSTAT = %01100100
SSPCON1 = %00100001
BAUDCON = %00001111

CCP2CON = %00011100 'changed on 11/16/12
CCP1CON = %00011100 'changed on 11/16/12

X VAR WORD

MainLoop:
FOR X=1 TO 512
PAUSE 100

LCDOUT $FE,148,DEC X," " '@ BARgraph Value, Row, Col, Width, Range, Style @ BARgraph _X, 1, 0, 20, 512, lines NEXT X GOTO MAINLOOP 6738 6739 I've tried a bunch of stuff (changing the parameters on the @ bargraph line but nothing seemed to help. This is the OLED screen I'm using: http://www.newhavendisplay.com/specs/NHD-0420DZW-AY5.pdf Darrel Taylor - 20th November 2012, 18:29 Everytime I hear Newhaven, I cringe. Here's your program running on a 4550 at 48Mhz in the simulator. So I don't think it's a programming issue. http://support.melabs.com/DT/Bargraph.gif It could be an R-M-W problem. Is the LCD connected via a ribbon cable? If so how long? Have you tried running the CPU at 20Mhz without the PLL? Or it could be just another Newhaven issue. Have you tried a normal LCD? Christopher4187 - 21st November 2012, 11:14 I did a lot of testing last night and it does appear to be the OLED screen that has issues. I have two OLED screens mounted on two different pieces of equipment and with the code above they do the same thing. I then put a standard LCD screen (2X16) through the same tests and it worked perfectly. I now have more questions than answers. Everytime I hear Newhaven, I cringe.Why? They work perfectly with displaying letters and numbers and the OLED screen is so much better than an LCD screen. I'm guessing you've had problems with them in the past? Here's your program running on a 4550 at 48Mhz in the simulator.That thing is pretty cool. Where can I get it? After some testing, here is some information that may be useful.........or may not be. With the following line of code: @ BARgraph _X, 0, 0, 20, 512, linesThe software will work perfectly from 0 to 33. If I use a For/Next routine for 0-33, it will run with no problems for hours on end (I know it will, trust me!) When I put 0-34, it flakes out when it gets to 34 and only 34. When it rolls back around, the same thing happens. 0-33 works good and then 34 won't, up until 98 or so. I don't get that. By changing to the following code: @ BARgraph _X, 0, 1, 20, 512, linesNow 0-110 works perfectly. The only thing I did was move the column from 0 to 1! Riddle me that one! Also, if I just change to this code @ BARgraph _X, 0, 1, 20, 10000, linesNow it will count much higher without a problem. Dave - 21st November 2012, 12:45 Wow, is that thing slowwwwwwww. 600uS. for just about any of the control instructions? I really think you need to check your command and data delay settings. If I was using it I would also operate it in 8 bit mode. Twice as fast..... I also suggest reading the busy flag because if you are not then you are probably sending it instructions while it is executing the last instruction. Christopher4187 - 21st November 2012, 14:08 Wow, is that thing slowwwwwwww. 600uS. for just about any of the control instructions? I really think you need to check your command and data delay settings. If I was using it I would also operate it in 8 bit mode. Twice as fast..... I also suggest reading the busy flag because if you are not then you are probably sending it instructions while it is executing the last instruction.If the command and data delay settings are wrong or the device is too slow, why does it work perfectly with displaying letters and numbers? In addition, I could put a for/next loop from 0 to 33 and the bargraph routine runs perfectly hours on end. More testing reveals this: Range.... Number where the bargraph is not displayed correctly 64 .... 4 128 .... 8 256 .... 16 512 .... 34 1024 .... 66 2048 .... 132 This means something, just not sure what. The one common thing I can see is that when one box (three vertical "l"'s) fills up, the next time the bargraph routine attempts to write to the next box, it will fail. If I adjust the column from 0 to 1, it will now allow me to successfully write four boxes instead of one. mackrackit - 21st November 2012, 16:03 why does it work perfectly with displaying letters and numbers? Maybe that is all it is good for? Darrel Taylor - 21st November 2012, 17:57 A vast majority of people that call tech support with LCD problems, are using Newhaven displays. It doesn't seem to matter what type (LCD, OLED, COG). But i agree with Dave, the timing requirements are ridiculous. It's even 600 uS for data transfers (per nibble) according to the datasheet. Try changing to this ... LCD_DATAUS CON 600 ' Data delay time in us (was 50) Christopher4187 - 21st November 2012, 18:04 Maybe that is all it is good for?C'mon, man! We don't give up that easily! It's not a timing issue because it runs fine at 25uS or 1000uS. I've found a conflict with the "LCDbar_INC" program and the OLED screen. When the LCDbar program attempts to write to even columns, it displays wacky stuff. When it writes to odd columns, it works like a champ! I'll explain more in detail when I get home from work. I got it working.....sort of.... mackrackit - 21st November 2012, 20:09 C'mon, man! We don't give up that easily! Life is too short to play with junk. Yes, I would give up and get a unit that works. Christopher4187 - 22nd November 2012, 16:20 I'm not smart enough to figure out why this is happening but the problem has been identified. Whenever the program sends "Threebars," it goes wacky. If I modify the code from this: SELECT CASE BARtemp CASE IS > BARloop LCDOUT ThreeBARS ; send 3 bars ||| CASE IS < BARloop to this: SELECT CASE BARtemp CASE IS > BARloop CASE IS < BARloop it will run fine. Of course only two bars will be displayed but something with the code is causing a problem in the display. I made a bargraph routine and it works just fine so the problem is a conflict between the lcdbar inlcude file and the OLED screen. There isn't enough experience in my brain to figure out why so maybe someone else can. It was a good experience for me because I never used bargraphs before and I learned a lot from DT's program. The only thing I don't like about the program below is that it keeps writing over the previous graph, even if the data doesn't change, so if the bargraph stays at 100% or a high amount, you can see the bargraph flicker a little bit. I'm guessing that a routine is needed whereby nothing is written unless the number changes. C0 VAR BYTE C1 VAR BYTE C2 VAR BYTE C3 VAR BYTE C4 VAR BYTE C5 VAR BYTE C6 VAR BYTE C7 VAR BYTE C0 =$40
C1 = $48 C2 =$50
C3 = $58 C4 =$60
C5 = $68 C6 =$70
C7 = $78 lcdout 254,C0,REP 16\8 lcdout 254,C1,REP 24\8 lcdout 254,C2,REP 28\8 lcdout 254,C3,REP 30\8 lcdout 254,C4,REP 31\8 BOX VAR WORD LINE VAR WORD FRICT_PAD_TQ_BAR VAR WORD LINE_DISPLAY VAR BYTE BOX_DISPLAY VAR BYTE FRICT_PAD_TQ VAR WORD MAIN: FRICT_PAD_TQ_BAR=(FRICT_PAD_TQ-12)/5 BOX_DISPLAY=127 LINE_DISPLAY=0 FOR LINE = 0 TO FRICT_PAD_TQ_BAR LCDOUT$FE, BOX_DISPLAY,LINE_DISPLAY
LINE_DISPLAY=LINE_DISPLAY+1
IF LINE_DISPLAY=5 THEN
BOX_DISPLAY=BOX_DISPLAY+1
LINE_DISPLAY=0
ENDIF
LCDOUT $FE,212, DEC FRICT_PAD_TQ_BAR NEXT LINE BOX_DISPLAY=0 LINE_DISPLAY=0 GOTO MAIN Dave - 23rd November 2012, 00:22 Chris, Have you written code to look at the BUSY bit? I think you would be a bit supprised to find out just how long it takes some SPOOLED commands to execute. I have had this problem before with some NewHaven displays and with there lack of documentation you just have to figure out things on your own. What I would do is, write a routine to first set an output bit and connect a scope, then look at the busy bit after you send a command string to the display. re-check the busy bit to be clear, reset the output bit when the bit is clear and you would be supprised. Why do you think they make it available? You as the programmer are supposed to knowlegable enough to use the BUSY bit. Otherwise, don't complain about someone elses routines not working unless you know what the problem is....... Happy Thanksgiving...... Christopher4187 - 23rd November 2012, 02:35 Otherwise, don't complain about someone elses routines not working unless you know what the problem isIt wasn't a complaint, Yoda. I said there was a conflict between DT's program and the OLED screen. That's a factual statement. In fact, I'm very appreciate of the information Darrel posts on here. Exhibit A: Darrel, this program is awesome by the way! I learned a lot from DT's program. I've been using the OLED screens for over a year now. I know people have had problems with the displays but I really like them and never had a problem. If you know of a better OLED screen, by all means a better suggestion is always welcomed. Do you think people on here use Newhaven LCD/OLED screens? I'd be inclined to say yes. Given that fact, someone along the way is going to run into this same problem. If there's a simple solution or a new line of code can be inserted to make it work correctly, why not do it? The main intent of the post was to elicit substantive discussion regarding the Newhaven OLED screen and DT's program. It doesn't work "off the shelf," which is perfectly fine. However, if Darrel or anyone else can provide a solution to make the program work, that would be great, but everyone on here understands there are no obligations. I don't have enough programming knowledge to contribute a lot here, so maybe this is a chance for me to do so if nobody else has the time to do it. Personally, a lot of time has been spent on this and I'm really learning a lot. Even if I don't find a solution, it's time well spent. Dave - 23rd November 2012, 14:14 Chris, Just use the busy bit to confirm the display is ready for the next command.... As I said in the my first return post, the commands are processed by the display far too slowly and I see no delays in your code after any of the cursor control commands and you are probably running it in 4 bit mode as opposed to 8 bit mode which now allows for even more data to be lost. looking at the timing constraints in the data sheet, I'm supprised the thing is working at all. The processor onboard the display is probably doing far more work than your code is. If you are commited to using this type of display with it's down falls because it looks good then you MUST you it as it was intended to be used it you expect it to relay the information correctly. No more to say... Christopher4187 - 23rd November 2012, 16:05 looking at the timing constraints in the data sheet, I'm supprised the thing is working at all. ....If you are commited to using this type of display with it's down falls because it looks good then you MUST you it as it was intended to be used it you expect it to relay the information correctly. No more to say...:rolleyes: Anyhow, for anyone who is using a Newhaven OLED display and wants to use Darrel's bargraph routine, you only have to modify a few things, which only takes about 30 seconds to do so. Here is what you need to do: Make this portion of the code: LCDOut$FE,$40,REP$15\8 ; Custom char 0 - 3 lines |||
LCDOut $FE,$48,REP $14\8 ; Custom char 1 - 2 lines || LCDOut$FE,$50,REP$10\8 ; Custom char 2 - 1 line |
To make it look like this:

LCDOut $FE,$48,REP $15\8 ; Custom char 0 - 3 lines ||| LCDOut$FE,$50,REP$14\8 ; Custom char 1 - 2 lines ||
LCDOut $FE,$58,REP $10\8 ; Custom char 2 - 1 line | You have change the numbers in the other two character sets if you use blocks and boxes. You also have to modify this code: ThreeBARS CON 0 ; Identify the Custom Characters TwoBARS CON 1 OneBAR CON 2 To this: ThreeBARS CON 1 ; Identify the Custom Characters TwoBARS CON 2 OneBAR CON 3 By modifying the lines of code above, the bargraph will display correctly on your OLED screen. I tested the bargraph a few different ways and it worked 100% of the time. I hope this is able to help someone. SteveB - 23rd November 2012, 18:39 THE CHANGES IN THE ABOVE POST ARE INCOMPLETE!!! If you make those modifications, you need to change all of the custom character declarations. Otherwise, the other styles will not work properly. Here are the other modifications (shown with the first set for context): ; --- lines Style custom chars ---- CharsetLines: LCDOut$FE,$48,REP$15\8 ; Custom char 0 - 3 lines |||
LCDOut $FE,$50,REP $14\8 ; Custom char 1 - 2 lines || LCDOut$FE,$58,REP$10\8 ; Custom char 2 - 1 line |
RETURN

; --- boxed Style custom chars ----
CharsetBoxed:
LCDOut $FE,$48,$1F,REP$15\6,$1F ; III LCDOut$FE,$50,$1C,REP $14\6,$1C ; II
LCDOut $FE,$58,REP $10\8 ; I RETURN ; --- blocks Style custom chars ---- CharsetBlocks: LCDOut$FE,$48,REP$1F\8
LCDOut $FE,$50,REP $1C\8 LCDOut$FE,$58,REP$10\8
RETURN

Darrel Taylor
- 23rd November 2012, 18:39
So, what you're saying is that if you use Custom Character 0 on those displays, everything goes crazy?
Displaying the wrong characters on the wrong lines.

And by just not using Cust. Char 0, everythings AOK?

That's a new one ... but it sounds typical for Newhaven.

Christopher4187
- 23rd November 2012, 19:28
THE CHANGES IN THE ABOVE POST ARE INCOMPLETE!!!

If you make those modifications, you need to change all of the custom character declarations. Otherwise, the other styles will not work properly. Here are the other modifications (shown with the first set for context):No kidding. Did you read my post?
You have change the numbers in the other two character sets if you use blocks and boxes.

So, what you're saying is that if you use Custom Character 0 on those displays, everything goes crazy?
Displaying the wrong characters on the wrong lines.

And by just not using Cust. Char 0, everythings AOK?

That's a new one ... but it sounds typical for Newhaven.Yup. I tried this on both displays with different programs. Whenever a 0 is used, the display gets all wacky. It will not only display the characters on the wrong line, the entire OLED displays wacky stuff. (I took two crappy cell phone pics of the differences). You also have to change the LCDOUT commands too. If you don't, it will still work but the box won't be filled out completely.

I tested it a bunch of different ways and I couldn't make it fail. Perhaps I didn't test every single mode but what I did test (what I normally use) worked perfectly!67416742

SteveB
- 24th November 2012, 01:26
Darrel, I hope you don't mind. ;)

Here is a modified version of Darrel's code that accommodates the flaw in the Newhaven Display Firmware preventing use of CGRAM location 0. (Changes I made are highlighted in blue)

'************************************************* ***************
'* Creates a variable sized BAR-graph anywhere on the screen *
'************************************************* ***************
'* Name : LCDbar_INC_MOD1.bas *
'* Original: *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2005 *
'* Date : 9/8/2005 *
'* Version : 1.0 *
'* Notes : Maximum Range is 32768 *
'* : Range must always be a Constant *
'* : Value must always be a WORD variable *
'* : *
'* Modified : By SteveB on 11/23/2012 *
'* : The original include has been modified to *
'* : accomodate a flaw in Newhaven OLEDs firmware. *
'* : By using the define below, it will adjust the *
'* : custom CGRAM character locations used to 1-3 *
'* : (vs. 0-2). *
'* : *
'* : If using a flawed Newhaven Display add the *
'* : following define BEFORE the INCLUDE statement: *
'* : *
'* : DEFINE NEWHAVEN_DISPLAY 1 *
'* : *
'************************************************* ***************

BAR_width VAR BYTE : BAR_width = 16 ; Width of the BARgraph 16
BAR_range VAR WORD : BAR_range = 100 ; Range of Values (0-100) 100
BAR_row VAR BYTE : BAR_row = 1 ; Row location (1-4) 1
BAR_col VAR BYTE : BAR_col = 0 ; Column location (0-15) 0
BAR_value VAR WORD : BAR_value = 0 ; Current BAR value 0
BAR_style VAR BYTE : BAR_style = 1 ; 1=lines, 2=boxed, 3=blocks 1

; --- Temporary vars ----
BARtemp VAR WORD
Remainder VAR WORD
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
Limit1 VAR WORD

GOTO overBAR ; Skip over Subroutines

ThreeBARS CON EXT
TwoBARS CON EXT
OneBAR CON EXT
CharLoc3 CON EXT
CharLoc2 CON EXT
CharLoc1 CON EXT

ASM
ifdef NEWHAVEN_DISPLAY
ThreeBARS = 1 ; Identify the Custom Characters
TwoBARS = 2
OneBAR = 3
else
ThreeBARS = 0 ; Identify the Custom Characters
TwoBARS = 1
OneBAR = 2
endif

CharLoc3 = 40h +(ThreeBARS*8)
CharLoc2 = 40h +(TwoBARS*8)
CharLoc1 = 40h +(OneBAR*8)

lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM

; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,CharLoc3,REP$15\8 ; Custom char 0 - 3 lines |||
LCDOut $FE,CharLoc2,REP$14\8 ; Custom char 1 - 2 lines ||
LCDOut $FE,CharLoc1,REP$10\8 ; Custom char 2 - 1 line |
RETURN

; --- boxed Style custom chars ----
CharsetBoxed:
LCDOut $FE,CharLoc3,$1F,REP $15\6,$1F ; III
LCDOut $FE,CharLoc2,$1C,REP $14\6,$1C ; II
LCDOut $FE,CharLoc1,REP$10\8 ; I
RETURN

; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,CharLoc3,REP$1F\8
LCDOut $FE,CharLoc2,REP$1C\8
LCDOut $FE,CharLoc1,REP$10\8
RETURN

; ----- Show the BAR graph -----------------------------------------------------
ShowBAR:
IF BAR_width = 0 then BARdone
if LastCharset <> BAR_style then ; If the Style has changed ?
LastCharset = BAR_style
SELECT CASE BAR_style ; Load the new custom chars
CASE 1 : GOSUB CharsetLines
CASE 2 : GOSUB CharsetBoxed
CASE 3 : GOSUB CharsetBlocks
END SELECT
endif

@ ifdef LCD4X20
LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp @ else LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
@ endif
LCDOUT $FE, BARtemp + BAR_col ; Move cursor to start of the BAR BARtemp = BAR_value * BAR_width ; calc the char position BARtemp = DIV32 BAR_range Remainder = R2 For BARloop = 0 to BAR_width -1 SELECT CASE BARtemp CASE IS > BARloop LCDOUT ThreeBARS ; send 3 bars ||| CASE IS < BARloop LCDOUT " " ; clear to end of BARwidth CASE IS = BARloop Limit1 = BAR_range * 6 Limit1 = DIV32 10 if Remainder >= Limit1 then LCDOUT TwoBARS ; send 2 bars || else Limit1 = BAR_range * 3 Limit1 = DIV32 10 if Remainder >= Limit1 then ; 30% LCDOUT OneBAR ; send 1 bar | else LCDOUT " " ; no bars endif endif END SELECT NEXT BARloop BARdone: RETURN ASM ; --- The main macro for creating BARgraphs ------------------------------------ BARgraph macro Value, Row, Col, Width, Range, Style MOVE?CW Range, _BAR_range ; Range MUST be a constant MOVE?WW Value, _BAR_value ; Value MUST be a WORD variable if (Row < 5) ; Row is a constant MOVE?CB Row, _BAR_row else ; Row is a variable MOVE?BB Row, _BAR_row endif if (Col < 16) ; Is Col a constant ? MOVE?CB Col, _BAR_col else ; NO, it's a variable MOVE?BB Col, _BAR_col endif if (Width <= 40) MOVE?CB Width, _BAR_width else MOVE?BB Width, _BAR_width endif if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ? MOVE?CB Style, _BAR_style else ; NO, treat it like a variable MOVE?BB Style, _BAR_style endif L?CALL _ShowBAR endm ENDASM overBAR: Of course, more could be done to make this even more flexible, but this is at least a tidy way do deal with this particular problem. Christopher4187 - 24th November 2012, 02:02 (Changes I made are highlighted in blue)I'm glad I was able to help. '* : If using a flawed Newhaven Display add the * '* : following define BEFORE the INCLUDE statement: It doesn't matter where you put this statement. Top, bottom, side, back, inbetween, etc. It will work no matter it is. SteveB - 24th November 2012, 02:55 Christopher, I wasn't slighting your contribution, sorry if it came across that way. I seriously don't think anybody would have figured it out without the testing you did (ok, maybe Darrel if he decided to take it on as a project). It is certainly a unique problem. My posts were both aimed at the community at large. Initially to aviod any confusion by a would be user that is less diligent than yourself. Then, to offer a more comprehensive solution that could be used as a substitute for the original include file. (I would have sent it to Darrel via PM initially for his approval, and possible change to the original file, but since he is a big-wig at ME now, he doesn't accept PMs anymore. :p) And yes, you are correct, that DEFINE can probably go anywhere and it will still work. (I was playing it safe due to limited time to write and test the code for errors while my 3 kids were playing sword-fighting in the living room with me ducking occasionally to avoid a head wound :eek: ). If Darrel is inclined to correct that statement via his Moderator powers, I've got no problem with that. I also missed coloring the second "CharLoc1" blue. Best Regards, Steve Christopher4187 - 24th November 2012, 03:06 No worries. I like to be sarcastic and I'm difficult to offend. In my 7 years (on and off) this forum, it was the first time I was able to provide a contribution that may help other people. :D Christopher4187 - 27th November 2012, 10:56 Is there a way to modify the code to display from the right to the left? I've tried a number of different things but it doesn't work correctly. Darrel Taylor - 27th November 2012, 19:10 Let the display do the hard work by using the Right to Left "Entry Mode". Then just change the custom characters. No changes are required to the include file. http://support.melabs.com/DT/Bargraph_R-L.gif X VAR WORD ;----[Initialize bargraph]------------------------------------------------------ X = 0 @ BARgraph _X, 1, 1, 20, 512, lines LCDOut$FE,$48,REP$15\8 ; Custom char 1 - 1 line |
LCDOut $FE,$50,REP $05\8 ; Custom char 2 - 2 lines || LCDOut$FE,$58,REP$01\8 ; Custom char 3 - 3 lines |||

;----[Main Program Loop]--------------------------------------------------------
MainLoop:
FOR X=1 TO 512
PAUSE 10
LCDOUT $FE,$94,DEC X," "

LCDOUT $FE,$04 ; Set Entry mode Right to Left
'@ BARgraph Value, Row, Col, Width, Range, Style
@ BARgraph _X, 1, 20, 20, 512, lines
LCDOUT $FE,$06 ; Restore Entry mode Left to Right

NEXT X
GOTO MAINLOOP

Of course, I'm assuming the Newhaven display can actually do that. :rolleyes:
Normal LCD's can.

SteveB
- 27th November 2012, 19:59
Darrel, I know you know what happens when one assumes. ;)

Christopher4187
- 28th November 2012, 02:59
Of course, I'm assuming the Newhaven display can actually do that. Are Newhaven LCD's the redheaded step children of LCD's? I've never had a problem with them. Then again, I don't make many projects that have displays and if I do need one I don't look at the manufacturer when ordering one. If I was using an LCD, I'd go with whoever is the cheapest. Regarding OLED, it's the first time I've used one and the Newhaven OLED's are awesome. I am making a product for a car and the screen doesn't get washed out in the light and it's not too bright at night time. It's perfect!

Anyhow, thanks for the help. I spent a little more than 6 hours trying to get it but you pushed the easy button! Regarding your comment, the display WILL show the bargraph but for some reason you have to modify this line:
BARgraph _X, 1, 20, 20, 512, lines
To this:
BARgraph _X, 1, 19, 20, 512, lines
If you don't modify it, the bargraph will sit in column one with three bars displayed while the number counts from 1 to 512. I guess you can add this to the "uniqueness" of Newhaven displays! ;)

SteveB
- 28th November 2012, 05:26
So, I know that Darrel provided a nice hardware solution. But, like a dog with a new bone, I wanted to work out a software solution.

When using the modified include file, the only change needed in the main program is an additional parameter to @ BARgraph:

@ BARgraph Value, Row, Col, Width, Range, Style, RtoL
0 = Left to Right, 1 = Right to Left

Here is the code, the file is below:

'************************************************* ***************
'* Creates a variable sized BAR-graph anywhere on the screen *
'************************************************* ***************
'* Name : LCDbar_INC_MOD2.bas *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2005 *
'* Date : 9/8/2005 *
'* Version : 1.0 *
'* Notes : Maximum Range is 32768 *
'* : Range must always be a Constant *
'* : Value must always be a WORD variable *
'* : *
'* Modified : By SteveB on 11/23/2012 *
'* : The original include has been modified to *
'* : accomodate a flaw in Newhaven OLEDs firmware. *
'* : By using the define below, it will adjust the *
'* : custom CGRAM character locations used to 1-3 *
'* : (vs. 0-2). *
'* : *
'* : If using a flawed Newhaven Display add the *
'* : following define statement: *
'* : *
'* : DEFINE NEWHAVEN_DISPLAY 1 *
'* : *
'* Modified : By SteveB on 11/27/2012 *
'* : This modification introduces the ability to *
'* : display the bargraph from Right-to-Left. *
'* : *
'************************************************* ***************;
;@ BARgraph Value, Row, Col, Width, Range, Style, RtoL
;
;Value: The Value of the BARgraph (0 to Range).If Range = 100 and Value is 50, then
; half of the BARgraph will be filled in. Value MUST be a WORD sized variable¹
;
;Row: LCD Row to place the BARgraph (1 to 4) can be either a constant or a
; variable¹.
;
;Col: LCD Column to place the BARgraph (0 to LCDsize² - 1) can be either a constant
; or a variable¹.
;
;Width: Width of the BARgraph in charaters. (1 to LCDsize²) can be either a constant
; or a variable¹.
;
;Range: The "full-scale" range of the BARgraph (0 to 32768) MUST be a constant.
; Variables will not work here.
;
;Style: Selects which Style will be used for the BARgraph (lines, boxed, blocks) can
; be either a constant or a variable¹.
;
;RtoL: MUST be a constant
; When set to 0, Bar will display Left-to-Right
; When set to 1, Bar will display Right-to-Left
;
;Note ¹ - Variables must be preceeded with a
; underscore. ie. _Temperature
;Note ² - LCDsize is the number of Chars in 1 line of
; the LCD, for "4x16" it's 16
; ; default
BAR_width VAR BYTE : BAR_width = 16 ; Width of the BARgraph 16
BAR_range VAR WORD : BAR_range = 100 ; Range of Values (0-100) 100
BAR_row VAR BYTE : BAR_row = 1 ; Row location (1-4) 1
BAR_col VAR BYTE : BAR_col = 0 ; Column location (0-15) 0
BAR_value VAR WORD : BAR_value = 0 ; Current BAR value 0
BAR_style VAR BYTE : BAR_style = 1 ; 1=lines, 2=boxed, 3=blocks 1
BAR_RtoL VAR BYTE : BAR_RtoL = 0

; --- Temporary vars ----
BARtemp VAR WORD
Remainder VAR WORD
BARloop VAR BYTE
LastCharset VAR BYTE : LastCharset = 0
LastRtoL VAR BYTE : LastRtoL = 0
Limit1 VAR WORD

GOTO overBAR ; Skip over Subroutines

ThreeBARS CON EXT ; Identify the Custom Characters
TwoBARS CON EXT
OneBAR CON EXT
CharLoc3 CON EXT
CharLoc2 CON EXT
CharLoc1 CON EXT

ASM
ifdef NEWHAVEN_DISPLAY
ThreeBARS = 1
TwoBARS = 2
OneBAR = 3
else
ThreeBARS = 0
TwoBARS = 1
OneBAR = 2
endif

CharLoc3 = 40h +(ThreeBARS*8)
CharLoc2 = 40h +(TwoBARS*8)
CharLoc1 = 40h +(OneBAR*8)

lines = 0x10000001 ; Define the Styles
boxed = 0x10000002
blocks = 0x10000003
ENDASM

; --- lines Style custom chars ----
CharsetLines:
LCDOut $FE,CharLoc3,REP$15\9 ; Custom char 3 lines |||
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,REP$14\9 ; Custom char 2 lines ||
LCDOut $FE,CharLoc1,REP$10\9 ; Custom char 1 line |
ELSE
LCDOut $FE,CharLoc2,REP$05\9 ; Custom char 2 lines ||
LCDOut $FE,CharLoc1,REP$01\9 ; Custom char 1 line |
ENDIF
RETURN

; --- boxed Style custom chars ----
CharsetBoxed:
LCDOut $FE,CharLoc3,$1F,REP $15\7,$1F ; III
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,$1C,REP $14\7,$1C ; II
LCDOut $FE,CharLoc1,REP$10\9 ; I
ELSE
LCDOut $FE,CharLoc2,$07,REP $05\7,$07 ; II
LCDOut $FE,CharLoc1,REP$01\9 ; I
ENDIF
RETURN

; --- blocks Style custom chars ----
CharsetBlocks:
LCDOut $FE,CharLoc3,REP$1F\9
IF BAR_Rtol = 0 THEN
LCDOut $FE,CharLoc2,REP$1C\9
LCDOut $FE,CharLoc1,REP$10\9
ELSE
LCDOut $FE,CharLoc2,REP$07\9
LCDOut $FE,CharLoc1,REP$01\9
ENDIF
RETURN

; ----- Show the BAR graph -----------------------------------------------------
ShowBAR:
IF BAR_width = 0 then BARdone
if LastCharset <> BAR_style OR LastRtoL <> BAR_RtoL then ; If for change
LastCharset = BAR_style
LastRtoL = BAR_RtoL
SELECT CASE BAR_style ; Load the new custom chars
CASE 1 : GOSUB CharsetLines
CASE 2 : GOSUB CharsetBoxed
CASE 3 : GOSUB CharsetBlocks
END SELECT
endif

@ ifdef LCD4X20
LOOKUP BAR_row,[$80,$80,$C0,$94,$D4],BARtemp @ else LOOKUP BAR_row,[$80,$80,$C0,$90,$D0],BARtemp
@ endif
LCDOUT $FE, BARtemp + BAR_col ; Move cursor to start of the BAR BARtemp = BAR_value * BAR_width ; calc the char position BARtemp = DIV32 BAR_range Remainder = R2 IF BAR_RtoL = 0 THEN LCDOUT REP ThreeBARS\(BARtemp) ; send 3 bars ELSE IF BARtemp < BAR_width THEN LCDOUT REP " "\(BAR_width - BARtemp - 1) ; Clear up to BARtemp-1 ENDIF ENDIF IF BARtemp < BAR_width THEN Limit1 = BAR_range * 6 Limit1 = DIV32 10 if Remainder >= Limit1 then LCDOUT TwoBARS ; send 2 bars else Limit1 = BAR_range * 3 Limit1 = DIV32 10 if Remainder >= Limit1 then ; 30% LCDOUT OneBAR ; send 1 bar else LCDOUT " " ; no bars endif endif ENDIF IF BAR_RtoL = 0 THEN IF BARtemp < BAR_width THEN LCDOUT REP " "\(BAR_width - BARtemp - 1) ; clear till the end ENDIF ELSE LCDOUT REP ThreeBARS\(BARtemp) ; send 3 bars ENDIF BARdone: RETURN ASM ; --- The main macro for creating BARgraphs ------------------------------------ BARgraph macro Value, Row, Col, Width, Range, Style, RtoL MOVE?CW Range, _BAR_range ; Range MUST be a constant MOVE?WW Value, _BAR_value ; Value MUST be a WORD variable if (Row < 5) ; Row is a constant MOVE?CB Row, _BAR_row else ; Row is a variable MOVE?BB Row, _BAR_row endif if (Col < 16) ; Is Col a constant ? MOVE?CB Col, _BAR_col else ; NO, it's a variable MOVE?BB Col, _BAR_col endif if (Width <= 40) MOVE?CB Width, _BAR_width else MOVE?BB Width, _BAR_width endif if ((Style >= lines) & (Style <= blocks)) ; Is Style a valid constant ? MOVE?CB Style, _BAR_style else ; NO, treat it like a variable MOVE?BB Style, _BAR_style endif MOVE?CB RtoL, _BAR_RtoL L?CALL _ShowBAR endm ENDASM overBAR: 6745 SteveB - 28th November 2012, 05:31 Here's some sample code (no fancy animations): 'DEFINE NEWHAVEN_DISPLAY 1 'uncomment if needed INCLUDE "LCDbar_INC_MOD2.bas" wCounter VAR WORD LCDOUT$FE, $01 PAUSE 100 MAIN: FOR wCounter = 0 to 100 PAUSE 50 LCDOUT$FE, $80, DEC3 wCounter ;@ BARgraph Value, Row, Col, Width, Range, Style, RtoL @ BARgraph _wCounter, 1, 5, 13, 100, lines, 0 NEXT wCounter FOR wCounter = 100 to 0 STEP -1 PAUSE 50 LCDOUT$FE, $80, DEC3 wCounter ;@ BARgraph Value, Row, Col, Width, Range, Style, RtoL @ BARgraph _wCounter, 1, 5, 13, 100, lines, 0 NEXT wCounter GOTO MAIN Darrel Taylor - 28th November 2012, 18:54 Nicely done Steve. It works great. :cool: SteveB - 28th November 2012, 22:51 Thanks Darrel. :D Christopher4187 - 29th November 2012, 02:30 Works perfectly! Awesome job! fratello - 24th January 2013, 14:16 I saw a schematic of volt-ampermeter, with PIC, with a nice animation ... Two different scale on the same row !!! Using "empty boxes" for volts and "filled boxes" for ampers ...the number of boxes varies proportionally with the parameter (volts; ampers). Can this be done in PBP ?! Thanks ! Darrel Taylor - 25th January 2013, 02:09 Can this be done in PBP ? Yes it can ... http://support.melabs.com/DT/2BarsPerLine.gif Custom Characters ... http://support.melabs.com/DT/2BarsCustChar.png LCDOUT$FE,$48,$00,$00,$00,$00,$1F,$1F,$1F,$00 ' Cust Char #1 LCDOUT$FE,$50,$1F,$11,$1F,$00,$00,$00,$00,$00 ' Cust Char #2 LCDOUT$FE,$58,$1F,$11,$1F,$00,$1F,$1F,$1F,$00 ' Cust Char #3 fratello - 25th January 2013, 06:04 Wow ! Amazing ! THANK YOU, Mr.Darrel ! I will try to figure out how displaying ... fratello - 25th January 2013, 15:25 Let's say I read maximum 50 volts and maximum 5 ampers ; so one "empty box" = 5 volts and one "filled box" = 0.5 ampers. It's this "pseudo" code correct ?! for y=9 to 0 step -1 if volts >= (y*5) then if ampers >= (y * 1/2) then char = 3 LCDOUT$FE, $80, char,char,char,char,char,char,char,char,char,char Endif Endif I'm sure it's another way, much easiers, but I have -till now- no ideea ... SteveB - 25th January 2013, 16:04 Untested, likely needs some debugging, but at least the methodology should be clear. LCDPos VAR BYTE volts VAR WORD ' 0 to 500 representing 0 to 50.0 Volts Amps VAR BYTE ' 0 to 50 representing 0 to 5.0 Amps Char VAR BYTE FOR LCDPos = 0 TO 9 IF Volts / 50 >= LCDPos + 1 THEN ' Fill in Volt Block IF Amps / 5 >= LCDPos + 1 THEN ' Fill in Volt + Amp Block Char = 3 ELSE ' Fill in Volt Block Only Char = 2 ENDIF ELSE ' Don't Fill in Volt Block IF Amps / 5 >= LCDPos + 1 THEN ' Fill in Amp Block only Char = 1 ELSE ' Fill with Space Char = 32 ENDIF ENDIF LCDOUT$FE, $80 + LCDPos, Char NEXT LCDPos fratello - 25th January 2013, 16:33 Thank You, I will post the results ! Watermark - 23rd August 2013, 12:14 In this code what does "Rep" do? I'm using it with the Proton IDE Basic Compiler. It works OK, but I am curious as I can't find any reference to "Rep" in the documentation. Is it a repeat function? Thanks, Mark Print$FE, CGRAM, Rep $0\8,$0, Rep $10\6,$0,$0, Rep$14\6,$0,$0, Rep $15\6,$0,\$0

Warnings = OFF
Byte_Math = On
BARS = (TOP_BAR Min MAXBAR) / 3 ; One full bar for each 3 graph units
BALANCE = (TOP_BAR Min MAXBAR) //3 ; Balance is the remainder after a division by 3
BALF = BALANCE Min 1
Print At 1,1, Dec3 POWERMAX, "W "
Print At 1,6, Rep FULLBAR\BARS,Rep (BALANCE + BASEBAR)\BALF,Rep " "\B_WDTH - (BARS + BALF)
BARS = (LOW_BAR Min MAXBAR) / 3 ; One full bar for each 3 graph units
BALANCE = (LOW_BAR Min MAXBAR) //3 ; Balance is the remainder after a division by 3
BALF = BALANCE Min 1

Ioannis
- 23rd August 2013, 12:33
You are on the wrong forum. Here is MELABS PicBasic Forum.

But anyway, REP is just repeating the next character \times

Ioannis

Art
- 11th October 2013, 02:39
Hi, DON
Just turn your LCD 90° cckw !!!
Alain

Did a vertical graphing tachometer over time with a single custom char (far right in the video).

Just got to matrix rotate the byte and shift every byte in the custom char every frame to make room for the next vertical byte.
(this one has odometer effect on the elapsed timer as well :)

Ioannis
- 11th October 2013, 07:34
Hi Art. It is awesome! Really nice effect.

Ioannis

srspinho
- 11th October 2013, 22:03
Hi Art !

nice idea for the tachometer.

I have an old project, where I´m already using 8 custom chars to show darrel´s bargraph, and other "compressed characters, like "Km/l" , "L/h".

Is it possible to re-use the custom char to show the odometer efect and this nice tachometer or this is not possible ?

Is your code for the tachometer complicated ?

Thank you.

Sérgio

Art
- 12th October 2013, 03:54
Hi,
I'll post it go in it's own thread in a little bit.
The tach is interrupt driven, display is PBP.
I'm close to finishing something much nicer ;)

srspinho
- 12th October 2013, 05:34
Hi Art,

I Will wait for your post.

My best regards.

Sérgio

Art
- 14th October 2013, 07:22
Hi srspinho,

Unfortunately I have lost that code :(
In the end, for that project, I ditched both the graphing tachometer,
and the rolling odometer effect for the time display.
They both looked good on the desk where the project spent a couple of months,
but in the car, they both turned out to be a terrible idea.

I could see the peak on the tachometer graph, but not tell if it was the current
reading without looking hard, and the same with the elapsed time.
I went back to a plain vertical bargraph for the tachometer:

I do still have current code for the project that I wouldn't otherwise mind sharing entirely,
but I would mind spending the time making sense of it where it was not written for others.
It is only a collection of things available here, or substitutes for them done myself.
I did my own asm interrupts for example, but DT's interrupts do exactly the same thing.

I have an old project, where I´m already using 8 custom chars to show darrel´s bargraph, and other "compressed characters, like "Km/l" , "L/h".
Is it possible to re-use the custom char to show the odometer efect and this nice tachometer or this is not possible ?