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

potentiometer and lcd 2x16 problem...

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







potentiometer and lcd 2x16 problem...
PostPosted: Fri Mar 20, 2009 7:32 am     Reply with quote

How can I show the value of potentiometer? The output of potentiometer is connect directly to pin2 (RA0/AN0) Pic16F877. PortD is use for LCD DB4-DB7,RS,EN. PortB is for LED and Buzzer. Below is the code but it doesn't work. Why??
Code:

#include<16F877A.h>
#device ADC=8
#fuses XT,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#include<LCD.C>

#define LCD_EN          PIN_D0     //lcd pin 6
#define LCD_RS          PIN_D1      //lcd pin 4
#define LCD_RW          PIN_D2     //lcd pin 5

#define LCD_D4          PIN_D4   //lcd pin 11
#define LCD_D5          PIN_D5   //lcd pin 12
#define LCD_D6          PIN_D6   //lcd pin 13
#define LCD_D7          PIN_D7   //lcd pin 14

#define LED_BUZZER      PIN_B7
#define LED_GREEN       PIN_B6
#define LED_YELLOW      PIN_B5
#define LED_RED         PIN_B4


void main(){

set_tris_a(0xff);
set_tris_b(0x00);
set_tris_d(0x00);

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);

do{
int8 valuepot;
set_adc_channel(0);
delay_ms(50);
valuepot=read_adc();
delay_ms(50);
lcd_init();
}

while(1);
{
float mvpb;
float result;
int8 valuepot;
mvpb=30.5/255.0;
delay_ms(100);
lcd_gotoxy(1,1);
valuepot=input_A();
result=valuepot*mvpb-16.5;

if((result>=5)&&(result<=16.5))
{
   printf(lcd_putc,"Weight:%5.2f kg\n",result);
   lcd_putc("*****TANK:OK******");

            output_low(PIN_B7);
            output_low(PIN_B5);
            output_low(PIN_B4);
     output_high(PIN_B6);
      }

      else if((result>=3)&&(result<5))
      {
      printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("*****TANK:LOW*****");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B4);
     output_high(PIN_B5);
      }

      else if((result>=1)&&(result<3))
      {
      printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("**TANK:VERY LOW*****");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B4);
     output_high(PIN_B5);
delay_ms(100);
      output_low(PIN_B5);
      }

      else if((result>=0)&&(result<=1))
      {
       printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("TANK:REPLACE NOW");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B5);
     output_high(PIN_B4);
      }

      else
      {
       printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("**SORRY!!EMPTY**");
            output_high(PIN_B7);
            output_high(PIN_B6);
            output_high(PIN_B5);
            output_high(PIN_B4);
delay_ms(100);
            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B5);
            output_low(PIN_B4);
      delay_ms(100);
      }
      delay_ms(1000);
}
 }

Anybody plzzz help me...
Ttelmah
Guest







PostPosted: Fri Mar 20, 2009 8:14 am     Reply with quote

I'll make two comments:
1) Switch to C variable declarations. Only declare variables at the start of a named function. The ability to declare variables inside 'sections', is a latter construct, and though CCS 'supposedly' supports this, it gains nothing, and quite often leads to problems....
2) Think through your constructs.
Code:

Do {

} while(TRUE);

executes _for ever_. How is any code after this going to run?.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 20, 2009 10:29 am     Reply with quote

Here is a test program to read a trimpot on pin AN0 and display the
voltage on an LCD. Try this program first. It will show if your hardware
is working OK:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
MrGreen
Guest







:-/
PostPosted: Sat Mar 21, 2009 8:08 am     Reply with quote

i still dont get it...anybody plzz help me ...
picoman



Joined: 17 May 2009
Posts: 1

View user's profile Send private message

Re: potentiometer and lcd 2x16 problem...
PostPosted: Sun May 17, 2009 7:27 am     Reply with quote

Code:

#include<16F877A.h>
#device ADC=8
#fuses XT,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#include<LCD.C>

#define LCD_EN          PIN_D0     //lcd pin 6
#define LCD_RS          PIN_D1      //lcd pin 4
#define LCD_RW          PIN_D2     //lcd pin 5

#define LCD_D4          PIN_D4   //lcd pin 11
#define LCD_D5          PIN_D5   //lcd pin 12
#define LCD_D6          PIN_D6   //lcd pin 13
#define LCD_D7          PIN_D7   //lcd pin 14

#define LED_BUZZER      PIN_B7
#define LED_GREEN       PIN_B6
#define LED_YELLOW      PIN_B5
#define LED_RED         PIN_B4


void main(){

set_tris_a(0xff);
set_tris_b(0x00);
set_tris_d(0x00);

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);

do{
int8 valuepot;
set_adc_channel(0);
delay_ms(50);
valuepot=read_adc();
delay_ms(50);
lcd_init();
}

while(1);
{
float mvpb;
float result;
int8 valuepot;
mvpb=30.5/255.0;
delay_ms(100);
lcd_gotoxy(1,1);
valuepot=input_A();
result=valuepot*mvpb-16.5;

if((result>=5)&&(result<=16.5))
{
   printf(lcd_putc,"Weight:%5.2f kg\n",result);
   lcd_putc("*****TANK:OK******");

            output_low(PIN_B7);
            output_low(PIN_B5);
            output_low(PIN_B4);
     output_high(PIN_B6);
      }

      else if((result>=3)&&(result<5))
      {
      printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("*****TANK:LOW*****");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B4);
     output_high(PIN_B5);
      }

      else if((result>=1)&&(result<3))
      {
      printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("**TANK:VERY LOW*****");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B4);
     output_high(PIN_B5);
delay_ms(100);
      output_low(PIN_B5);
      }

      else if((result>=0)&&(result<=1))
      {
       printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("TANK:REPLACE NOW");

            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B5);
     output_high(PIN_B4);
      }

      else
      {
       printf(lcd_putc,"Weight:%5.2f kg\n",result);
      lcd_putc("**SORRY!!EMPTY**");
            output_high(PIN_B7);
            output_high(PIN_B6);
            output_high(PIN_B5);
            output_high(PIN_B4);
delay_ms(100);
            output_low(PIN_B7);
            output_low(PIN_B6);
            output_low(PIN_B5);
            output_low(PIN_B4);
      delay_ms(100);
      }
      delay_ms(1000);
}
 }


Is very interesting this application.
I want to that realize this application but with load cells weight and d'not know how calibrate this .
Please, dear friend what is reprezent mvpb=30.5 / 255.0 and 16.5 value ?
Thank you very much!
Mirel
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