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.

pic18f4550 float value transmission using usart problem.

Status
Not open for further replies.
Joined
Feb 22, 2012
Messages
82
Helped
25
Reputation
50
Reaction score
25
Trophy points
1,298
Activity points
0
HI,

I designed a program given below. it gives an error. So help me to figure out this problem.
Code:
#include<P18f4550.h>
#include <usart.h>
#include <ctype.h>
#include<delays.h>
#include<string.h>


void main(void);
void delay(unsigned int );
void sertx(unsigned char);
int i,y=0,j;
char data[]="1.23";
char serx[];
//int str= strlen(data);


void main(void)
{
   
   TRISD=0X00;

TXSTA1=32;
SPBRG1=25;
TXSTA1bits.TXEN=1;
RCSTA1bits.SPEN=1;


for(y=0;data[y]!= '\0';y++)
	{
	serx[y] = data[y];
    sertx(serx[y]);
	}
serx[y]='\0';
}

void sertx(unsigned char k)
{
	while(PIR1bits.TX1IF==0);
   	TXREG1=k;
    delay(30);
}

void delay(unsigned int c )
{

  for(i=0 ;i<=10;i++)
   {
     	for(j=0;j<=135;j++)
		{
		}
}
}







I have already added header files are ctype.h,delays.h,p18f4550.h,string.h and usart.h and linker file.
 

can you desribe the what is wrong ?
 

In my view you need to convert your float in the char array and then only you will able to send this through UART.....I had written a function to convert the float values to char array

refer the code below-

unsigned char * retrun_char(float num)
{
unsigned char p[5];
unsigned char *p1;
// p = ( unsigned char *) malloc(5*sizeof(unsigned char));
unsigned char idigit,idigit1,idecimal, idecimal1;

idigit = num;
idecimal1 =( num - idigit)*100;
if(idecimal1>=10)
{
idecimal= idecimal1/10;
idecimal1 =idecimal1-(idecimal*10);
}
else
{
idecimal = 0;

}

if(idigit >= 10)
{
idigit1=idigit/10;
idigit = idigit - (idigit1*10);
}
else
{
idigit1 = 0;
}
p[0] =idigit1+48;
p[1] =idigit+48;
p[2] = '.';
p[3] = idecimal+48;
p[4]= idecimal1+48;
p1= &p[0];
return p1;

}

Good Luck
 
Sorry friend I forgot to mention error. These are the errors.



Error [1105] symbol 'TXSTA1' has not been defined
Error [1101] lvalue required
Error [1105] symbol 'SPBRG1' has not been defined
Error [1101] lvalue required
Error [1105] symbol 'TXSTA1bits' has not been defined
Error [1151] struct or union object designator expected
:Error [1101] lvalue required
Error [1105] symbol 'RCSTA1bits' has not been defined
Error [1151] struct or union object designator expected
Error [1101] lvalue required
Error [1205] unknown member 'TX1IF' in '__tag_100'
Error [1128] compatible scalar operands required for comparison
Error [1118] scalar type expected in 'while' statement
Error [1105] symbol 'TXREG1' has not been defined

---------- Post added at 06:35 ---------- Previous post was at 06:09 ----------

Hi,


I solved errors. I was little stupid in writing a registers name. I wrote TXREG1 instead of TXREG and all.

Thanks for your help...
 
  • Like
Reactions: hd.

    hd.

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top