nikhilrajg
Member level 3
- Joined
- Mar 2, 2012
- Messages
- 63
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Manipal,Karnataka,India
- Activity points
- 1,834
Hello,
I am working on PIC24FJ128GA010 micro-controller on Explorer-16 Development Board,..using MPLAB ICD 2 Debugger/Programmer.
Well I tried a lot to execute the serial port program just to send & receive the data from Micro controller to the HYPER TERMINAL, i.e., on the real hardware connected to PC via RS232 wire to the COM1 port... Nothing is working. The code works in the simulator and I am getting the result in Uart1 window. I dont know whether my code is wrong in some places like to set the baud rates and enabling the UART ect ... ??
Can please someone check this bellow code and reply me back whether the code is CORRECT or WRONG !! If found wrong can you please post the correct one ??? And I beg for your suggestions for the exact method to be followed to get the proper output on the terminal...
I have set BRATE(a defined new variable) as 129 in the code for 9600 baud rate.. Is it the correct one ??
Please correct the code and repost it. Can anyone please tell me how to find out the oscillator frequency ?
Thanks for your consideration.
Nikhil Raj
I am working on PIC24FJ128GA010 micro-controller on Explorer-16 Development Board,..using MPLAB ICD 2 Debugger/Programmer.
Well I tried a lot to execute the serial port program just to send & receive the data from Micro controller to the HYPER TERMINAL, i.e., on the real hardware connected to PC via RS232 wire to the COM1 port... Nothing is working. The code works in the simulator and I am getting the result in Uart1 window. I dont know whether my code is wrong in some places like to set the baud rates and enabling the UART ect ... ??
Can please someone check this bellow code and reply me back whether the code is CORRECT or WRONG !! If found wrong can you please post the correct one ??? And I beg for your suggestions for the exact method to be followed to get the proper output on the terminal...
Code:
/***********************************************************************************************************/
/***********************************************************************************************************/
#include<p24fj128ga010.h>
#define CTS _RF12
#define RTS _RF13
#define TRTS TRISFbits.TRISF13
#define BRATE 129
#define U_ENABLE 0X8008
#define U_TX 0X0400
#define DELAY 1
void initU2()
{
U1BRG = BRATE;
U1MODE = U_ENABLE;
U1STA = U_TX;
TRTS = 0;
T1CON = 0x8030;
TMR1=0;
while(TMR1 < DELAY);
TMR1 = 0;
RTS = 1;
}
int putU2(int c)
{
while(CTS);
while(U1STAbits.UTXBF);
U1TXREG = c;
return c;
}
char getU2(void)
{
RTS = 0;
while(!U1STAbits.URXDA);
return U1RXREG;
RTS = 1;
}
//=======================================================
int putsU2(char *s)
{
printf("%s",(*s));
while(*s)
putU2(*s++);
}
char *getsnU2(char *s,int len)
{
char *p = s;
do
{
*s = getU2();
if(*s=='\r')
break;
s++;
len--;
}while(len>1);
*s = '\0';
return p;
}
//=======================================================
void main(void)
{
initU2();
while(1)
putsU2("hello\t");
}
/**********************************************************************************************************/
/**********************************************************************************************************/
I have set BRATE(a defined new variable) as 129 in the code for 9600 baud rate.. Is it the correct one ??
Please correct the code and repost it. Can anyone please tell me how to find out the oscillator frequency ?
Thanks for your consideration.
Nikhil Raj