...
unsigned char dataString[10]="1234567890";
...
void main()
...
LCDinit();
while (1) // this is how to make a never ending loop.
{
lcdcmd(0x1);
lcdcmd(0x2);
//itoa (integer, biginin);
stringtoLCD(dataString);
}
void LCDinit(void)
{
TRISE=0;
lcdcmd(0x28); //set 4-bit upper mode and 2 lines
lcdcmd(0x10); //cursor move & shift left
lcdcmd(0x06); //entry mode = increment
lcdcmd(0x0d); //display on - cursor blink on
lcdcmd(0x01); //clear display
}
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(i<10)
{
LCDdata(m[i]);
i++;
}
}
void lcdcmd(unsigned char temp)
{
busylcd();
RS=0;
RW=0;
TRISD=0;
DATALCD=temp;
E=1;
LCDDelay();
E=0;
}
void LCDDelay(void)
{
int i=0;
int j=0;
int k=0;
int l=0;
int ll=0;
while (i<10)
{
j=0;
while (j<10)
{
j++;
l++;
ll++;
k++;
}
i++;
}
}
Post your LCDdata function here, May be It has following described problem:
you're not adding 30 in all your digits, you need to do it because you are sending just 1,2,3... one by one.
but instead you need to send their ASCII values, & you'll get them by adding 30 to your decimal values.
so send 31,32,33... to print 1,2,3....
void LCDdata (unsigned char value)
{
busylcd();
TRISD = 0;
DATALCD = value;
RS=1;
RW=0;
E=1;
LCDDelay();
E=0;
}
Magvitron said:from the looks of waht you said, it may be due to improper data pin assigned.
Code:void LCDdata (unsigned char value) { busylcd(); TRISD = 0; DATALCD = value; RS=1; RW=0; E=1; LCDDelay(); E=0; }
void LCDdata (unsigned char value)
{
busylcd();
TRISD = 0;
value+=30;
DATALCD = value;
RS=1;
RW=0;
E=1;
LCDDelay();
E=0;
}
Instead of above use this code and check it:
Code:void LCDdata (unsigned char value) { busylcd(); TRISD = 0; value+=30; DATALCD = value; RS=1; RW=0; E=1; LCDDelay(); E=0; }
Instead of above use this code and check it:
Code:void LCDdata (unsigned char value) { busylcd(); TRISD = 0; [B][COLOR="#FF0000"]value+=30;[/COLOR][/B] DATALCD = value; RS=1; RW=0; E=1; LCDDelay(); E=0; }
void LCDdata (unsigned char value)
{
busylcd();
TRISD = 0;
value+=0x30;
DATALCD = value;
RS=1;
RW=0;
E=1;
LCDDelay();
E=0;
}
In order to convert the integer to an ascii format you either need to add hex 0x30 or decimal 48 , if you add decimal 30 then you will get wrong result
- - - Updated - - -
@myru28
Try with
Code:void LCDdata (unsigned char value) { busylcd(); TRISD = 0; value+=0x30; DATALCD = value; RS=1; RW=0; E=1; LCDDelay(); E=0; }
unsigned char dataString[10] = "1234567890";
Code:unsigned char dataString[10] = "1234567890";
This doesn't leave space for the null terminator, either use dataString[10] or dataString[]
you are configuring for 4 bit nah? or 8 bit?lcdcmd(0x28); //set 4-bit upper mode and 2 lines
void four_bit_data(unsigned char datai)
{
unsigned char datax;
datax=(datai &0xF0); // data is anded with 0f0 for the upper nibble
LCDdata(datax); // sent the data.
data1=((datai<<4)&0xF0); // this for lower nibble
LCDdata(datax);
}
void four_bit_cmd(unsigned char datai)
{
unsigned char datax;
datax=(datai &0xF0);
lcdcmd(datax);
data1=((datai<<4)&0xF0);
lcdcmd(datax);
}
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(i<10)
{
four_bit_data(m[i]);
i++;
}
}
void lcd_ini()
{
dis_cmd(0x02); // To initi LCD in 4-bit mode.
dis_cmd(0x28); // To init LCD in 2 lines and have 5x7 dots and in 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x80);
}
I believe the following piece of code:
Code:void stringtoLCD(unsigned char *m)
void stringtoLCD(unsigned char *m)
{
unsigned char i;
for(i=1;i<=10;i++)
{
LCDdata(*m);
m++;
}
}
I got the EXACT LOCATION OF YOUR ERROR.
try by editing this function (stringtoLCD) as below: (I've implement this code on hardware through 8051 before sometime)
Code:void stringtoLCD(unsigned char *m) { unsigned char i; for(i=1;i<=10;i++) { LCDdata(*m); m++; } }
Reason : you can't use the pointer as an array.
Pointer assignment is straightforward; the pointer on the left is simply made to point wherever the pointer on the right does. We haven't copied the data pointed to (there's still just one copy, in the same place); we've just made two pointers point to that one place.
The similarities between arrays and pointers end up being quite useful, and in fact C builds on the similarities, leading to what is called ``the equivalence of arrays and pointers in C.'' When we speak of this ``equivalence'' we do not mean that arrays and pointers are the same thing (they are in fact quite different), but rather that they can be used in related ways, and that certain operations may be used between them.
The first such operation is that it is possible to (apparently) assign an array to a pointer:
Code:int a[10]; int *ip; ip = a;
What can this mean? In that last assignment ip = a, aren't we mixing apples and oranges again? It turns out that we are not; C defines the result of this assignment to be that ip receives a pointer to the first element of a. In other words, it is as if you had written
Code:ip = &a[0];
The second facet of the equivalence is that you can use the ``array subscripting'' notation on pointers, too. If you write
Code:ip[3]
it is just as if you had written
Code:*(ip + 3)
So when you have a pointer that points to a block of memory, such as an array or a part of an array, you can treat that pointer ``as if'' it were an array, using the convenient notation. In other words, at the beginning of this section when we talked about *ip, *(ip+1), *(ip+2), and *(ip+i), we could have written ip[0], ip[1], ip[2], and ip. As we'll see, this can be quite useful (or at least convenient).
problems:
you are configuring for 4 bit nah? or 8 bit?
if for 4 bit the data to lcd routine is completely off here.
for data inp
for command :Code:void four_bit_data(unsigned char datai) { unsigned char datax; datax=(datai &0xF0); // data is anded with 0f0 for the upper nibble LCDdata(datax); // sent the data. data1=((datai<<4)&0xF0); // this for lower nibble LCDdata(datax); }
and enter it hereCode:void four_bit_cmd(unsigned char datai) { unsigned char datax; datax=(datai &0xF0); lcdcmd(datax); data1=((datai<<4)&0xF0); lcdcmd(datax); }
Code:void stringtoLCD(unsigned char *m) { unsigned char i; i = 0; while(i<10) { four_bit_data(m[i]); i++; } }
and for init
Code:void lcd_ini() { dis_cmd(0x02); // To initi LCD in 4-bit mode. dis_cmd(0x28); // To init LCD in 2 lines and have 5x7 dots and in 4bit mode. dis_cmd(0x0C); dis_cmd(0x06); dis_cmd(0x80); }
#include <stdio.h>
#include <P18CXXX.h>
#include <delays.h>
#include <timers.h>
#pragma code page // This code make sure the program starts from 0x0004, not from 0x0000
#pragma config WDT = OFF
#pragma config OSC=INTIO67
#define RS PORTEbits.RE1
#define dirRS TRISEbits.TRISE1
#define RW PORTBbits.RB1
#define dirRW TRISBbits.TRISB1
#define E PORTEbits.RE2
#define dirE TRISEbits.TRISE2
#define DATALCD PORTD
#define dirDATA TRISD
#define LCDBusy PORTDbits.RD7
void LCDdata (unsigned char);
void busylcd(void);
void LCDinit (void);
void LCDDelay( void );
void lcdcmd(unsigned char);
void stringtoLCD(unsigned char *m);
void four_bit_cmd(unsigned char datai);
void four_bit_data(unsigned char datai);
unsigned char dataString[]="2";
void main (void) // main function
{
TRISD = 0;
PORTD = 0;
TRISB = 0; // Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1; // make sure this pin is input
ADCON1=255;
dirRS = 0;
LCDinit();
while (1) // this is how to make a never ending loop.
{
lcdcmd(0x1);
lcdcmd(0x2);
stringtoLCD(dataString);
}
//Con LCDInit propuesto no funciona
//Con LCDInit normal y configurado para 4 bits funciona a veces y da lo mismo y con simbolos raros
//Con LCDInit normal y configurado para 8 suele funcionar sacando el 3
}
//////////////////////////////////////////////////////////////////////////////////////
//LCD finctions------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////
void LCDdata (unsigned char value)
{
busylcd();
TRISD = 0;
DATALCD = value;
RS=1;
RW=0;
E=1;
LCDDelay();
E=0;
}
//--------------------------------------------------------------------------------------
void LCDinit(void)
{
TRISE=0;
//clear display*/
four_bit_cmd(0x02); // To initi LCD in 4-bit mode.
four_bit_cmd(0x28); // To init LCD in 2 lines and have 5x7 dots and in 4bit mode.
four_bit_cmd(0x0C);
four_bit_cmd(0x06);
four_bit_cmd(0x80);
}
//-------------------------------------------------------------------------------------
void busylcd(void)
{
RS=0;
RW=1;
TRISD=255;
E=0;
LCDDelay();
E=1;
while(LCDBusy==1){
E=0;
LCDDelay();
E=1;
}
}
//-------------------------------------------------------------------------------------
void lcdcmd(unsigned char temp)
{
busylcd();
RS=0;
RW=0;
TRISD=0;
DATALCD=temp;
E=1;
LCDDelay();
E=0;
}
void four_bit_data(unsigned char datai)
{
unsigned char datax;
unsigned char data1;
datax=(datai &0xF0); // data is anded with 0f0 for the upper nibble
LCDdata(datax); // sent the data.
data1=((datai<<4)&0xF0); // this for lower nibble
LCDdata(datax);
}
void four_bit_cmd(unsigned char datai)
{
unsigned char datax;
unsigned char data1;
datax=(datai &0xF0);
lcdcmd(datax);
data1=((datai<<4)&0xF0);
lcdcmd(datax);
}
//--------------------------------------------------------------------------------------
void LCDDelay(void)
{
int i=0;
for (i=0;i<250;i++);
}
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(i<1)
{
four_bit_data(m[i]);
i++;
}
}
void four_bit_data(unsigned char datai)
{
unsigned char datax;
unsigned char data1;
datax=(datai &0xF0); // data is anded with 0f0 for the upper nibble
LCDdata(datax); // sent the data.
[COLOR="#FF0000"]datax[/COLOR]=((datai<<4)&0xF0); // this for lower nibble
LCDdata(datax);
}
#include <stdio.h>
#include <P18CXXX.h>
#include <delays.h>
#include <timers.h>
#pragma code page // This code make sure the program starts from 0x0004, not from 0x0000
#pragma config WDT = OFF
#pragma config OSC=INTIO67
/*
#define RS PORTEbits.RE1
#define dirRS TRISEbits.TRISE1
#define RW PORTBbits.RB1
#define dirRW TRISBbits.TRISB1
#define E PORTEbits.RE2
#define dirE TRISEbits.TRISE2
#define DATALCD PORTD
#define dirDATA TRISD
*/
#define RS LATE.F1
#define RW LATB.F1
#define E LATE.F2
#define DATALCD LATD
//conectar el nibble superior de la pantalla LCD para el nibble b puerto mas alto que es el puerto b 4-7
void LCDdata (unsigned char);
void LCDinit (void);
void LCDDelay( void );
void lcdcmd(unsigned char);
void four_bit_cmd(unsigned char datai);
void four_bit_data(unsigned char datai);
unsigned char dataString[]="Hola mundo";
void main (void) // main function
{
unsigned int i=0;
TRISD=0; // Configure Port B as output port
LATD=0;
LCDinit();
while (1) // this is how to make a never ending loop.
{
unsigned int i;
while(dataString[i]!='\0')
{
four_bit_data(dataString[i]);
i++;
}
}
//Con LCDInit propuesto no funciona
//Con LCDInit normal y configurado para 4 bits funciona a veces y da lo mismo y con simbolos raros
//Con LCDInit normal y configurado para 8 suele funcionar sacando el 3
}
//////////////////////////////////////////////////////////////////////////////////////
//LCD finctions------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////
void LCDdata (unsigned char value)
{
DATALCD = value;
RS=1;
RW=0;
E=1;
Delay_ms(10);
E=0;
}
//--------------------------------------------------------------------------------------
void LCDinit(void)
{
//clear display*/
four_bit_cmd(0x02); // To initi LCD in 4-bit mode.
four_bit_cmd(0x28); // To init LCD in 2 lines and have 5x7 dots and in 4bit mode.
four_bit_cmd(0x0C);
four_bit_cmd(0x06);
four_bit_cmd(0x80);
}
//-------------------------------------------------------------------------------------
void lcdcmd(unsigned char temp)
{
RS=0;
RW=0;
DATALCD=temp;
E=1;
Delay_ms(10);
E=0;
}
void four_bit_data(unsigned char datai)
{
unsigned char datax;
datax=(datai &0xF0); // data is anded with 0f0 for the upper nibble
LCDdata(datax); // sent the data.
data1=((datai<<4)&0xF0); // this for lower nibble
LCDdata(datax);
}
void four_bit_cmd(unsigned char datai)
{
unsigned char datax;
datax=(datai &0xF0);
lcdcmd(datax);
data1=((datai<<4)&0xF0);
lcdcmd(datax);
}
//--------------------------------------------------------------------------------------
}
So when you have a pointer that points to a block of memory, such as an array or a part of an array, you can treat that pointer ``as if'' it were an array, using the convenient notation. In other words, at the beginning of this section when we talked about *ip, *(ip+1), *(ip+2), and *(ip+i), we could have written ip[0], ip[1], ip[2], and ip. As we'll see, this can be quite useful (or at least convenient).
Code:void stringtoLCD(unsigned char *m) { unsigned char i; i = 0; while(i<1) { four_bit_data(m[i]); i++; } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?