BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Tue Oct 23, 2018 11:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: progress bar convertion
PostPosted: Tue Aug 06, 2013 10:24 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Hi all, i was looking for an lcd progress bar example program for basicmicro but could only find a sample in parallax basic shown below. Although i can read and have a basic understanding of what the program is trying to do i am still struggling to convert, especially with the index cco and data part. All i need it to do is add complete blocks one at a time (16) along the second row of the 2x16 lcd over 3 or 4 seconds to show the progress. any help would be appreciated. thanks
Code:
'
{$STAMP BS2sx}
' {$PBASIC 2.5}
' =========================================================================
'
'   File...... Bar Graph (Simple).bs2
'   Purpose... Demostrate A Simple Bar Graph
'   Author.... Chris Savage -- Parallax, Inc.
'   E-mail.... csavage@parallax.com
'   Started... 10-09-2005
'   Updated... 10-11-2005
'
'
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------

' This program shows how to draw a Simple Bar Graph Display on a Parallax
' 2X16 Serial LCD.  The subroutine needs only to know the highVal and the
' current index to display the Percent and Bar Graph.  Feel free to change
' the code to suit your own application.
'
' NOTE: This code includes other unused constants for the display so you
' have them, however if not used, these do not take up any memory in the
' BASIC Stamp, so they are good to have available.
'
' You can change the value of highVal and see how it affects things.
' highVal and index are Byte values and should never exceed 255.
'
' If you only want the BarGraph in the bottom of the display and not the
' numbers at the top, simply delete the first SEROUT line in the subroutine
' but be sure not to delete the line before it or the SEROUT after it.


' -----[ I/O Definitions ]-------------------------------------------------

'lCD             PIN     0               ' LCD Serial I/O Pin


' -----[ Constants ]-------------------------------------------------------

'LcdBkSpc        CON     $08             ' Move Cursor Left             8
'LcdRt           CON     $09             ' Move Cursor Right            9
'LcdLF           CON     $0A             ' Move Cursor Down 1 Line      10
LcdCls          CON     $0C             ' Clear LCD (Use PAUSE 5 After)   12
'LcdCR           CON     $0D             ' Move Pos 0 Of Next Line      13
LcdBLon         CON     $11             ' Backlight On               
'LcdBLoff        CON     $12             ' Backlight Off
'LcdOff          CON     $15             ' LCD Off
LcdOn1          CON     $16             ' LCD On; Cursor Off, Blink Off
'LcdOn2          CON     $17             ' LCD On; Cursor Off, Blink On
'LcdOn3          CON     $18             ' LCD On; Cursor On, Blink Off
'LcdOn4          CON     $19             ' LCD On; Cursor On, Blink On
LcdLine1        CON     $80             ' Move To Line 1, Column 0
LcdLine2        CON     $94             ' Move To Line 2, Column 0

LcdCC0          CON     $F8             ' Define Custom Char 0

Baud            CON     32              ' 19.2 Kbps (BS2)


' -----[ Variables ]-------------------------------------------------------

work            VAR     Byte            ' Work Variable
index           VAR     Byte            ' Current Value Of Count/Loop
highVal         VAR     Byte            ' Highest Value Expected
perCent         VAR     Byte            ' Percentage


' -----[ EEPROM Data ]-----------------------------------------------------

' Full Block Custom Character Data
CC0             DATA    LcdCC0, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F
'write LcdCC0, $1F, $1F, $1F, $1F, $1F, $1F, $1F, $1F

' -----[ Initialization ]--------------------------------------------------
'lcdinit p0\p1\p7\p6\p5\p4\,p2         ?
  HIGH LCD                              ' Setup Serial Output Pin
  PAUSE 100                             ' Give LCD Time To Settle

Download_Chars:
  FOR index = 0 TO 8                    ' Download Custom Characters
    READ CC0 + index, work              ' Read EEPROM Data
    SEROUT LCD, Baud, [work]            ' Send To LCD CGRAM

   'lcdwrite p0\p1\p7\p6\p5\p4,p2 [cgram+0,{work},scrram+0]
 
 
  NEXT

  SEROUT LCD, Baud, [LcdOn1, LcdBLon]   ' Turn LCD Display & Backlight On
                                        ' Backlight Only On Backlit Models
  PAUSE 10                              ' Allow LCD Time To Settle

  highVal = 255                         ' You can change this value to any
                                        ' Non-Zero value

' -----[ Program Code ]----------------------------------------------------

Main:
  DO
    'SEROUT LCD, Baud, [LcdCls]            ' Clear LCD Screen
    PAUSE 10                              ' Must Follow CLS

    FOR index = 0 TO highVal              ' Count To highVal
      GOSUB Disp_Graph                    ' Update Display
      PAUSE 20                            ' Small Delay
    NEXT

    PAUSE 3000                            ' Wait 3 Seconds Then Repeat

  LOOP                                    ' Forever
  STOP


' -----[ Subroutines ]-----------------------------------------------------

Disp_Graph:
  perCent = ((index * 100) / highVal)     ' Calculate Percent Value
'  SEROUT LCD, Baud, [LcdLine1, DEC3 index, " / ",
'    DEC3 highVal, " = ", DEC perCent, "%"]
  SEROUT LCD, Baud, [LcdLine2, "0%", REP 0\(perCent / 10),
    REP 32\(10 - (perCent / 10)), "100%"]
  RETURN


Top
 Profile  
 
 Post subject: Re: progress bar convertion
PostPosted: Wed Aug 07, 2013 9:29 am 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
The section your having problems with is basically an array of stored data where a custom character definition(solid bar) is stored in the program memory ready to be sent to the LCD's on board memory and this is a great way to do this when you need to define a SET of characters BUT in your case you only need to send the data for one new character so the use of the array is not needed at all,


You can simply send the command to the LCD first using :-

SEROUT LCD, Baud, [LcdCCo] ' Send CGRAM Command

FOR index = 0 TO 7 ' Download Custom Characters
SEROUT LCD, Baud, [0x1F] ' Send To LCD CGRAM, add any needed other data such as RAM address etc
NEXT


This will work to simplify the sending of the data as in this case the 8 bytes of data are all the same number,


It will be worth looking at the data sheet for the LCD you are using to check the commands are correct etc

I hope this helps,

Thanks,

Dave

BasicMicroUK
www.basicmicro.co.uk


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO