Hi, I've been working on this issue for days now and I'm not a programmer but I've been trying to make my pic (PIC24HJ12GP201) communicate with my LCD (Matrix Orbital LK204-25). When I connect to output on hyperterm the code works great it shows what it is suppose to show, however I cannot seem to make it work on LCD which is using the serial RS-232 interface. Can anyone please give me an idea as to how to make it work?
Here is the code that I have:
#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);
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
Here is the code that I have:
#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);
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
Attachments
-
3.6 KB Views: 42
-
4.3 KB Views: 32
-
14.9 KB Views: 24