Problems with PIC18F4550 - using UESART are different?

General discussion on mikroC.
Post Reply
Author
Message
MasterBlaster
Posts: 165
Joined: 25 Oct 2007 22:22
Location: Wuppertal, Germany, Earth... :-)
Contact:

Problems with PIC18F4550 - using UESART are different?

#1 Post by MasterBlaster » 07 Sep 2008 19:22

Hi all,

i use the mikroC example for driving UART (receive only). With the
standard settings at 8Mhz it will be working perfectly with :shock: :

- 16F877A
- 18F452

but the same code won't be run with 18F4550 and 18F4685. :(

At the moment, i use the settings as like as here:

http://www.mikroe.com/forum/viewtopic.php?t=10646

and for 18F4685:

http://www.mikroe.com/forum/viewtopic.p ... ht=18f4685

It's seems like (I think) that are the MCU project settings are the
problem - anybody knows what are the right settings for the 18F
MCU's so that the UART will be run?

Here's my code:

Code: Select all

//
// Used:  EasyPic4 with 8 Mhz. Xtal
//
// 

#define USART

#define ID_BLOCKLEN    22
#define ID_BAUDRATE    9600

unsigned char ch, sBuffer[21], serBuffer[ID_BLOCKLEN+1];
unsigned long rcvdBytes;
unsigned int  counter, mycount;

unsigned char OutTxt[] = "Hello and welcome!";

void DTR_OFF( void)
{
  PORTC.F2 = 1;
}

void DTR_ON( void)
{
  PORTC.F2 = 0;
}

//**************************************************************************************************
// Main Routine
//**************************************************************************************************
void main( void)
{
  TRISA = 0;
  TRISB = 0;
  TRISC = 0;
  TRISD = 0;
  TRISE = 0;

  PORTA = 0;
  PORTB = 0;
  PORTC = 0;
  PORTD = 0;
  PORTE = 0;

  ADCON1 |= 0x0f;           // disable analog inputs
   CMCON |= 0x07;           // turn off comparators

  DTR_OFF();

  Lcd_Init( &PORTD);
  delay_ms( 250);
  Lcd_Cmd(Lcd_CLEAR);          // Clear display
  Lcd_Cmd(Lcd_CURSOR_OFF);     // Turn cursor off

  delay_ms( 250);
  Lcd_Out( 1, 1, "Bytes: ");    // Zeichenausgabe
  Lcd_Out( 2, 1, "Data: ");    // Zeichenausgabe

  USART_init( ID_BAUDRATE);  // initialize USART module

  mycount   = 1;
  rcvdBytes = 0;

  // Empfang starten
  DTR_ON();

  while(1)
  {
    // receive 22 chars (one infoline without CR/LF)
    // in the first byte, the number of the information will be stored
    // there are a max. of 10 datalines, after they repeat the informations
    // comming over serial port.
    counter   = 0;
    do
    {
      if( USART_Data_Ready())
      {
        ch = USART_Read();   // read the received data
        serBuffer[counter] = ch;
        counter++;
      };
    } while(counter < ID_BLOCKLEN);

    if( 1)  // some controls for the future - ignore it yet...
    {
      if( counter == ID_BLOCKLEN)
      {
        mycount++;
        rcvdBytes += ID_BLOCKLEN;

        sprintl( &sbuffer, "%u", (unsigned long )rcvdBytes);
        Lcd_Out( 1, 8, &sbuffer);

        // sprinti( &sbuffer, "%u", (unsigned int )counter);
        // Lcd_Out( 2, 14, &sbuffer);

        ch = serBuffer[0];
        sprinti( &sbuffer, "%u", (unsigned int )ch);
        Lcd_Out( 2, 8, "   ");    
        Lcd_Out( 2, 8, &sbuffer); 
      };
    };
  };
}
Thanks for help in advance...
so long,
MasterBlaster.

Using: EasyPIC4 HW. Rev. 1.03, LCD- & GLCD Display, NetWork and SD/MMC Adapter,
reg. MikroC Pro for PIC 2009, PIC 16F877A, 18F452 and 18F4685 with 8/20 MHz Xtal.

Post Reply

Return to “mikroC General”