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
You are here: Home / Topics / pic16f877a uart not working

pic16f877a uart not working

|

Microcontroller › PIC › pic16f877a uart not working

  • This topic has 2 replies, 3 voices, and was last updated 8 years, 4 months ago by erwin.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • March 23, 2014 at 8:45 pm #2975
    navin tiwari
    Participant

    hello there!
    I’m trying to communicate with PC using pic16f877a’s uart.. I’ve written a code in HITECH C.. but it doesn’t seem to work.. pls help.. I’m using 20 MHz crystal and 9600 bauds..
    the code is given below..

    <code>
    #include <htc.h>
    #define _XTAL_FREQ 20000000
    __CONFIG(FOSC_HS&LVP_OFF&CP_OFF&BOREN_OFF&PWRTE_OFF&WRT_OFF&WDTE_OFF);
    unsigned char x;
    void main()
    {
        TRISC6 = 1;
        TRISC7 = 1;
        BRGH = 1;
        SYNC = 0;

        SPEN = 1;
        SPBRG = 129; //9600 baud with 20MHz
        TXIE = 1;
        RCIE = 1;
        GIE = 1;
        PEIE = 1;
           CREN = 1;
        TXEN = 1;
        while(1);
        
    }

    void interrupt ISR(void)
    {
        if(RCIE && RCIF)
        {    
            x = RCREG;
            if(TXIF)
                TXREG = x;
                __delay_ms(100);
        }
    }
    </code>
     

    March 24, 2014 at 7:52 am #11366
    AJISH ALFRED
    Participant

    Hi Navin,

    I would suggest to simplify the code by avoid the interrupt. Place that piece of code which writes into the transmit buffer inside the infinite loop of the main code and try again.

    March 24, 2014 at 9:00 am #11367
    erwin
    Participant

    check your loop or try to use mikroC it is easier to understand..there is a library for uart…

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

RSS Recent Posts

  • Nokia 5110 HW in Oshonsoft August 17, 2022
  • Digital Display Information August 17, 2022
  • Seeking Help to compile code August 17, 2022
  • 2nd pcb design program? August 17, 2022
  • Door exit button August 17, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

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