PDA

View Full Version : POT command



Joval
- 21st March 2006, 06:10
Hi, all
I am new to the forum and terrible at coding.

I am doing a project that reguires 4 sensors.
I have named them sens1 thru sens4.
I read the sensors and send the serial data to an lcd.

Include "modedefs.bas"

trisa = %00000010
trisb = %00001111

lcd var PORTA.0 ' Lcd connected porta.0
sens1 var PORTB.0 ' Light sensor 1 connected to portb.0
sens2 var PORTB.1 ' Light sensor 2 connected to portb.1
sens3 var PORTB.2 ' Light sensor 3 connected to portb.2
sens4 var PORTB.3 ' Light sensor 4 connected to portb.3
cw_az var PORTB.4 ' To turn azimuth motor clockwise
ccw_az var PORTB.5 ' To turn azimuth motor counterclockwise
cw_el var PORTB.6 ' To turn elevation motor clockwise
ccw_el var PORTB.7 ' To turn elevation motor counterclockwise
b0 var byte ' Place to hold variable value
b1 var byte ' Place to hold variable value
b2 var byte ' Place to hold variable value

'Routine to display values. THESE IS WHAT I AM TRYING TO IMPROVE

sens_chk: 'Check light sensors
pot sens1,255,B0 'Check sensor 1. Put value in B0
serout lcd,N2400, [254,1] 'Clear lcd
serout lcd,N2400, ["sensor1",#B0] 'Send sensor 1 value to lcd
pause 1000 'Delay 1 second

pot sens2,255,B0 'Check sensor 2. Put value in B0
serout lcd,N2400, [254,1] 'Clear lcd
serout lcd,N2400, ["sensor2",#B0] 'Send sensor 2 value to lcd
pause 1000 'Delay 1 second

pot sens3,255,B0 'Check sensor 3. Put value in B0
serout lcd,N2400, [254,1] 'Clear lcd
serout lcd,N2400, ["sensor3",#B0] 'Send sensor 3 value to lcd
pause 1000 'Delay 1 second

pot sens4,255,B0 'Check sensor 4. Put value in B0
serout lcd,N2400, [254,1] 'Clear lcd
serout lcd,N2400, ["sensor4",#B0] 'Send sensor 4 value to lcd
pause 1000 'Delay 1 second
goto start

end

Is there a way to eliminate repeating the serial out commands?
Can it be done with a FOR..NEXT loop?

I will greatly appreciate any help.

Joe

paul borgmeier
- 21st March 2006, 07:24
Joe,

This addition/substitution compiles okay but I have not tried on an actual chip. Let us know.

X var byte

For X = 0 to 3
pot portb.0[X],255,B0
serout lcd,N2400, [254,1]
serout lcd,N2400, ["sensor",#X,#B0]
pause 1000
Next X

(You also do not have Start: defined for the goto Start line of your program)

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA