Conversion of data recieved by Xbee ....

Bluetooth, XBee, RF......

Re: Conversion of data recieved by Xbee ....

Postby Kromuald13 » Mon Mar 12, 2012 6:36 pm

Is C[3] a string yet ??
Kromuald13
Novice
 
Posts: 26
Joined: Wed Feb 09, 2011 2:03 am

Re: Conversion of data recieved by Xbee ....

Postby ABSF » Mon Mar 12, 2012 8:08 pm

Your original program which works

char code[4] ="1234";
while(1)
{
value = atoi(code);
lcd_goto(5);
send_string(" the value is ");
lcd_goto(20);
dis_num(value);
}


But in your new program, it becomes:

unsigned char c[3] = "123";
while(1)
{
int value = atoi(c[3]);
lcd_goto(0);
send_string("the value is");
lcd_goto(20);
dis_num(value);
}


You need to read more

http://www.ro.feri.uni-mb.si/predmeti/m ... chap07.htm
http://www.iu.hio.no/~mark/CTutorial/CT ... tml#Arrays
http://www.iu.hio.no/~mark/CTutorial/CT ... ml#Strings

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Conversion of data recieved by Xbee ....

Postby robosang » Mon Mar 12, 2012 10:38 pm

Kromuald13 WROTE:Is C[3] a string yet ??


It depends what you put in c[3];

c[3] simply mean an array of char (8-bit) space with 3 elements, mean you can only store 3 byte of data into this array. String is an array with special condition. All elements must be in char (8-bit) and they will be treated as ASCII code and these character must be terminated with NULL or \0 or the value of 0. In ASCII, every character have value, even '0' have value of 0x30, so program uses \0 to indicate that a string is finish or complete of a sentence.

Yup, read more! This is just a tiny concept!
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Conversion of data recieved by Xbee ....

Postby Kromuald13 » Tue Mar 13, 2012 1:56 am

Hey guys , thx for ur replies and advices
fianlly get it workly perfectly
here below is the full
the problem was at the declaration of the string and also the application of the function atoi : no brakect should be ther
May God Bless u guys

CODE: SELECT_ALL_CODE
#include<pic.h>
#include<stdlib.h>
#include <stdio.h>
#include<htc.h>
__CONFIG (0x3F32);
/*
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
*/

#define lcd        PORTD
#define rs         RB4
#define e          RB5

unsigned char data;
unsigned char c[] = "879/0";
int value,value1;
int i,n;

// Prototypes================================================================================

//void delay(unsigned short i);

void send_string(const char *s) ;
void lcd_clr(void);
void lcd_goto(unsigned char data);
void e_pulse(void);
void send_dec(unsigned long data,unsigned char num_dig);
void send_char(unsigned char data);
void send_config(unsigned char data);
void delay(unsigned long data);
   


void  main(void)
{
       ADCON1=0b00000110;
        TRISB=0b00000011;
        TRISC=0b01000000;
        TRISD=0b00000000;
   

        PORTC=0;
      PORTD=0;
       PORTB=0;



   send_config(0b00001001);   //clear display at lcd
   send_config(0b00000010);   //Lcd Return to home
   send_config(0b00000110);   //entry mode-cursor increase 1
   send_config(0b00001100);   //diplay on, cursor off and                //cursor blink off
   send_config(0b00111000);   //function   
   
 

   
while(1)
{
    value = atoi(c);
 
lcd_goto(0);
send_string("the value is");
lcd_goto(20);

send_dec(value,3);
}


}



//Functions

void delay(unsigned long data)                        //delay function, the delay time
{   
   int i;
   for( i = data; i>0; i--);                        //depend on the given value
}




//   LCD   functions
//============================================================================================================

void send_config(unsigned char data)                  //send lcd configuration
{
   rs=0;                                       //set lcd to config mode
   lcd=data;                                 //lcd data port = data
   delay(400);                        
   e_pulse();                                    //pulse e to confirm the data
}

void send_char(unsigned char data)                     //send lcd character
{
   rs=1;                                       //set lcd to display mode
   lcd = data;                              //lcd data port = data            
   delay(400);
   e_pulse();                                    //pulse e to confirm the data
}

void send_dec(unsigned long data,unsigned char num_dig)      //convert binary number and display number in decimal
{
   if(num_dig>=10)                                 
   {
      data=data%10000000000;
      send_char(data/1000000000+0x30);
   }   
   if(num_dig>=9)
   {
      data=data%1000000000;
      send_char(data/100000000+0x30);
   }   
   if(num_dig>=8)
   {
      data=data%100000000;
      send_char(data/10000000+0x30);
   }   
   if(num_dig>=7)
   {
      data=data%10000000;
      send_char(data/1000000+0x30);
   }   
   if(num_dig>=6)
   {
      data=data%1000000;
      send_char(data/100000+0x30);
   }   
   if(num_dig>=5)
   {
      data=data%100000;
      send_char(data/10000+0x30);
   }   
   if(num_dig>=4)
   {
      data=data%10000;
      send_char(data/1000+0x30);
   }
   if(num_dig>=3)
   {
      data=data%1000;
      send_char(data/100+0x30);
   }
   if(num_dig>=2)
   {
      data=data%100;
      send_char(data/10+0x30);
   }
   if(num_dig>=1)
   {
      data=data%10;
      send_char(data+0x30);
   }
}

void e_pulse(void)                              //pulse e to confirm the data
{
   e=1;
   delay(300);
   e=0;
   delay(300);
}

void lcd_goto(unsigned char data)                  //set the location of the lcd cursor
{
    if(data<16)                                 //if the given value is (0-15) the
   {                                       //cursor will be at the upper line
       send_config(0x80+data);
   }
   else                                    //if the given value is (20-35) the
   {                                       //cursor will be at the lower line
       data=data-20;                           //location of the lcd cursor(2X16):
      send_config(0xc0+data);                     // -----------------------------------------------------
   }                                       // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
}                                          // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
                                          // -----------------------------------------------------   

void lcd_clr(void)                              //clear the lcd
{   
    send_config(0x01);
   delay(350);   
}

void send_string(const char *s)                   //send a string to display in the lcd
{         
     while (s && *s)send_char (*s++);
}






Kromuald13
Novice
 
Posts: 26
Joined: Wed Feb 09, 2011 2:03 am

Re: Conversion of data recieved by Xbee ....

Postby ABSF » Tue Mar 13, 2012 9:26 am

Glad to hear that it works. :)

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Previous

Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 9 guests

cron