'**************************************************************** '* Name : Syn-Ren1.BAS * '* Author : Gary R. Melander * '* Notice : Copyright (c) 2006 Binary Farm, 2005 * '* : All Rights Reserved * '* Date : 5/13/2006 * '* Version : 1.0 * '* Notes : Simple serial mode... reads a pot at AD0 * '* : and sends it to SyRen * '**************************************************************** 'The following example program has GPIO.0 as the ADC input and all other ports as outputs. ' GPIO.0 is Analog in 0 to +5 Vdc ' GPIO.1 is connected to the serial LCD ' GPIO.2 is connected to the Servo output 'a 5K pot between Vdd and Vss feeds GPIO.0 @ DEVICE HS_OSC ' System Clock Options @ DEVICE WDT_OFF ' Watchdog Timer @ DEVICE PWRT_OFF ' Power-On Timer @ DEVICE BOD_OFF ' Brown-Out Detect @ DEVICE CPD_OFF ' Data Memory Code Protect @ DEVICE PROTECT_OFF ' Program Code Protection @ DEVICE MCLR_OFF INCLUDE "modedefs.bas" ADCON0=131 ANSEL=1 'sets Fosc/2 and GPIO.0 as ADC input CMCON=7 'turns off comparator function TRISIO=%00000001 'sets GPIO.0 as in input and all others as outputs DEFINE OSC 20 DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 READING VAR WORD ' 10 bits needed for good resolution on ADC ADC0 VAR GPIO.0 ' variable voltage. Vdd to Vcc via a 5K potentiometer LCD VAR GPIO.1 'output for LCD MOTOR VAR GPIO.2 ' to SyRen S1 connection First: ADCIN 0, READING 'read ADC and save in READING range is 0 to 1023 Here: READING = (READING/4) ' SyRen only needs one byte in this mode so quarter the input value SEROUT MOTOR,T9600,[READING] SEROUT LCD,N9600,[$1E, #READING,13, 10] 'display reading on LCD which is inverted TTL ADCIN 0, READING 'read ADC and save in READING range is 0 to 1023 PAUSE 105 GOTO Here END