Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:03 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : writing a variable to a 1602a display in mmbasic

Author Message
Turrican
Newbie

Joined: 24/06/2019
Location: Sweden
Posts: 10
Posted: 06:25pm 14 Mar 2021
Copy link to clipboard 
Print this post

Hi!

I have been busy porting my solar tracker from a Duinomite to a Micromite, since the Micromite have no screen I bought a 1602a display. I would like to plot the value of different variables on it but it seems the LCD command expects a string and not a variable. Am I correct in thinking I need to convert my variable "A" to a string before using it with the LCD command?

example code of what I want to achieve:

Do
a=a+1
lcd 1,1,"Counter:"
lcd 2,1,a
pause 50
loop

/Tobias
There is NO need for more than 8-bits.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 06:34pm 14 Mar 2021
Copy link to clipboard 
Print this post

Hi Turrican,

If your 1602 display is a 16 character, 2 line display, this may be a good way:

'+--------------------------------------------------------------+
'|                     RMS convertor for MX170                  |
'+--------------------------------------------------------------+
' The RMS value of a signal is the R(oot)M(ean)S(quare) value.
' It is calculated by adding up the squares of the input signal
' The mean of these squares is rooted. This process is explained
' in the steps below.
' This example uses the ADC in the PIC32MX170 to measure the
' AC input signal. Output is displayed at a 16x2 LCD.

'----------------------  Defines -------------------------------
ADCpin = 23         ' ADC input pin
Total = 800         ' array size for measuring 220mSec @ 48MHz
Offset = 1.650      ' numeric offset at 3.300V
CalValue = 24.85    ' gain factor attenuator and AC coupling @ 50Hz

Option explicit
'------------------------- Dim Variables --------------------
Dim Sample!(Total)
Dim SumSQ!, Value!
Dim i%,j%,a%

'---------------------- Initialize hardware -------------------
SetPin ADCpin, AIN  ' initialize ADC
CPU 48              ' maximum speed for the MX170

'LCD
LCD init 4,5,6,7,2,26
LCD 1,1,"Samples =       "
LCD 2,1,"RMS =          V"


'--------------------------- Measuring ----------------------

Do
  'sample input signal
  For i%=1 To Total
    Sample(i%)=Pin(ADCpin)-Offset
  Next i%

  'find zero crossings
  i%=0:j%=Total-1
  'first zero crossing in array
  Do
    i%=i%+1
  Loop Until(Sample(i%)>0 And Sample(i%+1)<0)

  'last zero crossing in array
  Do
    j%=j%-1
  Loop Until (Sample(j%)>0 And Sample(j%+1)<0)

  'calculate SQUARES
  SumSQ!=0
  For a%=i% To j%
    SumSQ! = SumSQ! + (Sample!(a%)*Sample!(a%))
  Next a%

  'calculate MEAN
  SumSQ! = SumSQ!/(j%-i%)

  'calculate ROOT
  Value! = Sqr(SumSQ!)

  'display values on 16x2 LCD
  LCD 1,11,Str$(j%-i%)
  LCD 2,7,Left$(Str$(Value!*CalValue!),5)

Loop


This is a routine that does an RMS calculation on a 50Hz waveform. But in essence it shows how to print strings to the LCD. The LCD-init will have different pin numbers in your application, but this is explained in the MMBasic manual.
PicomiteVGA PETSCII ROBOTS
 
Turrican
Newbie

Joined: 24/06/2019
Location: Sweden
Posts: 10
Posted: 06:46pm 14 Mar 2021
Copy link to clipboard 
Print this post

That worked perfectly.
Many thanks!
/Tobias
There is NO need for more than 8-bits.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025