Thanks Brian your code idea works a treat. So how come yours does and mine doesn't????? I just don't understand why not. The only issue now i have is the servo keeps resetting itself(matter of speach) goes in the direction i want holds for a second then rotates all the way back then rotates back to where it should be. I require the servo to stay put how do i go about this as my code does not do this when in my head it should. what am i doing wrong
the code..
Code:
OSCCON = %01101000 'INTRC = 4 MHz
TRISA = %11111111
ANSEL = 0 'DISABLE ALL ADC
CMCON = 7 'DISABLE ALL ANALOG COMPARATOR
WHILE OSCCON.2=0:WEND 'STABILISE THE CLOCK
ADCON1 = 1
DEFINE OSC 4
PAUSE 1000
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4 '4,5,6,7
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
pause 1000
lcdout $fe, 1
'-------------------------------------------------------------------------------
ServoWidth var byte
ServoPin Var PORTB.0
ServoWidth = 1500
DQ VAR PORTA.1 ' One-wire data pin
b3 var byte
b3 = 1200
temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
TEMP VAR WORD
LoopCtr var byte
'-------------------------------------------------------------------------------
MainLoop:
LoopCtr = LoopCtr + 1
if LoopCtr > 50 then loopCtr = 0
if LoopCtr = 1 then TempConversion
IF TEMP > 24 THEN ServoWidth = ServoWidth - 1
IF TEMP < 22 THEN ServoWidth = ServoWidth + 1
if TEMP = 23 THEN ServoWidth = ServoWidth + 0
if LoopCtr = 0 then ReadTemperature
ServoCodeHere:
Low ServoPin
if ServoWidth = 1105 then high ServoPin ' servo stop
if ServoWidth = 1895 then high ServoPin ' servo stop
Pulsout ServoPin, ServoWidth
'Delay to give 20 mSec looptime
PAUSE 18
Goto MainLoop
TempConversion:
'Issue code to start the temperature conversion - don't wait for result
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
Goto MainLoop
ReadTemperature:
'Issue code to read most recent temperature conversion
DS18S20WAITLOOP: OWIn DQ, 4, [count_remain] ' Check for still busy converting
IF count_remain = 0 Then DS18S20WAITLOOP
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
TEMP = temperature / 100
LCDOut $fe, 1, DEC (temperature / 100)," C"
Goto MainLoop
Regards
Crazy Cooter
Bookmarks