Hi Gurus of Picland,
Iīm building a Lambdatester that flattens somewhat out the hard jump in output voltage between lean and rich.
wrote a code that works. Fine, and fast enough because theres hardly need for speed.
Way of simple code for Picdummies like me .
But if an oldschool mechanic like me looks at it even he knows that theres plenty room for codesaving.
You Gurus fall down your chairs laughing and crying at the same time, I know.
'************************************************* ****************
'* Name : Analogbargraph1(16F628A).BAS *
'* Author : M.David *
'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 28.02.2008 *
'* Version : 1.0 *
'* Notes : needs 12F675 for Lambdatesting device and LCD 1X16 *
'* : input 0.1 - 1.1 Volts in GPIO.0 *
'* : needs ADCserout(12F675).bas *
'************************************************* ****************
'
' DEFINITIONS
@__config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 4
Uin var word
B0 VAR word ' Cnt is a word variable
inputData var word ' variable to receive data into
' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = 1 ' RB0 is Input others output
main:
Serin PORTB.0,N2400,B0
B0 = 100 * B0
Uin = B0 / 207
gosub bargraph
Pause 5
goto main
bargraph:
if Uin < 10 then LCDOUT $FE,1,"TOO LOW"
if (Uin > 10) and (Uin <= 15 ) then
LCDOUT $FE,1,255
endif
if (Uin > 15) and (Uin <= 19 ) then
LCDOUT $FE,1,255,255
endif
if (Uin > 19) and (Uin <= 24 ) then
LCDOUT $FE,1,255,255,255
endif
if (Uin > 24) and (Uin <= 29 ) then
LCDOUT $FE,1,255,255,255,255
endif
if (Uin > 29) and (Uin <= 34 ) then
LCDOUT $FE,1,255,255,255,255,255
endif
if (Uin > 34) and (Uin <= 43 ) then
LCDOUT $FE,1,255,255,255,255,255,255
endif
if (Uin > 43) and (Uin <= 53 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255
endif
if (Uin > 53) and (Uin <= 62 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255
endif
if (Uin > 62) and (Uin <= 72 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255
endif
if (Uin > 72) and (Uin <= 81 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255
endif
if (Uin > 81) and (Uin <= 86 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255
endif
if (Uin > 86) and (Uin <= 91 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255,255
endif
if (Uin > 91) and (Uin <= 96 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255,255,255
endif
if (Uin > 96) and (Uin <= 100 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255,255,255,255
endif
if (Uin > 100) and(Uin <= 105 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255,255,255,255,255
endif
if (Uin > 105) and(Uin <= 110 ) then
LCDOUT $FE,1,255,255,255,255,255,255,255,255,$FE,$C0,255, 255,255,255,255,255,255,255
endif
if Uin > 110 then
LCDOUT $FE,$C0,"TOO RICH"
endif
return
END ' End of program
on the other hand it works and shows how good and fast the combination of pics and PBP works.
Any Ideas? maybe case select or lookdown or whatever?
sincerely
Mugel
Bookmarks