Help with adcin and serout, using a 16F688 Chip


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2017
    Posts
    5

    Question Help with adcin and serout, using a 16F688 Chip

    Need some help with using analog inputs and sending results out serial to a LCD. I am expecting to see Low_Val= 0 to 254 on a LCD screen, What I am see on the LCD is Low_Val= 1 or Low_Val= 0. It is the same on all serial out on the LCD.
    Using a 16F688 chip
    Programing using PBP V3

    Code I wrote so far is this:
    ************************************************** ************************************
    'PIC-16F688

    #CONFIG
    __config _FOSC_INTOSCIO & _WDT_OFF & _MCLRE_OFF & _CPD_OFF & _CP_OFF & _PWRTE_ON & _BOREN_OFF

    #ENDCONFIG

    'Initialize Regsters:
    CMCON0 = %00000111 'Comparators off CMCON0 = 7
    OSCCON = %01100110 'Oscillator Setup
    ANSEL = %01110000 'Analog Select) 0 = Digital, 1 = Analog
    ADCON0 = %10000010 'ADC in operation,Rightadjust and Vref = VDD
    ADCON1 = %00110000 'clock derived from a dedicated internal oscillator
    WPUA = %00000000 'WEAK PULL-UP PORTA 0 = Pull-up disabled, 1 = Pull-up enabled
    TRISA = %00110000 'Port A 0 = output, 1 = input
    TRISC = %00000111 'Port C 0 = output, 1 = input

    'Includes:

    INCLUDE "modedefs.bas"

    'Defines:

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

    'Constants:
    I Con 254 ' Control Byte
    Clr Con 1 ' Clear the display
    Line1 Con 128 ' Point to beginning of line 1
    Line2 Con 193 ' Point to beginning of line 2
    Line3 Con 148 ' Point to beginning of line 3
    Line4 Con 212 ' Point to beginning of line 4
    Cgram Con 64 ' Point to Cgram within LCD
    Shift_L Con 24 ' Shift display left
    Shift_R Con 28 ' Shift display right


    'Variables:

    Low_Val var word
    Mid_Val var word
    High_Val var word

    'Alias and Modifiers

    Alarm var PORTA.2 ' Digital output on pin 2
    Pump var PORTA.4 ' Digital output on pin 3
    Valve var PORTA.3 ' Digital output on pin 4
    Pump_LED var PORTC.4 ' Digital input on pin 6
    Pulse_Out var PORTC.3 ' PWM output on pin 7
    Low_Level var PORTC.0 ' Analog input on pin 8
    Mid_Level var PORTC.1 ' Analog input on pin 9
    High_Level var PORTC.2 ' Analog input on pin 10
    Serial_Out var PORTA.0 ' Digital output on pin 13

    '================================================= ================================================== ============
    'Program Code:
    '================================================= ================================================== ============

    Start:
    low pump ' Turn filter pump Off
    Low Pump_LED ' Turn filter pump LED Off
    pause 1000 ' Wait 1 Sec.
    High Pump_LED ' Turn filter pump LED On
    pause 1000 ' Wait 1 Sec.
    Low Pump_LED ' Turn filter pump LED Off
    low Valve ' Turn Water valve Off
    low Alarm ' Turn Alarm Off

    Main:

    pwm Pulse_Out, 127, 100 ' Output a Pulse width 50% duty cycle for a 100 cycles
    adcin Low_Level, Low_Val ' Read Voltage at Low_Level probe and store in Low_Val
    adcin Mid_Level, Mid_Val ' Read Voltage at Mid_Level probe and store in Mid_Val
    adcin High_Level,High_Val ' Read Voltage at High_Level probe and store in High_Val

    SEROUT Serial_Out,N2400, [I]
    SEROUT Serial_Out,N2400, [Clr] ' clear the screen
    SEROUT Serial_Out,N2400, [I]
    SEROUT Serial_Out,N2400, [Line1]
    serout Serial_Out,N2400, ["Low_Val=",#Low_Val] ' Send the ASCII value of Low_Val followed by line Feed
    pause 1000 ' Wait 1 Second
    SEROUT Serial_Out,N2400, [I]
    SEROUT Serial_Out,N2400, [Line2]
    serout Serial_Out, N2400, ["Mid_Val=",#Mid_Val] ' Send the ASCII value of Mid_Val
    pause 1000 ' Wait 2 Second
    SEROUT Serial_Out,N2400, [I]
    SEROUT Serial_Out,N2400, [Clr] ' clear the screen
    SEROUT Serial_Out,N2400, [I]
    SEROUT Serial_Out,N2400, [Line1]
    serout Serial_Out,N2400, ["High_Val=",#High_Val]' Send the ASCII value of High_Val
    pause 1000 ' Wait 1 Second
    goto Main
    end
    ************************************************** ************************************************** ***********

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: Help with adcin and serout, using a 16F688 Chip

    Low_Level var PORTC.0 ' Analog input on pin 8
    adcin Low_Level, Low_Val ' Read Voltage at Low_Level probe and store in Low_Val
    you need to read the chapter on adcin, the input channel is not a pin number or pin alias its the analogue channel desired
    Warning I'm not a teacher

  3. #3
    Join Date
    Jun 2017
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Help with adcin and serout, using a 16F688 Chip

    Richard Thank You I am feeling really stupid right now. Again Thank you for you reply.

    [QUOTE][Make yourself look really stupid so you don't feel bad doing something a little stupid." (Mark Hoppus)]"

Similar Threads

  1. 16f688 Adc
    By PICante in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd August 2008, 11:34
  2. LCDOUT on the 16F688
    By PICante in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th August 2008, 18:42
  3. newbie: 16F688 with COUNT & SEROUT
    By ShortBus in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th June 2007, 14:29
  4. Help with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st October 2006, 00:12
  5. A/D problem ON 16F688
    By Christopher4187 in forum General
    Replies: 2
    Last Post: - 19th October 2005, 23:13

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts