CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Hello im newbie,need a bit help to simple write in my LCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

Hello im newbie,need a bit help to simple write in my LCD
PostPosted: Wed Jan 11, 2012 8:33 am     Reply with quote

Hello, i have PIC18F2550 and i want to write in my LCD , the string "hello world", i found some tutorials and i code this:

Code:
#include <18f2550.h>
#use delay(clock=20M)

#include <lcd.c>
#define LCD_ENABLE_PIN  PIN_RB0                                   
#define LCD_RS_PIN      PIN_RB1                                   
#define LCD_RW_PIN      PIN_RB2                                   
#define LCD_DATA4       PIN_RB3                                   
#define LCD_DATA5       PIN_RB4                                   
#define LCD_DATA6       PIN_RB5                                   
#define LCD_DATA7       PIN_RB6


void main()
{
   lcd_init();
   lcd_gotoxy(1,1);
   lcd_putc("Hello world");
}

But on my LCD I only see this:
[][][][][][][][][][][][] ( full black rectangles in all LCD chars)

It sounds like LCD is doing init, but isn't sending the string.

Can you help me there??
Thanks,
Chaud
Ttelmah



Joined: 11 Mar 2010
Posts: 19341

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 8:59 am     Reply with quote

The LCD PIN definitions need to be _before_ of LCD.C. Otherwise it'll use it's default pins......
The block display is what you get 'by default' from the LCD, with no communication at all.

Best Wishes
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 9:04 am     Reply with quote

Ttelmah wrote:
The LCD PIN definitions need to be _before_ of LCD.C. Otherwise it'll use it's default pins......
The block display is what you get 'by default' from the LCD, with no communication at all.

Best Wishes


Hmm I see, I did it but know I get 40+ errors, all things like this:

"Undefined identifier PIN_RB6" etc etc for all pins

Aren't they identified already??
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

Re: Hello im newbie,need a bit help to simple write in my LC
PostPosted: Wed Jan 11, 2012 9:15 am     Reply with quote

Chaud wrote:
Hello, i have PIC18F2550 and i want to write in my LCD , the string "hello world", i found some tutorials and i code this:

Code:
#include <18f2550.h>
#use delay(clock=20M)

#include <lcd.c>
#define LCD_ENABLE_PIN  PIN_RB0                                   
#define LCD_RS_PIN      PIN_RB1                                   
#define LCD_RW_PIN      PIN_RB2                                   
#define LCD_DATA4       PIN_RB3                                   
#define LCD_DATA5       PIN_RB4                                   
#define LCD_DATA6       PIN_RB5                                   
#define LCD_DATA7       PIN_RB6


void main()
{
   lcd_init();
   lcd_gotoxy(1,1);
   lcd_putc("Hello world");
}

But on my LCD I only see this:
[][][][][][][][][][][][] ( full black rectangles in all LCD chars)

It sounds like LCD is doing init, but isn't sending the string.

Can you help me there??
Thanks,
Chaud


use this
Code:

 #define enable  PIN_RB0     
#define rs      PIN_RB1     
#define  rw      PIN_RB2
#define D4       PIN_RB3   
#define D5       PIN_RB4
#define D6       PIN_RB5   
#define D7       PIN_RB6

hope help u
_________________
sahu
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

Re: Hello im newbie,need a bit help to simple write in my LC
PostPosted: Wed Jan 11, 2012 9:17 am     Reply with quote

sahu77 wrote:

use this
Code:

 #define enable  PIN_RB0     
#define rs      PIN_RB1     
#define  rw      PIN_RB2
#define D4       PIN_RB3   
#define D5       PIN_RB4
#define D6       PIN_RB5   
#define D7       PIN_RB6

hope help u



got same errors,they are located in "lcd.c"
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 9:38 am     Reply with quote

Porblem was i need to write PIN_Bx isntead of PIN_RBx, thanks for help , problem solved
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 9:51 am     Reply with quote

any1 know how to print "int values" with lcd_putc??

im doing this:

lcd_putc("Volts: %f", value);

And i get "Expecting a close paren" error
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 10:13 am     Reply with quote

Chaud wrote:
any1 know how to print "int values" with lcd_putc??

im doing this:

lcd_putc("Volts: %f", value);

And i get "Expecting a close paren" error


use this
Code:
      lcd_gotoxy(1,1);
      printf ( lcd_putc,"Volts  ""%lu ",value);   

_________________
sahu
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 10:38 am     Reply with quote

Yeah it works, im doing a digital A/D converter, with ADC=8 bits

8 bits = 255 decimal
so
1= 0,019 V
255 = 5V


and i use this
value = read_Adc();
volts = 0.019 * value;

but to write on LCD, he only write decimal number

example, conversion = 4,995 volts
LCD screen = 4

with your code-> printf ( lcd_putc,"Volts ""%lu ",volts);

How can i print all numbers? and do you where i can see all sintaxes? like %lu

Thanks for help
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 10:56 am     Reply with quote

Chaud wrote:
Yeah it works, im doing a digital A/D converter, with ADC=8 bits

8 bits = 255 decimal
so
1= 0,019 V
255 = 5V


and i use this
value = read_Adc();
volts = 0.019 * value;

but to write on LCD, he only write decimal number

example, conversion = 4,995 volts
LCD screen = 4

with your code-> printf ( lcd_putc,"Volts ""%lu ",volts);

How can i print all numbers? and do you where i can see all sintaxes? like %lu

Thanks for help

what u want display ,
example, conversion = 4.995 volts or
conversion = 49.95 volts or
conversion = 499.5 volts or
conversion = 4995 volts
_________________
sahu
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:03 am     Reply with quote

I want to display "4,995 volts" can you explain how I do it??
And one more simple question, is there a command to clean all info from lcd??
Code:

 while(1)
  {
  value = read_Adc();
  lcd_gotoxy(1,1);
  printf ( lcd_putc,"");
  lcd_gotoxy(1,1);
  printf ( lcd_putc,"%lu ""Volts",value);
  }

I'm using lcd_putc(""), but for example if it goes from 100 to 99, it appears "100 volts" to "99 voltss" with double "s".

Thanks for all help
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:15 am     Reply with quote

OK now change in your code as ....

Code:

/*******************************************************
 ADC Defines
 *******************************************************/
#bit ADFM = 0x1F.7      // A/D Result Formed Select bit
            // 0=Left Justified, 1=Right Justified
#define ADC_AVERAGE_COUNT 10     // # of times to average ADC_Value
#define ADC_DELAY 1              // Change to "1" for 1 ms
#define ADC_2TAD 1               // Wait 1 ms for 2TAD to complete before doing another AD conversion.

int16 getchreading(int channel)
{
       int32 tlong;
        int1 done; // Put local variable at beginning of code block
        int x; // Number of times to average ADC value
        int16 temp_result, adc_value;

        set_adc_channel(channel); // Select Channel

        // Average ADC value
        temp_result = 0;
        for (x=1; x<=ADC_AVERAGE_COUNT; x++)
        {
                delay_us(ADC_DELAY); //Charge capacitor
                read_adc(ADC_START_ONLY); //Do A/D conversion

                done == adc_done();

                while(!done) {
                done = adc_done();
                }

                temp_result += read_adc(); // Read A/D register . Pin A0 in an input
                delay_ms(ADC_2TAD); // Wait 2 TADs before doing another A/D conversion
        }

        adc_value = temp_result / ADC_AVERAGE_COUNT;
       tlong = (int32)ADC_value*6000/255; //1023;
       return (int32) tlong;
 }

void Process_display(void)
{
  int16 volt ;
    ch_0 = getchreading(0); // ch_0 mens AN0
    involts =(int16) ch_0 / 1000
      lcd_gotoxy(1,1);
      printf ( lcd_putc,"Volts  ""%lu ",volt); 

hope help, now solve your problem ? or anything rest ?
_________________
sahu
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 11:26 am     Reply with quote

Chaud wrote:


with ADC=8 bits

8 bits = 255 decimal
so
1= 0,019 V
255 = 5V


No, not quite right. 256 is 5V, not 255. So 1 bit is 0.0194549560546875V. That's way too precise for float maths however, so call it 19.45mV per bit. In general for unipolar ADCs the resolution is Vref/2^Bits and the range in volts is 0 to (2^Bits - 1) * resolution. Vin = Vref is overrange, not just Vin > Vref. Put another way the range is zero to one bit's worth less than the reference voltage.

I normally do all this in #defines so that I don't calculate the conversions, the compiler does it for me. If I change from 10 to 12 bit ADCs all I do is change one constant, from 1024 to 4096, everything else tracks that change automatically. I include analogue gains and that sort of thing. Here's one from one of my projects:

Code:

#define ADC_COUNTS         1024          // 10 bits unipolar

// The volts per dB is fixed and well defined. Its
// derived from the -22mv per dB of the log detector multiplied by
// the analogue gain, i.e. -3.
#define VOLTS_PER_DB       -.022f          // -22mV/dB
#define GAIN                     -3.0f                // * -3 analogue gain
#define DB_PER_BIT         ((ADC_VREF / ADC_COUNTS) / (VOLTS_PER_DB * GAIN) )



This is a very common mistake, and I see quite experienced embedded engineers making it too. It makes a very small, insignificant error at 8 bits. A small error at ten bits that might cause trouble, and if you are going for 12 bits and more you should get it right! Why not get it right now and you're much more likely to keep on getting it right.

RF Developer
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group