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.

need help with logic

Status
Not open for further replies.

hemnath

Advanced Member level 3
Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Visit site
Activity points
6,589
Using, PIC 18F2520, CCS C Compiler, 6.144 Mhz crystal,

unsigned char UNITS[7][16] = {"PRESSURE ", "TEMPERATURE ", "LEVEL ", "VOLUME ", "FLOW ", "FREQUENCY ", "PERCENTAGE "};

unsigned char PRESSURE[9][16] = { "BAR ", "mbar ", "psi ", "KSC ", "cmWC ", "mmWC ", "inWC ", "KPa ", "Mpa "};

like this i have declared many variables, for temperature, level, volume, flow, frequency, percentage....

void main()
{
while(1)
{
if(button_pressed)
{
i++;
printf(lcd_data,"%s",units);// print the string on LCD
// conditional checking and printing the string.
}
}
}

Above shown is sample program. When i declared like this, my RAM memory gets 90%. Is there any other possible methods to print the string on LCD.
Tried using switch, but the program very large.

need help.
Thanks in advance:)
 

Try putting the word 'const' before 'unsigned char' in the UNITS and PRESSURE definitions. It should tell the compiler that these are fixed values rather than variables and hopefully it will put them in program space instead of RAM.

Brian.
 
again, I'm back with some problem.

I'm using 16 x 1 LCD Display. Please check the below program. Display shows some random characters with trial.
HTML:
#include "18F2520.h"
#fuses HS
#use delay(clock = 6144000)

#define RS PIN_A2
#define EN PIN_A1

void lcd_init();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);

const char data[1][8] = {"trial   "};						 

void main()
{
	signed int i;
	lcd_init();
 	i = 5;
	while(1)
	{	
		lcd_cmd(0x80);
		printf(lcd_data, "%s %d", data[0],i);
	}
}

void lcd_init()
{
   lcd_cmd(0x30);      // Configure the LCD in 8-bit mode, 1 line and 5x7 font
   //lcd_cmd(0x28);
   lcd_cmd(0x0c);      // display on and cursor off
   lcd_cmd(0x01);      // clear display screen
   lcd_cmd(0x06);      // increment cursor
   lcd_cmd(0x80);      // set cursor to 1st line
}

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);
}

Please help .

- - - Updated - - -

Attached is the display characters.
 

Attachments

  • LCD.bmp
    867.7 KB · Views: 84

Without the CCS compiler I can't verify your code but I think the problem lies with the way you pass characters in the 'printf' function. The display suggests there is no terminator after the 'i' variable so it continued passing information to the LCD until it came across a zero (the usual terminator) somewhere further along the memory from where 'i' was stored. At the moment you also pass unsigned chars to the routine but 'i' is a signed number although I wouldn't expect that to produce those symptoms.

These are things to try:
1. change "printf(lcd_data, "%s %d", data[0],i);" to "printf(lcd_data, "%s %d\0", data[0],i);" which forces a zero after 'i'.

if that doesn't work:
2. add a new variable "char LCD_String[20] = {0};" then change the line to "sprintf(LCD_String,"%s %d", data[0],i);" followed by "printf(lcd_data, "%s",LCD_String);".

That "sprintf's" the entire line into a character string and copies it to the LCD in one go.

Brian.
 

Thanks betwixt for your suggestion.
I tried what you have said.
1. First, i tried your 1st point. Result: The problem remains the same.

2. Now i tried your 2nd point. Result: In LCD, it displays only 5 at position 0x80.
 

OK, let's break the problem down into manageable size. Using the second solution, can you use the debugger to view the contents of "LCD_String" and tell me what it contains. I'm trying to work out whether the wrong information is being passed to the LCD or whether the LCD routine isn't displaying it properly.

Brian.
 

try const char data[1][9] = {"trial "};

to leave room for the string terminator
 
hi betwixt,
Sorry for the late reply.

I used MPLAB Proteus VSM debugger to view the content in the LCd_string. Below is the attached image. Please look into it.

hi kam1787,
I tried as you suggested, and it works perfectly.

Thank you guys for your great help.
 

Attachments

  • LCD.bmp
    507 KB · Views: 78

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top