Coding For PIC 18f4520

Status
Not open for further replies.

sudhag

Newbie level 6
Joined
Nov 30, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,353
i want to display different values from sensor through PIC18f4520 in lcd. im using embedded c language.plzz help me by sending the code
 

Try this Code,,,,
Code:
void main()
{
    TRISA=0x01;        // Configure RA0 as input pin
    LATA=0;
    TRISB=0;        // Configure Port B as output port
    LATB=0;
    TRISD=0;
    LATD=0;
    lcd_ini();        // LCD initialization
    while(data[i]!='\0')
    {
        lcddata(data[i]);      // Call lcddata function to send character one by from 'data' array
        i++;
    }

    adc_init();        //ADC Initialization

    while(1)
    {
        temp=0;
        for(i=0;i<10;i++)
        {
            ADCON0|=(1<<GO);                              // Start A/D conversion
            while(!(ADCON0 & (1<<GO)));                   // Wait until conversion gets over
            digital_out[i]=((ADRESL)|(ADRESH<<8));        // Store 10-bit output into a 16-bit variable
            Delay_ms(20);
            temp=temp+digital_out[i];
        }
        avg_output=temp/10;                           // Take average of ten digital values for stablity
        adc_con(avg_output);                          // Function to convert the decimal vaule to its corresponding ASCII

    }
}


void adc_init()
{
    ADCON1=0x0E;                            // Make RA0/AN0 pin as analog pin (Other pins remain to be digital I/O)
    ADCON0=0x00;                            // Select Channel0 & ADC off
    ADCON2=0x8A;                            // Left justified, 2TAD acquiciation time, Fosc/32 clock option
    ADCON0.ADON=1;                          // Enable ADC
}


void lcd_ini()
{
    lcdcmd(0x38);        // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    lcdcmd(0x0C);        // Display On and Cursor Off
    lcdcmd(0x01);        // Clear display screen
    lcdcmd(0x06);        // Increment cursor
    lcdcmd(0x80);        // Set cursor position to 1st line, 1st column
}


void adc_con(unsigned int adc_out)
{
    unsigned int adc_out1;
    int i=0;
    char position=0xC3;

    for(i=0;i<=3;i++)
    {
        adc_out1=adc_out%10;                     // To exract the unit position digit
        adc_out=adc_out/10;
        lcdcmd(position);
        lcddata(48+adc_out1);                    // Convert into its corresponding ASCII
        position--;

    }
}


void lcdcmd(unsigned char cmdout)
{
    lcdport=cmdout;        //Send command to lcdport=PORTB
    rs=0;                        
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
}


void lcddata(unsigned char dataout)
{
    lcdport=dataout;    //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    Delay_ms(10);
    en=0;
}
 

what sensor u using ? TC74 ?

- - - Updated - - -

http://ww1.microchip.com/downloads/en/devicedoc/mplab_c18_libraries_51297f.pdf
use this link to learn I2C
 

what sensor u using ? TC74 ?

- - - Updated - - -

https://ww1.microchip.com/downloads/en/devicedoc/mplab_c18_libraries_51297f.pdf
use this link to learn I2C



I'm using pulse oximeter sensor sp1006.Its a ear lobe sensor with rs232 cable. In ear lobe photo detector and led.It measures the oxygen saturation level. now getting my sensor as voltage the maximum voltage is 25mV and minimum will be 1mV. if maximum voltage it should display as 99% according to all inputs from sensor it should display in percentage values. plz help me in coding...
 

do you have a schematic ? if have upload to the forum

PIN 1 RESISTANCE(7.5kΩ)
PIN 2 LED(negative)
PIN 3 LED(positive)
PIN 4 TRANSISTOR(positive)
PIN 5 SENSOR(positive)
PIN 6 INNER SHIELD RESISTANCE(7.5kΩ)
PIN 7 OUTER SHIELD
PIN 8 TRANSISTOR(negative)
PIN 9 SENSOR(negative)
 

its very hard for the others users to see this kind.
what u give was a pin assignment diagram..
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…