Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me figure out this rs232 and c18 example (Proteus).

Status
Not open for further replies.

asic1984

Full Member level 5
Joined
Nov 15, 2003
Messages
257
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,298
Activity points
2,340
hi

i tried this example in proteus but it didnot work ,where is the problem
Code:
#include <p18f452.h>
#include <usart.h>

/* Set configuration bits for use with ICD2 / PICDEM2 PLUS Demo Board:
 *  - set HS oscillator
 *  - disable watchdog timer
 *  - disable low voltage programming
 *  - enable background debugging
 */
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = ON

void rx_handler (void);

#define BUF_SIZE 25




#pragma code rx_interrupt = 0x8
void rx_int (void)
{
  _asm goto rx_handler _endasm
}
#pragma code

#pragma interrupt rx_handler
void rx_handler (void)
{
  unsigned char c;

  /* Get the character received from the USART */
  c = ReadUSART();
  if (c >= '0' && c <= '9')
    {
     // c -= '0';
      /* Display value received on LEDs */
      PORTB = c;

      /*
       * Display the string located at the array offset
       * of the character received
       */
      putsUSART (c);
      PORTB = c;
    }
    else
    {
      /*
       * Invalid character received from USART.
       * Display error string.
       */
      putsUSART (c);

      /* Display value received on LEDs */
      PORTB = c;
    }

    /* Clear the interrupt flag */
    PIR1bits.RCIF = 0;
}

void main (void)
{
  /* Configure all PORTB pins for output */
  TRISB = 0;

  /* Open the USART configured as 8N1, 2400 baud, in polled mode */
  OpenUSART (USART_TX_INT_OFF &
             USART_RX_INT_ON &
             USART_ASYNCH_MODE &
             USART_EIGHT_BIT &
             USART_CONT_RX &
             USART_BRGH_LOW, 31);

  /* Display a prompt to the USART */
  putrsUSART ((const far rom char *)"\n\rEnter a digit 0-9!\n\r");

  /* Enable interrupt priority */
  RCONbits.IPEN = 1;

  /* Make receive interrupt high priority */
  IPR1bits.RCIP = 1;

  /* Enable all high priority interrupts */
  INTCONbits.GIEH = 1;

  /* Loop forever */
  while (1)
    ;
}

thanks for help
 

usart c18

I think the problem is crystal freq. you should set it to 5Mhz (it's because the code is written for picdem2 plus demo board i think)

13bf.jpg


As you see its working and showing '6' at the terminals rb0-rb3 (0110)

Don't forget to set virtual terminal's baud rate to 2400

Ps:i agree with your avatars message :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top