Hey thx for ur reply allen
sending to the lcd is just a test for myself to check if the conversion from string to integer had been successful
my prime aim , is to be able to collect data of integer or double type from a xbee
And since , the xbee output are string or characters and want to convert those into integers or doubles for further computational work
....
thx once more
From my last post , i advance a little bit
the stuff , compile successfully but i am having strange sign at the LCD ..
have a look on this code pls
- 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[3] = "123";
int value;
int i,n;
// Prototypes================================================================================
//void delay(unsigned short i);
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void dis_num(unsigned long data);
void e_pulse(void);
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
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);
}
}
//Functions
void send_char(unsigned char data) //send lcd character
{
rs=1; //set lcd to display mode
lcd=data; //lcd data port = data
e=1; //pulse e to confirm the data
__delay_ms(500); //before 10
e=0;
__delay_ms(500);
}
void lcd_goto(unsigned char data) //set the location of the lcd cursor
{ //if the given value is (0-15) the
if(data<16) //cursor will be at the upper line
{ //if the given value is (20-35) the
send_config(0x80+data); //cursor will be at the lower line
} //location of the lcd cursor(2X16):
else // -----------------------------------------------------
{ // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
data=data-20; // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
send_config(0xc0+data); // -----------------------------------------------------
}
}
void lcd_clr(void) //clear the lcd
{
send_config(0x01);
__delay_ms(600);
}
void send_string(const char *s) //send a string to display in the lcd
{
while (s && *s)send_char (*s++);
}
void e_pulse(void)
{
e=1;
__delay_ms(500); //before 50000
e=0;
__delay_ms(500); // before 50000
}
void send_config(unsigned char data)
{
rs=0;
lcd = data;
__delay_ms(500); // before 50000
e_pulse();
}
void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;
hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;
if(hundred_thousand>0)
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}