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 / How to get addc value through uart

How to get addc value through uart

|

Microcontroller › PIC › How to get addc value through uart

  • This topic has 1 reply, 2 voices, and was last updated 9 years, 9 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • July 8, 2016 at 5:42 am #4509
    NANDHAkumar
    Participant

    I got adc value on LCD but i cannot get values through UART

    Hitech c compiler

    MPLAB IDE

     

     
    #include "Includes.h"
     
    // Configuration word for PIC16F877
    __CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON 
    & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);
     
    #define AN7  7
     
    #define BAUDRATE 9600  //bps
     
    //unsigned char ch="ADC DATA ACQUISTION";
     
    unsigned int result [11];
    void InitADC(void)
    {
    ADCON1  = 0x80;     // Make PORTA and PORTE analog pins
    // Also, Vref+ = 5v and Vref- = GND
    TRISA   = 0x2f;      // Make RA5, RA3, RA2, RA1, RA0 input
    TRISE   = 0x07; // Make RE0, RE1 and RE2 input
    ADCON0  = 0x81; // Turn on the A/D Converter
    }
     
     
     
    void InitUART(void)
    {
    TRISC6 = 1;   // TX Pin
    TRISC7 = 1;   // RX Pin
     
    SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) – 1;
    BRGH  = 1;                   // Fast baudrate
    SYNC  = 0; // Asynchronous
    SPEN  = 1; // Enable serial port pins
    CREN  = 1; // Enable reception
    SREN  = 0; // No effect
    TXIE  = 0; // Disable tx interrupts
    RCIE  = 1; // Enable rx interrupts
    TX9   = 0; // 8-bit transmission
    RX9   = 0; // 8-bit reception
    TXEN  = 0; // Reset transmitter      
    TXEN  = 1; // Enable the transmitter
    }
     
     
    unsigned int GetADCValue(unsigned char Channel)
    {
       ADCON0 &= 0xc7;         // Clear Channel selection bits
     
    unsigned char temp = 0; 
    //unsigned int num = 0; 
     
    unsigned int num = 0; 
    ADON=1;
    ADCON0|=0b01000000;
    while(ADCON0==0x11) // wait for the A/D conversion to finish 
    result [10]= ADRESL & 0xff; // store the lower eight bits in their respective place in the results array 
    temp = ADRESH & 0x03; // get the uppermost two bits 
     
     
    }
     
     
    void SendByteSerially(unsigned char byte)  // Writes a character to the serial port
    {
    while(!TXIF);  // wait for previous transmission to finish
    TXREG = result [10];
    while(!TXIF);
    }
     
    // Main Function
    void main(void)
    {
    unsigned int ADC_value = 0;
    unsigned int digit1, digit2, digit3, digit4;
     
    InitADC(); // Initialize ADC
    InitLCD(); // Initialize LCD
        InitUART();
    //void SendByteSerially(unsigned char);
    while(1)
    {
    ClearLCDScreen(); // Clear LCD screen
         GetADCValue(AN7); // Read ADC value from RE2(AN7) pin
     
            __delay_ms(1000);
            void SendByteSerially(unsigned char byte);
    // ADC_value can have a value from 0 (0v) to 1023(5v) only.
    // SO display 4 digits of ADC_value
    digit1 = (unsigned int)(ADC_value/1000); // Calculate digit1 of ADC_value
    digit2 = (unsigned int)((ADC_value – digit1*1000)/100); // Calculate digit2 of ADC_value
    digit3 = (unsigned int)((ADC_value – (digit1*1000+digit2*100))/10); // Calculate digit3 of ADC_value
    digit4 = (unsigned int)(ADC_value – (digit1*1000+digit2*100+digit3*10)); // Calculate digit4 of ADC_value
     
    WriteDataToLCD(digit1+0x30); // Display digit1 of ADC_value on LCD
    WriteDataToLCD(digit2+0x30); // Display digit2 of ADC_value on LCD
    WriteDataToLCD(digit3+0x30); // Display digit3 of ADC_value on LCD
    WriteDataToLCD(digit4+0x30); // Display digit4 of ADC_value on LCD
     
    __delay_ms(1000); // Half second delay before next reading
    }
    }
     
     
     
     
     
     
     

     

    July 9, 2016 at 7:59 pm #14054
    Ashutosh Bhatt
    Participant

    may be the problem in baud rate. just check crystal frequency and com port setting

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

RSS Recent Posts

  • EasyEda program has a major bug April 13, 2026
  • understanding transmission line properties from TDR plot April 13, 2026
  • Search term needed for remote control hobby. April 13, 2026
  • Decoupling Cap placement. April 12, 2026
  • isolating S-params in of PCB board without connectors April 12, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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