Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Display value on LCD without new values rewriting first valu

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
joeyko10642

Bascom Member



Joined: 17 Oct 2016
Posts: 1

PostPosted: Mon Oct 17, 2016 8:40 am    Post subject: Display value on LCD without new values rewriting first valu Reply with quote

Hi guys, im fairly new to this forum so maybe this might not be the right place to post this? but i am having trouble on displaying a value from a variable on the lcd without it being rewritten by the next value. Is there a way to keep the same value displayed without needing to use a stop command for the program?

Im currently trying to display the first distance value from a rotating ultrasonic sensor, but as it moves new distances are detected and it rewrites the first value with the new distance values.

$crystal = 1000000
$regfile = "m16adef.dat"

Config Pina.1 = Input 'Config PinA.1 as input, ECHO of HC-SR04 ultrasonic sensor
Config Porta = Output 'Config rest of PORTA as output, including TRIGGER of HC-SR04 ultrasonic sensor
Set Portd.5 'Turn on backlight of LED
Dim Ontime As Word 'Delay time of BYJ48 stepper motor
Dim I As Word 'Variable for the amount of steps stepper motor BYJ48 will rotate
Dim Ii As Byte 'the number of phases of the stepper motor BYJ48
Dim S(4) As Byte
Dim Distance As Single 'Distance that the ultrasonic reads
Dim W As Dword 'Same as distance
Dim A As Word

Ontime = 800

Config Lcdbus = 4
Config Lcdpin = Pin Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.0 'LCD Configuration
Config Lcd = 20 * 4
Cursor Off

Do
Gosub Ultrasonic

loop
end

Ultrasonic:
Pulseout Porta , 2 , 20 'Min. 10us pulse 'send out ultrasonic waves
Pulsein W , Pina , 1 , 1 'read distance 'receive ultrasonic waves
Incr I 'increase steps after one reading
If Err = 0 Then 'when error is 0
W = W * 26 'calcul ate to 'calculations to convert wave signals to cm
W = W / 58.3090379009 ' centimeters
Distance = W
A = I * 35
A = A / 100
Print #1 , W ; " , " ; I ; " , " ; A 'print onto terminal emulator using rs232
'For Index = 1 To 10
'Spoint(index) = Distance
'Next
End If

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Oct 17, 2016 9:31 am    Post subject: No return Reply with quote

First of all you are doing a gosub to a subroutine but that subroutine is missing a return.

Second you can place the complete subroutine between the do and loop. Without the return.

Third I don't see any LCD commands after you init the LCD. Where would you like to display and have you seen the LCD commands in the help? Going to the second line of the display, the loxate command etc.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum