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

printf and atof

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 13, 2006 11:59 am     Reply with quote

Here's a demo program for the PicDem2-Plus that works.

Use the "Flex_lcd.c" driver that you can get from here. It's already
configured to work with a PicDem2-Plus.
http://www.ccsinfo.com/forum/viewtopic.php?t=24661

This program reads the value of the trimpot, converts it to volts,
and displays it on the LCD on the PicDem2-Plus board. I tested
this with PCM vs. 3.249 and it works OK.

I also installed your version, 3.163, and it works with that one too.
For your version, the "AN0" constant doesn't exist. Use the RA0_ANALOG
constant instead. (They're the same thing).

Change this line
Code:
setup_adc_ports(AN0);

to this:
Code:
setup_adc_ports(RA0_ANALOG);

Then it will compile with vs. 3.163.

Code:

#include <16F877.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include "flex_lcd.c"

//============================
void main()
{
int16 adc_value;
float volts;
 
lcd_init();

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);

while(1)
  {
   adc_value = read_adc();
   volts = (float)(adc_value * 5)/1023.0;   
   printf(lcd_putc, "\f%3.2f", volts);
   delay_ms(500);
  }
}
Ttelmah
Guest







PostPosted: Mon Nov 13, 2006 3:29 pm     Reply with quote

The answer to the array size, is simple. A _string_, always needs one more character than the number in the text, for the '\0' terminator character.

Best Wishes
new2ccs



Joined: 29 Oct 2006
Posts: 10

View user's profile Send private message

PostPosted: Tue Nov 14, 2006 9:58 am     Reply with quote

thanks for the code, but suddenly my program works now. Maybe I changed the line in my loop from i =16 after the if statement to BREAK;
Code:
void display(char arr[])
{
   int i;
   
   for( i = 0; i <16; i++ )
   {
      if( arr[i] == '\0')   
         break;
      else
        lcd_write_data(1,arr[i]);
      
   }


}
new2ccs



Joined: 29 Oct 2006
Posts: 10

View user's profile Send private message

address lines picdem 2+
PostPosted: Wed Nov 15, 2006 3:39 pm     Reply with quote

I have a question about the address lines of the LCD. In the data sheet of hd44780U says line 2 = 0x40 and line 1 = 0X00, but when debugging the flex.c code. i notice that line 1 = 0xff and line 2 =0xbf. Why not line 1 = 00 and line 2 =40.

HD44780U
00 01 02 03 04 05 06 07 08 09 0A 0B0C0D0E 27
40 41 42 43 44 45 46 47 48 49 4A 4B4C4D4E 4F
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 15, 2006 3:47 pm     Reply with quote

Quote:
when debugging the flex.c code. i notice that line 1 = 0xff and line 2 =0xbf

In the lcd_gotoxy() function, it sets the address to 0x00 for line 1
and to 0x40 for line 2.
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