PIC microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by rekha, May 21, 2008.

  1. rekha

    Thread Starter New Member

    May 21, 2008
    1
    0
    i need program and circuit IN pic microcontroller ie c language
    i am using 16f877 i am giving analog input according to that input output is varies in dual 7 segment display
    250mv=1degree
    500mv=2degree

    2.5v=10degree

    5 v=20 degree
    display in degree
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    I have a program more or less the same as the one you want. My program reads the value of an analogue input and lights a string of leds according to the value of the analogue signal. Check it below to get an idea

    #include <16f819.h>
    #device ADC=10

    #fuses NOWDT, INTRC_IO, NOPUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT

    #use fast_io(A)
    #use fast_io(B)

    #INT_TIMER0

    void isr()
    {
    int input=0;

    output_b(0b11111111);
    output_a(0b11111111);

    input=read_adc();

    if (input>115)
    {
    output_b(0b00000000);
    output_a(0b00111111);
    }
    else if (input>102)
    {
    output_b(0b00000001);
    output_a(0b00111111);
    }

    else if (input>90)
    {
    output_b(0b00000011);
    output_a(0b00111111);
    }

    else if (input>77)
    {
    output_b(0b00000111);
    output_a(0b00111111);
    }

    else if (input>64)
    {
    output_b(0b00001111);
    output_a(0b00111111);
    }

    else if (input>51)
    {
    output_b(0b00011111);
    output_a(0b00111111);
    }

    else if (input>38)
    {
    output_b(0b00111111);
    output_a(0b00111111);
    }

    else if (input>26)
    {
    output_b(0b01111111);
    output_a(0b00111111);
    }

    else if (input>13)
    {
    output_b(0b11111111);
    output_a(0b00111111);
    }

    else if (input>0)
    {
    output_b(0b11111111);
    output_a(0b01111111);
    }

    }

    void main()
    {
    setup_oscillator(OSC_8MHZ);

    set_TRIS_B(0b00000000);
    set_TRIS_A(0b00111111);

    SETUP_TIMER_0(RTCC_DIV_128);
    setup_timer_1(T1_DISABLED);
    setup_timer_2(T2_DISABLED,0,1);

    setup_ADC_ports(AN0);
    setup_ADC(ADC_CLOCK_DIV_16);
    set_ADC_channel(0);

    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);

    do
    {
    isr();
    } while (TRUE);
    }
     
Loading...