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 CCS Technical Support

LCD problem / help

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



Joined: 14 Nov 2005
Posts: 2
Location: KOREA

View user's profile Send private message

LCD problem / help
PostPosted: Tue Nov 15, 2005 12:44 am     Reply with quote

Hello, I want to print sum(type double) on LCD display.

device : 16F874
use 8LINES
LCD 16x2

This is my source code.

Code:
#include <C:\Program Files\PICC\Devices\16f874.h>
#use delay(clock=4000000)

struct lcd_pin_map{
         boolean enable;      // lcd enable signal
         boolean rs;          // lcd register select signal
         boolean rw;          // lcd read/write signal
       } lcd_control;

#byte lcd_control = 5         
#byte portb = 6               



void BusyCheck(){
      do{
      portb = 0x00;
      set_tris_b(0xff);
      lcd_control.rs = 0;

      delay_cycles(1);
      lcd_control.rw = 1;
      delay_cycles(1);
      lcd_control.enable = 1;
      delay_cycles(2);
      lcd_control.enable = 0;
      } while(bit_test(portb,7));
                             
      lcd_control.enable = 0;
      portb = 0x00;
      return;
}


void SendChar(char bf){
      BusyCheck();
      set_tris_b(0x00);
      portb = bf;
      lcd_control.rw = 0;
      lcd_control.rs = 1;
      delay_cycles(1);
      lcd_control.enable = 1;
      delay_cycles(1);
      lcd_control.enable = 0;
      return;
}


void SendCmd(char cmd){
      BusyCheck();
      set_tris_b(0x00);
      portb = cmd;
      lcd_control.rw = 0;
      lcd_control.rs = 0;
      delay_cycles(1);
      lcd_control.enable = 1;
      delay_cycles(1);
      lcd_control.enable = 0;
      return;
}



void lcd_init(){
      setup_adc_ports(no_analogs);
      set_tris_b(0x00);
      set_tris_a(0x00);

      lcd_control = 0x00;
      portb = 0x00;

      portb = 0b00111000;     
      delay_cycles(1);
      lcd_control.enable = 1;
      delay_cycles(1);
      lcd_control.enable = 0;
      delay_ms(15);

      portb = 0b00111000;   
      delay_cycles(1);
      lcd_control.enable = 1;
      delay_cycles(1);
      lcd_control.enable = 0;
      delay_ms(1);

      SendCmd(0b00001110);    // disply on/off control
      SendCmd(0b00000110);    // entry mode set
      SendCmd(0b00000001);    // clear display
      SendCmd(0b00000010);    // return home
      return;
}



void gotoxy(int x, int y)
{
      int address;
      if(x>=16) x = 0;
      if(y!=1)
            address = 0x80;   
      else
            address = 0xc0;
      SendCmd(address + x);
}


void main(){

      double sum;
      sum = 10000;

      lcd_init();

      while(1){
         gotoxy(0,0);         
         SendChar("MATH SUM");
         gotoxy(5,1);         
         SendChar(sum);  <<==== This is my problem   :cry:  :question:
      }
}


I know SendChar("10000");
Is there another way to print sum on LCD?
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Nov 15, 2005 12:52 am     Reply with quote

Code:
void main(){

      double sum;
      sum = 10000;

      lcd_init();

      while(1){
         gotoxy(0,0);         
         printf(SendChar, "MATH SUM");
         gotoxy(5,1);         
         printf(SendChar, "%d", sum);
      }
}

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah
Guest







PostPosted: Tue Nov 15, 2005 3:49 am     Reply with quote

First, CCS, does not support a 'double' data type. It accepts the keyword, and stores a 4byte float, for this 'type', but this is a bodge to avoid complaints when porting code. Safer to use one of the types that is documented as supported.
Given this variable then holds a float, the printf % statement to display it, should use %f, or %g (to give different rounding behaviour).
Given that you are only holding integers, better to use either an int16, or an int32. The printf format for these is %Ld (not %d, which only handles single 'byte' integers).

Best Wishes
SungYong



Joined: 14 Nov 2005
Posts: 2
Location: KOREA

View user's profile Send private message

PostPosted: Tue Nov 15, 2005 4:20 am     Reply with quote

Thank you so much!! Razz
Now I can print~ Smile
Thanks again.
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