'****************************************************************
'* Name : Transmit.BAS *
'* Author : Jan Kordylewski*
'* Notice : Copyright (c) 2004 freely distributable *
'* : All Rights Reserved *
'* Date : 12/12/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

ADCvar VAR WORD ' Create variable to store result
hit var word

output portb.7
OUTPUT portd.2
output portb.6

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
portd.2 = 1
hit = 0
Pause 500 ' Wait .5 second

main:
ADCIN 0, ADCvar ' Read channel 0 to adval
serout2 portc.6, 16468, ["myvar = ", DEC ADCvar, 10, 13]
'serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10] ' print it to serial out,
' with linefeed and carriage return (10, 13)


  If ADCvar>50 and ADCvar<=200Then
'portd.2 = 0
if hit = 0 then
hit = 1
endif
portb.7 = 1
'pause 2000
'portd.2 = 1
endif

if ADCvar>200 Then
'portd.2 = 1
portb.7 = 1
portb.6 = 1
ELSE
'portd.2 = 1
portb.7 = 0
portb.6 = 0
endIF

if hit > 0 then
portd.2 = 0
hit = hit +1
if hit > 1000 then
hit = 0
portd.2 = 1
endif
endif

'portd.2 = 1
'portb.7 = 0
'endIf



GoTo main ' Do it forever