EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / pic18f452 to read voltage and display on lcd

pic18f452 to read voltage and display on lcd

|

Microcontroller › PIC › pic18f452 to read voltage and display on lcd

  • This topic has 0 replies, 1 voice, and was last updated 11 years, 2 months ago by ANAMIKA VYAS.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 12, 2014 at 1:05 pm #3036
    ANAMIKA VYAS
    Participant

    i have to design a pic to read voltage, analog signal is set to an0 and display the result on lcd.but imam getting error.it says undefined identifier for”ANSEL=0x04″. i am attaching the code also. i am using mickroc.

    // LCD module connections

    sbit LCD_RS at RB4_bit;

    sbit LCD_EN at RB5_bit;

    sbit LCD_D4 at RB0_bit;

    sbit LCD_D5 at RB1_bit;

    sbit LCD_D6 at RB2_bit;

    sbit LCD_D7 at RB3_bit;

    sbit LCD_RS_Direction at TRISB4_bit;

    sbit LCD_EN_Direction at TRISB5_bit;

    sbit LCD_D4_Direction at TRISB0_bit;

    sbit LCD_D5_Direction at TRISB1_bit;

    sbit LCD_D6_Direction at TRISB2_bit;

    sbit LCD_D7_Direction at TRISB3_bit;

    // End LCD module connections

     

    unsigned char ch;                    //

    unsigned int adc_rd;                 // Declare variables

    char *text;                          //

    long tlong;                          //

     

    void main() {

        INTCON = 0;                      // All interrupts disabled

        ANSEL = 0x04;                    // Pin RA2 is configured as an analog input

        TRISA = 0x04;

        ADCON1 = 0;                      // Rest of pins are configured as digital

       

        Lcd_Init();                      // LCD display initialization

        Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)

        Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)

       

        text = “mikroElektronika”;       // Define the first message

        Lcd_Out(1,1,text);               // Write the first message in the first line

        text = “LCD example”;            // Define the second message

        Lcd_Out(2,1,text);               // Define the first message

       

        ADCON1 = 0x82;                   // A/D voltage reference is VCC

        TRISA = 0xFF;                    // All port A pins are configured as inputs

        Delay_ms(2000);

       

        text = “voltage:”;               // Define the third message

       

        while (1) {

            adc_rd = ADC_Read(2);        // A/D conversion. Pin RA2 is an input.

            Lcd_Out(2,1,text);           // Write result in the second line

            tlong = (long)adc_rd * 5000; // Convert the result in millivolts

            tlong = tlong / 1023;        // 0..1023 -> 0-5000mV

            ch = tlong / 1000;           // Extract volts (thousands of millivolts)

                                         // from result

            Lcd_Chr(2,9,48+ch);          // Write result in ASCII format

            Lcd_Chr_CP(‘.’);

            ch = (tlong / 100) % 10;     // Extract hundreds of millivolts

            Lcd_Chr_CP(48+ch);           // Write result in ASCII format

            ch = (tlong / 10) % 10;      // Extract tens of millivolts

            Lcd_Chr_CP(48+ch);           // Write result in ASCII format

            ch = tlong % 10;             // Extract digits for millivolts

            Lcd_Chr_CP(48+ch);           // Write result in ASCII format

            Lcd_Chr_CP(‘V’);

            Delay_ms(1);

        }

    }

     

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Fun with AI and swordfish basic June 23, 2025
  • Simple LED Analog Clock Idea June 23, 2025
  • Microinverters and storeage batteries? June 23, 2025
  • PIC KIT 3 not able to program dsPIC June 23, 2025
  • Is AI making embedded software developers more productive? June 23, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise