char code[4] ="1234";
while(1)
{
value = atoi(code);
lcd_goto(5);
send_string(" the value is ");
lcd_goto(20);
dis_num(value);
}
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);
}
Kromuald13 WROTE:Is C[3] a string yet ??
#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++);
}
Users browsing this forum: No registered users and 45 guests