1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Suart pic2550

Discussion in 'Microcontrollers' started by be80be, Sep 23, 2017.

  1. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Could some one have look at this I zipped the whole MPLAB-X project
    Im just getting a ?P output not the text I should be getting.
     

    Attached Files:

  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    The demo is set to 115200 baud!! Is your PC set to this?
     
  3. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Yes I got it set 115200 Changed it to 9600 and got the same thing "?P"
    The first one I use MMC and then changed chip setting to 18f2550
    I found this which I got it to work but there is a bug in it I can send data 0 to 255
    or text but not both
    uart.h
    Code (C):

    char UART_Init(const long int baudrate)
    {
        unsigned int x;
        x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
        if(x>255)
        {
            x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
            BRGH = 1;
        }
        if(x<256)
        {
         SPBRG = x;
         SYNC = 0;
         SPEN = 1;
              TRISB7 = 1;
              TRISB6 = 0;
              CREN = 1;
              TXEN = 1;
         return 1;
        }
        return 0;
    }

    char UART_TX_Empty()
    {
      return TRMT;
    }

    char UART_Data_Ready()
    {
       return RCIF;
    }
    char UART_Read()
    {

      while(!RCIF);
      return RCREG;
    }

    void UART_Read_Text(char *Output, unsigned int length)
    {
        unsigned int i;
        for(int i=0;i<length;i++)
            Output[i] = UART_Read();
    }

    void UART_Write(char data)
    {
      while(!TRMT);
      TXREG = data;
    }

    void UART_Write_Text(char *text)
    {
      int i;
      for(i=0;text[i]!='\0';i++)
         UART_Write(text[i]);
    }
     
    main.c
    Code (C):

     do
      {
        UART_Write(100);
        __delay_ms(500);
         UART_Write_Text("I'm alive");
        __delay_ms(500);
      }while(1);
    }
    [code]
     
    Last edited: Sep 24, 2017

Share This Page