Here is the code that I have:
[code]
#define FCY 25000000
#define BAUDRATE 19200
#define BRGVAL ((FCY/BAUDRATE)/16)-1
void initUART(void)
{
PORTBbits.RB4 = 1;
///***************************
// Assign U1Rx To Pin RP0
//***************************
RPINR18bits.U1RXR = 0;
//***************************
// Assign U1CTS To Pin RP1
//***************************
RPINR18bits.U1CTSR = 1;
//***************************
// Configure Output Functions
// (See Table 9-2)
//***************************
//***************************
// Assign U1Tx To Pin 11
//***************************
RPOR4bits.RP8R = 3;
//***************************
// Assign U1RTS To Pin 12
//***************************
RPOR4bits.RP9R = 4;
//UART Initialization//
PLLFBD=38; // M=40
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
RCONbits.SWDTEN=0; // Disable Watch Dog Timer
while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock
U1MODEbits.STSEL = 0; // 1-stop bit
U1MODEbits.PDSEL = 0; // No Parity, 8-data bits
U1MODEbits.ABAUD = 0; // Autobaud Disabled
U1MODEbits.BRGH = 0; // Low Speed mode
U1BRG = BRGVAL; // BAUD Rate Setting for 19200
U1STAbits.UTXISEL1 = 0;
U1MODEbits.UARTEN = 1; // Enable UART
U1STAbits.UTXEN = 1; // Enable UART Tx
}
///////////////////////////////////////////////////////////////////
int main ()
{
unsigned int place1,place2,place3;
int STX,ETX,sign,unit_num;
int temperature;
initADC(); // initialize the ADC
initUART(); // initalize the UART
LCDinit();
OutStr(">");
The LCDinit(); Is a function from a header. I didn't included it here, but what the LCD requires to perform tasks is to have decimal values sent to it. For instance in order to clear the screen which I've been trying to do, the following must be done (this is excerpt from LCD manual);
Clear Screen
Syntax Hexadecimal 0xFE 0x58
Decimal 254 88
ASCII 254 ?X?
Description This command will immediately clear all of the contents of the display.
so what I've done is make the following commands
WriteUART1(254);
WriteUART1(88);
[/code]
I do not know why it does not work by sending this, I have the LCD to it's default setting to 19200 baudrate and that's how i set software too. Please, any help with be greatly appreciated
You also indicated (I believe) that the RS-232 output of your PIC design generates the correct characters on the computer monitor (running hyperterminal) in response to the characters you send it.
All of the above understanding being true then a few things to check are that the LCD is set to the correct bit-per-second data rate and that the LCD is set to RS-232 mode and not I2C data mode. Do you have the correct pinout so that you are sending the data to the LCD on its receive input pin and not accidentally on its transmit output pin?
Can you post a copy of the schematic of your PIC board so that we can have a look at the hardware connections you are using.
And as a matter of fact, I do have that chip!! I connected it and like said before it works for hyperterminal but it does not work for my LCD. This is my first time ever programming a PIC, I'm sure something about my code is weird. Any other suggestions?
The I2C interfaces is indeed a 0V to 5V signal interface but the serial data definition is different from the RS-232 serial data definition.
You could get your hands on a MAX232 device. This device runs on 5V but is capable of translating from the 0 to 5V logic levels used by the microcontroller to the typical -10V to +10V signal levels required by RS-232.
Someone who knows how to resolve this..it really is boggling me