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.

The function: Open1USART() not worked on MCC18 !!

Status
Not open for further replies.

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
Hi all!

I have a problem with PIC18F97J60, writting code on MCC18 & MPLAB IDE v8.76. I can not communicated with COM port 1.
This is my c code:

#include "p18f97j60.h"
#include "global.h"
#include "usart.h"

void main(void)
{

//Delay10KTCYx(125); // = 10000*Value*Tcy = 10000*x*0.16 = 200ms
Init();


//debug on COM port 1
#ifdef _UART1_USE_
putc1USART('\n');putc1USART('\r');
putc1USART('O');

#endif






while(1)
{







}//end while
}//end main


void Init(void)
{

TRISA = INIT_TRISA;
TRISB = INIT_TRISB;
TRISC = INIT_TRISC;
TRISD = INIT_TRISD;
TRISE = INIT_TRISE;
TRISF = INIT_TRISF;
TRISG = INIT_TRISG;
TRISH = INIT_TRISH;
TRISJ = INIT_TRISJ;

PSPCONbits.PSPMODE = 0; //Disables the PSP port on the chip.

//INTCON2bits.RBPU = 0; //Internal PORTB pull-up resistor feature (1:On , 0:Off).
PORTAbits.RJPU = 1; //Internal PORTJ pull-up resistor feature (1:On , 0:Off).
LATAbits.RDPU = 1; //Internal PORTD pull-up resistor feature (1:On , 0:Off).
//LATAbits.REPU = 1; //Internal PORTE pull-up resistor feature (1:On , 0:Off).

configureUSART(9600);

}




void configureUSART(unsigned int baudrate)
{
unsigned int spbrg;

TRISCbits.TRISC6 = 0; // set TX (RC6) as output
TRISCbits.TRISC7 = 1; // and RX (RC7) as input
TXSTA1 = 0; // Reset USART registers to POR state
RCSTA1 = 0;
TXSTA1bits.TXEN = 1; // Enable transmitter
RCSTA1bits.SPEN = 1; // Enable receiver
//spbrg = (CPU_CLOCK/16)/baud - 1 , (High Speed)
//spbrg = (CPU_CLOCK/64)/baud - 1 , (Low Speed)

switch(baudrate)
{
case 2400: spbrg = 650;
break;
case 4800: spbrg = 324;
break;
case 19200: spbrg = 80;
break;
case 38400: spbrg = 39;
break;
case 57600: spbrg = 26;
break;
case 115200: spbrg = 12;
break;
case 500000: spbrg = 2;
break;
case 1000000: spbrg = 0;
break;
default: // 9600 baud
spbrg = 161;//40;
break;
}

//Asynchronous mode, high speed(BRGH=1): (FOSC/(16 x Baud rate)) - 1
//Asynchronous mode, low speed(BRGH=0): (FOSC/(64 x Baud rate)) - 1
//Synchronous mode: FOSC / (4 * (spbrg + 1))

baud1USART(BAUD_8_BIT_RATE & BAUD_AUTO_OFF);

// Open1USART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, spbrg );
Open1USART(
USART_TX_INT_OFF &
USART_RX_INT_ON & //recieve interrupt on
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
//USART_CONT_RX &
USART_BRGH_HIGH &
USART_ADDEN_OFF,
spbrg );

//Interrupt on Transmission:
//USART_TX_INT_ON Transmit interrupt ON
//USART_TX_INT_OFF Transmit interrupt OFF
//Interrupt on Receipt:
//USART_RX_INT_ON Receive interrupt ON
//USART_RX_INT_OFF Receive interrupt OFF
//USART Mode:
//USART_ASYNCH_MODE Asynchronous Mode
//USART_SYNCH_MODE Synchronous Mode
//Transmission Width:
//USART_EIGHT_BIT 8-bit transmit/receive
//USART_NINE_BIT 9-bit transmit/receive
//Slave/Master Select*:
//USART_SYNC_SLAVE Synchronous Slave mode
//USART_SYNC_MASTER Synchronous Master mode
//Reception mode:
//USART_SINGLE_RX Single reception
//USART_CONT_RX Continuous reception
//Baud rate:
//USART_BRGH_HIGH High baud rate
//USART_BRGH_LOW Low baud rate
}

Can anybody help me?

Thanks a lot very much !!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top