Society of Robots - Robot Forum
Software => Software => Topic started by: algorithem on October 08, 2008, 01:17:33 AM
-
Baud rate at 9600, want to display data like <CO2 READING> on LCD display.
Original data below:
// configuration bit settings, Fcy=72MHz, Fpb=36MHz
#pragma config POSCMOD=XT, FNOSC=PRIPLL
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF
#define FCY 72000000L
#define FPB 36000000L
#include <p32xxxx.h>
// I/O definitions for the Explorer16
#define CTS _RF12 // Cleart To Send, input
#define RTS _RF13 // Request To Send, output
#define TRTS TRISFbits.TRISF13 // tris control for RTS pin
// timing and baud rate calculations
#define BRATE (FPB/4/9600)-1 // 9600 baud
#define U_ENABLE 0x8008 // enable UART (BREGH=1)
#define U_TX 0x0400 // enable transmission
// initialize the UART2 serial port
void initU2( void)
{
U2BRG = BRATE;
U2MODE = U_ENABLE;
U2STA = U_TX;
TRTS = 0; // make RTS output
RTS = 1; // set RTS default status
} // initU2
// send a character to the UART2 serial port
int putU2( int c)
{
while ( CTS); // wait for !CTS, clear to send
while ( U2STAbits.UTXBF); // wait while Tx buffer full
U2TXREG = c;
return c;
} // putU2
// wait for a new character to arrive to the UART2 serial port
char getU2( void)
{
RTS = 0; // assert Request To Send !RTS
while ( !U2STAbits.URXDA); // wait for a new character to arrive
RTS = 1;
return U2RXREG; // read the character from the receive buffer
}// getU2
main()
{
char c;
// 1. init the UART2 serial port
initU2();
// 2. prompt
putU2( '>');
// 3. main loop
while ( 1)
{
// 3.1 wait for a character
c = getU2();
// 3.2 echo the character
putU2( c);
} // main loop
}// main
May i know what do i need to change from the code above in order to display "CO2 READING" ?
THANK YOU VERY MUCH.
-
How do i program a string of characters to be transmitted throught the U2TX pin from my I/O expansion board so my serial LCD can show this characters on it.
This is the program im trying ,Thank You for your time :
/*
** Tranmission.C
** UART2 RS232 asynchronous communication demonstration code
**
*/
// configuration bit settings, Fcy=72MHz, Fpb=36MHz
#pragma config POSCMOD=XT, FNOSC=PRIPLL
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF
#define FCY 72000000L
#define FPB 36000000L
#include <p32xxxx.h>
// I/O definitions for the Explorer16
#define CTS _RF12 // Cleart To Send, input
#define RTS _RF13 // Request To Send, output
#define TRTS TRISFbits.TRISF13 // tris control for RTS pin
// timing and baud rate calculations
#define BRATE (FPB/4/9600)-1 // 9600 baud
#define U_ENABLE 0x8008 // enable UART (BREGH=1)
#define U_TX 0x0400 // enable transmission
// initialize the UART2 serial port
void initU2( void)
{
U2BRG = BRATE;
U2MODE = U_ENABLE;
U2STA = U_TX;
TRTS = 0; // make RTS output
RTS = 1; // set RTS default status
} // initU2
// send a character to the UART2 serial port
void putU2( int c)
{
while ( U2STAbits.UTXBF); // wait while Tx buffer full
U2TXREG = c;
} // putU2
main()
{
char c[16],b;
int i=0;
c="Welcome To Pic32";
initU2();
while(1)
{
b=c
putU2( b);
i++;
if i=15
{
i=0;
}
}
} // main
I wanted to sent this string IG to be shown on my serial LCD working on 9600 baudrate.
This was shown on my Output:
Make: The target "C:\Documents and Settings\students\Desktop\GEY grp\CONU2test.o" is out of date.
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX360F512L -x c -c "C32\9 UART\CONU2test.c" -o"CONU2test.o" -MMD -MF"CONU2test.d" -g
C32\9 UART\CONU2test.c: In function `main':
C32\9 UART\CONU2test.c:29: error: incompatible types in assignment
Halting build on first failure as requested.
BUILD FAILED: Mon Oct XX XX:XX:XX 2008
What does this mean?Can anyone explain to me or teach me any methods for me to send This string of characters to the transmitter pin simultaneously so it can presented on my serial LCD?
-
/*
** Tranmission.C
** UART2 RS232 asynchronous communication demonstration code
**
*/
// configuration bit settings, Fcy=72MHz, Fpb=36MHz
#pragma config POSCMOD=XT, FNOSC=PRIPLL
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF
#define FCY 72000000L
#define FPB 36000000L
#include <p32xxxx.h>
// I/O definitions for the Explorer16
#define CTS _RF12 // Cleart To Send, input
#define RTS _RF13 // Request To Send, output
#define TRTS TRISFbits.TRISF13 // tris control for RTS pin
// timing and baud rate calculations
#define BRATE (FPB/4/9600)-1 // 9600 baud
#define U_ENABLE 0x8008 // enable UART (BREGH=1)
#define U_TX 0x0400 // enable transmission
// initialize the UART2 serial port
void initU2( void)
{
U2BRG = BRATE;
U2MODE = U_ENABLE;
U2STA = U_TX;
TRTS = 0; // make RTS output
RTS = 1; // set RTS default status
} // initU2
// send a character to the UART2 serial port
void putU2( int c)
{
while ( U2STAbits.UTXBF); // wait while Tx buffer full
U2TXREG = c;
} // putU2
main()
{
char c[16],b;
int i=0;
c="Welcome To Pic32";
initU2();
while(1)
{
b=c
putU2( b);
i++;
if i=15
{
i=0;
}
}
always use [ code ] tags
-
what do you mean by always use code tags?? can you give an example??
Thanks.
-
If you google for it, or read the compiler manual, answers will come ;D
(outputing a string in C)
But for a quick hack, I see this:
// 3.2 echo the character
putU2( c);
that could easily be:
putU2("h");putU2("e");putU2("l");putU2("l");putU2("o");
and maybe even this depending on your compiler:
putU2("hello world!");
Oh, and DO NOT DOUBLE POST. It causes a ton of confusion with double answers and mostly just mucks up the forum. I merged your two posts.
-
I've checked your code.
while(1)
{
b=c
putU2( b);
i++;
if i=15
{
i=0;
}
}
Number one. b and c are char c[16],b; (as you defined them)
when you will assign c to b, b will only contain the first character of b. you won't get all the characters in c, one by one into b, because what an array of char returns is always a pointer to the first element.
what you want is b = c[ i];
Two. You ever heard about scope? If you declare a global variable gigi, it will be seen everywhere. If you'll declare a gigi variable inside function fute() it won't be seen outside fute(). You declared your variables in main(), so they are not global. However, you are using them inside another function. How do you expect THAT to work?
Alas, remember to declare variables used in both procedural code and interrupt as volatile, such as volatile int ana;