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 / Problem with EUSART module pf PIC16F1933

Problem with EUSART module pf PIC16F1933

|

Microcontroller › PIC › Problem with EUSART module pf PIC16F1933

  • This topic has 0 replies, 1 voice, and was last updated 11 years, 2 months ago by Debou Alexander.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 22, 2015 at 4:11 pm #3634
    Debou Alexander
    Participant

    Hey everyone!

    I have a problem with the EUSART receiver module of my PIC 16F1933. I use this module to receive data trought bluetooth. First I tried to use the MikroC library for UART but it also didn't work. Then I tried to initialise the module by myself like the code below. Can anyone find the problem? The bluettoh module receives the data correctly, so this is not the problem. The Baudrate is 9600

    With regards

    Alexander

    unsigned char data_Rx
    char i,j=0;

    /*==============================================================================
    *
    ==============================================================================*/

    /******************************************************************************
    *EUSART_Init_9600

    *8bit data

    *Instellen BAUDRATE

    *TXSTA.SYNC = 0            |   *BR = 9600
    *TXSTA.BRGH = 1            |   *Value SPBRGL = 25
    *BAUDCON.BRG16 = 0    |   *Fault = 16%
    *SPBRGL = 25                 |   *FOSC = 4MHz
    *BAUDCON.SCKP = 0
    *BAUDCON.WUE = 0
    *BAUDCON.ABDEN = 0

    *Instellen EUSART

    *TRISC.B7 = 1
    *RCSTA.SPEN = 1
    *RCSTA.RX9 = 0
    *RCSTA.ADDEN = 0
    *RCSTA.CREN = 1
    RCSTA.SREN = 0

    *TXSTA.SYNC=0
    *TXSTA.BRGH=1
    *BAUDCON=0b00000000=0x00
    *SPBRGL = 25
    *SPBRGH = 0
    *RCSTA = 0b10010000
     ******************************************************************************/
    void EUSART_Init_9600()
    {
        TXSTA.SYNC=0;
        TXSTA.BRGH=1;
        BAUDCON=0x00;
        SPBRGL = 25;
        SPBRGH = 0;
        RCSTA = 0b10010000;
    }

    /******************************************************************************
    *EUSART_read()

    *returns RCREG (char)
     ******************************************************************************/
    char EUSART_Read()
    {
      return RCREG;
    }

    /******************************************************************************
    *EUSART_read_Text(char *Output, unsigned int length)

    *returns RCREG (char)
     ******************************************************************************/
    void EUSART_Read_Text(char *Output, unsigned int length)
    {
            int i;
            for( i=0;i<length;i++) Output = RCREG;
    }

    /******************************************************************************
    *Interrupt routine
     ******************************************************************************/
     void interrupt()
     {
         INTCON.GIE=0;
         if(PEIE.RCIF)
         {
           EUSART_Read_Text(data_Rx,5);
             i++;
             if(i==5)
             {
                i=0;
             }

         data_Rx = EUSART_Read();

         }
         INTCON.GIE=1;
     }

    /******************************************************************************
    *Hoofdprogramma
     ******************************************************************************/
     void main()
     {

        
        ANSELA=0;
        ANSELB=0;
        
        TRISC.B7=1;    // Rx pin as input

        TRISB.B0=0;
        TRISB.B5=0;

       EUSART_Init_9600();

        Delay_ms(100);

        PIE1.RCIE = 1;
        INTCON.PEIE=1;
        INTCON.GIE=1;
        
        while(1)
        {
            data_Rx=UART1_Read();
            if (data_Rx ==0xAA)
            {
                PORTB.B0 = 1;
                Delay_ms(2000);
                PORTB.B5 = 1;
                Delay_ms(2000);
                PORTB.B0 = 0;
                Delay_ms(2000);
                PORTB.B5 = 0;
            }
        }
     }
     
    /*============================================================================
    *Einde Programma
      ============================================================================*/

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

RSS Recent Posts

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