Multiple inputs with PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by auststud, Apr 26, 2009.

  1. auststud

    Thread Starter New Member

    Mar 25, 2009
    In my project, I am using sensors connected to PIC16F877. I have to get the readings from the sensors and display the value on the Computer (through parallel port). For example, I am using LM35 to display the temperature value on the PC (using Visual Basic). When I want to display, more than 1 sensor reading, it doesnot work. I want to use three ports for A/D conversion to display three different readings.

    For synchronization between PC and PIC16F877, I am using control pins of parallel port. The temperature reading is displayed correctly on PC from the 3 ports. Since, sensors are not available now, I am using voltage less than 1.2V from the bread board to check, if synchronization is achieved or not. Along with the voltage from LM35, when I add any other voltage, I get the same reading of the temperature, i.e., the two ports are reading the same value, how is that possible, although I am putting 2 different voltage on AN0 and AN1???

    I am programming using picbasic pro and the code is shown below.


    define ADC_BITS 10
    define ADC_CLOCK 3
    define ADC_SAMPLEUS 50

    x var word 'ADC is made 10 bits for proper resolution of LM35
    y var byte
    a var word
    b var byte
    c var word
    d var byte

    TRISD = 255
    pause 500
    if (portd.0 = 1) AND (portd.1 = 0) Then

    ADCIN 0,x
    y = x 'the last two bits will be discarded, but the reading for temperature is correct.
    PortB = y
    output PortB
    pause 500

    if (portd.0 = 0) AND (portd.1 = 1) Then

    ADCIN 1,a
    b = a
    PortB = b
    output PortB
    pause 500

    if (portd.0 = 1) AND (portd.1 = 1) Then

    ADCIN 2,c
    d = c
    PortB = d
    output PortB
    pause 500
    goto loop


    By proper programming in Visual basic, the control pins are changing, i.e., portd.0 and portd.1 is changing as 10, 01, 11. But, why is that the microcontroller is not reading multiple inputs separately??

    Plz help...