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 driver

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



Joined: 18 Feb 2012
Posts: 3

View user's profile Send private message Send e-mail

LCD driver
PostPosted: Tue Apr 03, 2012 6:30 am     Reply with quote

I am using PIC 16F887 and CCS-C compiler(version 4.093) plugin in MPLAB IDE. I've connected LCD to port D and it is working. I am using LCD.C driver to implement lcd functions in which LCD is configured as port access. Now i want to use pin 5 of port d for PWM (half bridge mode) which is already being used as LCD data pin. How do I change LCD data pin in driver ? What changes should I make in LCD.C in order to use pin D5 for PWM or to configure LCD using pin access ? I am not using pin D3. If I could use pin D3 for lcd data, can I use pin D5 for pwm ? How to do this ? I've attached LCD driver file and my code.

hardware connection details
port D
pin d0 connected to LCD enable
pin d1 connected to LCD RS
pin d2 connected to LCD R/W
pin d3 NOT USED
pin d4 connected to LCD data pin 4
pin d5 connected to LCD data pin 5
pin d6 connected to LCD data pin 6
pin d7 connected to LCD data pin 7


Code:

[b]LCD driver[/b]
///////////////////////////////////////////////////////////////////////////////
////                             LCD.C                                     ////
////                 Driver for common LCD modules                         ////

Driver code deleted.



++++++++++++++++++++++
CCS lcd driver code removed.

Reason: Forum rule #10:

10. Don't post the CCS example code or drivers.

Forum rules -
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
++++++++++++++++++++++

Code:

#include <16f887.h>
#device ADC=10
#use delay(clock=16000000)   
#fuses HS, NOWDT, NOPROTECT, NOLVP       
#use RS232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#include <lcd.c>
       
       int16 temp_adc1;
       float temp1;
       int16 temp_adc2;
       float temp2;

       int16 volt_adc1;
       float volt1;
       int16 volt_adc2;
       float volt2;
     
       
       int16 crnt_adc1;
       float crnt1;
       int16 crnt_adc2;
       float crnt2;

       long pwmv_adc1;

 void main()
 {
 lcd_init();
 setup_adc(ADC_CLOCK_DIV_32);

while(1)
 {
        printf ( lcd_putc, "Battery Status\n" );
        delay_ms(100);                            //print to lcd  --- clear LCD ---  lcd_putc("\f");
        printf ("Battery Status vasanth\n\r" );  //print to serial com
        delay_ms(100);
       
        //temperature measurement   
         
         set_adc_channel(0); //read analog input from channel 0
         delay_ms(10);
         temp_adc1 = read_adc();
         temp1 = 5.00*temp_adc1*100.00/1023.00; // = temp_adc*0.48828125;
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)temp1);
         delay_ms (100);                   // printf(lcd_putc, "value = %lu \n",value);
         lcd_putc(223);                     //this number 223 will display the degree sign
         delay_ms (100);
         lcd_putc('C');
         delay_ms (10);
         lcd_putc("  b1_temp");
         delay_ms(100);
         
         printf ("\n");
         delay_ms (100);
         printf ("%5.1f", (float)temp1);
         delay_ms (100);
         putc(223);
         putc('C');
         delay_ms (100);
         puts("  b1_temp");
         delay_ms (10);
         printf ("\n\r");
         delay_ms(100);
         
         set_adc_channel(1); //read analog input from channel 1
         delay_ms(10);
         temp_adc2 = read_adc();
         temp2 = temp_adc2*0.48828125;
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)temp2);
         delay_ms (100);
         lcd_putc(223);      //this number 223 will display the degree sign
         delay_ms (100);
         lcd_putc('C');
         delay_ms (100);
         lcd_putc("  b2_temp");
         delay_ms(100);
       
         printf ("%5.1f", (float)temp2);
         delay_ms (100);
         putc(223);
         putc('C');
         delay_ms (100);
         puts("  b2_temp");
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);
         
        //voltage measrement
       
         set_adc_channel(2); //read analog input from channel 2
         delay_ms(10);
         volt_adc1 = read_adc();
         volt1 = (volt_adc1*0.0048875855)+9;//(volt*5)/1023

         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)volt1);
         delay_ms (100);
         lcd_putc('V');
         delay_ms (100);
         lcd_putc("  b1_volt");
         delay_ms(1000);
         
         printf ("%5.1f", (float)volt1);
         delay_ms (100);
         putc('V');
         delay_ms (100);
         puts("  b1_volt");
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);
         if(volt1<=10.5)
         output_high(PIN_B2);
         else
         output_low(PIN_B2);
         
         set_adc_channel(5); //read analog input from channel 5
         delay_ms(10);
         volt_adc2 = read_adc();
         volt2 = (volt_adc2*0.0048875855)+9;//(volt*5)/1023
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)volt2);
         delay_ms (100);
         lcd_putc('V');
         delay_ms (100);
         lcd_putc("  b2_volt");
         delay_ms(100);
         
         printf ("%5.1f", (float)volt2);
         delay_ms (100);
         putc('V');
         delay_ms (100);
         puts("  b2_volt");
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);
         if(volt2<=10.5)
         output_high(PIN_B3);
         else
         output_low(PIN_B3);
         
        // current measurement

         set_adc_channel(3); //read analog input from channel 3
         delay_ms(10);
         crnt_adc1 = read_adc();
         crnt1 = crnt_adc1*0.0048875855;//(volt*5)/1023
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)crnt1);
         delay_ms (100);
         lcd_putc('A');
         delay_ms (100);
         lcd_putc("  b1_crnt");
         delay_ms(100);
         
         printf ("%5.1f", (float)crnt1);
         delay_ms (100);
         putc('A');
         delay_ms (100);
         puts("  b1_crnt");
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);

         set_adc_channel(6); //read analog input from channel 6
         delay_ms(10);
         crnt_adc2 = read_adc();
         crnt2 = crnt_adc2*0.0048875855;//(volt*5)/1023
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"%5.1f", (float)crnt2);
         delay_ms (100);
         lcd_putc('A');
         delay_ms (100);
         lcd_putc("  b2_crnt");
         delay_ms(100);
         
         printf ("%5.1f", (float)crnt2);
         delay_ms (100);
         putc('A');
         delay_ms (100);
         puts("  b2_crnt");
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);
       
 
        //pwm value
       
       /*set_adc_channel(4); //read analog input from channel 4
         delay_ms(10);       
         set_tris_c(0xff);
         pwmv_adc1 = read_adc();
         lcd_gotoxy(1,2);
         printf ( lcd_putc,"pwm_v= %lu",pwmv_adc1);// or set adc=8 and get using %x for int8 pwmv_adc1
         delay_ms(100);
         setup_ccp1(CCP_PWM);         
         setup_timer_2(T2_DIV_BY_4,255,16);
         set_tris_c(0x00);
         set_pwm1_duty(pwmv_adc1);  //Change the duty cycle
         delay_ms(100);
         
         printf ("  pwm_v = %lu",pwmv_adc1);
         delay_ms (100);
         printf ("\n\r");
         delay_ms(50);*/   
}
}
temtronic



Joined: 01 Jul 2010
Posts: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Apr 03, 2012 6:56 am     Reply with quote

quickest,easiest solution...
..download the 'flex_lcd' driver from the code library...
It allows you to setup almost any PIC I/O pin for LCD use.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

LCD driver
PostPosted: Tue Apr 03, 2012 8:23 am     Reply with quote

Or you could configure LCD bits as:-

pin d0 connected to LCD data pin 4
pin d1 connected to LCD data pin 5
pin d2 connected to LCD data pin 6
pin d3 connected to LCD data pin 7

pin d4 connected to LCD enable
pin d5 NOT USED
pin d6 connected to LCD RS
pin d7 connected to LCD R/W

You've now made d5 free for the pwm, and you're keeping the data pins together as a nibble.

You'll should only have to change the structure definition, pin I/O maps, and code where you handle data.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 03, 2012 4:07 pm     Reply with quote

Quote:
void main()
{
lcd_init();
setup_adc(ADC_CLOCK_DIV_32);

You left out the line for setup_adc_ports(). You need it, so you can
specify which i/o pin should be enabled for Analog Input. Look in the
16F887.h file for a list of suitable parameters (sAN0, sAN1, etc.).
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