dear all
m designing a project using pic18f4550 with usart . m not able to get proper data on hyperterminal. m using 4 mhz crystal.bellow is the code .please help me find mistake.
#include <p18f4550.h>
#include <stdio.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
/*
* Step #1 – The data is allocated into its own section.
*/
#pragma idata bigdata
char data[11][BUF_SIZE+1] = {
{ "String #0\n\r" },
{ "String #1\n\r" },
{ "String #2\n\r" },
{ "String #3\n\r" },
{ "String #4\n\r" },
{ "String #5\n\r" },
{ "String #6\n\r" },
{ "String #7\n\r" },
{ "String #8\n\r" },
{ "String #9\n\r" },
{ "Invalid key (0-9 only)\n\r" }
};
#pragma idata
#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;
/*
* Step #2 – This example did not need an additional
* pointer to access the large memory because of the
* multi-dimension array.
*
* Display the string located at the array offset
* of the character received
*/
putsUSART (data[c]);
}
else
{
/*
* Step #2 – This example did not need an additional
* pointer to access the large memory because of the
* multi-dimension array.
*
* Invalid character received from USART.
* Display error string.
*/
putsUSART (data[10]);
/* Display value received on LEDs */
PORTB = c;
}
/* Clear the interrupt flag */
PIR1bits.RCIF = 0;
}
void main (void)
{
TRISB = 0;
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 103);/* 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
m designing a project using pic18f4550 with usart . m not able to get proper data on hyperterminal. m using 4 mhz crystal.bellow is the code .please help me find mistake.
#include <p18f4550.h>
#include <stdio.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
/*
* Step #1 – The data is allocated into its own section.
*/
#pragma idata bigdata
char data[11][BUF_SIZE+1] = {
{ "String #0\n\r" },
{ "String #1\n\r" },
{ "String #2\n\r" },
{ "String #3\n\r" },
{ "String #4\n\r" },
{ "String #5\n\r" },
{ "String #6\n\r" },
{ "String #7\n\r" },
{ "String #8\n\r" },
{ "String #9\n\r" },
{ "Invalid key (0-9 only)\n\r" }
};
#pragma idata
#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;
/*
* Step #2 – This example did not need an additional
* pointer to access the large memory because of the
* multi-dimension array.
*
* Display the string located at the array offset
* of the character received
*/
putsUSART (data[c]);
}
else
{
/*
* Step #2 – This example did not need an additional
* pointer to access the large memory because of the
* multi-dimension array.
*
* Invalid character received from USART.
* Display error string.
*/
putsUSART (data[10]);
/* Display value received on LEDs */
PORTB = c;
}
/* Clear the interrupt flag */
PIR1bits.RCIF = 0;
}
void main (void)
{
TRISB = 0;
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 103);/* 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