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.

Increment count on LCD display?

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
I want to increment a count and display in lcd, when pushbutton is pressed. Button connected to PIN C0. It compiles successfully. In the display it shows count, but when i press push button it shows different characters at location 0x86 in the display. Please help...
HTML:
#include "18F2520.h"
#fuses  INTRC_IO
#use delay(clock=4000000)     // internal clock

#define RS PIN_A2   
#define EN PIN_A1

void lcd_init();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
unsigned char data[] = "count";
unsigned int i = 0;
unsigned int counter = 0;
int16 temp;

void main()
{
lcd_init();
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
while(1)
{
while(data[i]!='\0')
{
lcd_data(data[i]);
i++;
}
lcd_cmd(0x86);
if(input(PIN_C0)==0)
{
delay_ms(200);
temp=counter++;
lcd_data(temp);
}
}
}

void lcd_init()
{
   lcd_cmd(0x30);      // Configure the LCD in 8-bit mode, 1 line and 5x7 font
   lcd_cmd(0x0C);      // Display On and Cursor Off
   lcd_cmd(0x01);      // Clear display screen
   lcd_cmd(0x06);      // Increment cursor
   lcd_cmd(0x80);      // Set cursor position to 1st line, 1st column
}

void lcd_cmd(unsigned char c)
{
output_b(c);
output_low(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}

void lcd_data(unsigned char z)
{
output_b(z);
output_high(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
 

Where is your TRIS settings?

Change this ti
Code:
if(input(PIN_C0)==0)
{
delay_ms(200);
temp=counter++;
lcd_data(temp);
}

to

Code:
if(input(PIN_C0)==0)
{
delay_ms(200);
if(input(PIN_C0)==0)
{
temp=counter++;
lcd_data(temp);
}
}
 
Last edited:

When sending data to LCD you should keep in mind that to LCD meaningful data is ASCII characters.
But you have used unsigned int which is a decimal value.
So you should make a conversion before sending it to LCD.
the conversion is as follows:
if X=100;
lcd_data((X/100)+0x30);
lcd_data(((X%100)/10)+0x30);
lcd_data((X%10)+0x30);
In this manner you can display the value 100 in LCD as 100 itself
 
Thanks for the useful information.
Code:
lcd_data((X/100)+0x30);
When i use this line in my program, and when pushbutton is pressed, it increments to 0 and no more increment . Y it is?

Code:
lcd_data((X/100)+0x30);
lcd_data(((X%100)/10)+0x30);
lcd_data((X%10)+0x30);
when i use all these lines, it increments normally. Please can you guide me how you did this? how you convert the values to ascii? Please help.

Thanks in advance :)
 

Hemanth, in Ascii characters there is no 10 or more numbers.. it has only 0 to 9 after that other characters... refer this
https://www.asciitable.com/
so if you want to display 19 you have to split it as 1 and then 9 similry for more than 10 numbers.
So RAVI KUMAR is dividng 19/10.. you will get quotient as 1 so display it then divide the number (19) by 10 ang get the remainder i.e., 9 so display it..
So to convert the decimal numbers to ASCII you have to add 48 or 30h as LCD recieves only ASCII Characters.

Similar procedure for 100,1000 numbers.

hope this would help you
 
If i want to display 4 digits in LCD? how can i do that?
 

Something like this. 48 dec = 0x30

Code:
string[0] = (temp/1000) + 48;
                string[1] = (temp/100)%10 + 48;
                string[2] = (temp/10)%10 + 48;
                string[3] = (temp/1)%10 + 48;
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top