![]() |
Forum Index : Microcontroller and PC projects : writing a variable to a 1602a display in mmbasic
Author | Message | ||||
Turrican Newbie ![]() Joined: 24/06/2019 Location: SwedenPosts: 10 |
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: NetherlandsPosts: 5089 |
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: SwedenPosts: 10 |
That worked perfectly. Many thanks! /Tobias There is NO need for more than 8-bits. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |