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

Why this lcd and adc code not working?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jayanthd



Joined: 06 Dec 2012
Posts: 47
Location: Banned - pirate

View user's profile Send private message

Why this lcd and adc code not working?
PostPosted: Wed Mar 20, 2013 11:47 am     Reply with quote

Here is my CCS C code for PIC16F877 device. If I try to include 16F877.h file it gives error while compiling. I have used the Project Wizard to create the project. I am testing on real hardware.

Code:
#include <main.h>
  #include <ctype.h>
  #include <float.h>
  #include <math.h>
  #include <stdio.h>
  #include <stddef.h>
  #include <stdlib.h>
  #include <string.h>
#use delay(clock=20000000)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading

#define LCD_ENABLE_PIN  PIN_B2                                    ////
#define LCD_RS_PIN      PIN_B0                                    ////
#define LCD_RW_PIN      PIN_B1                                    ////
#define LCD_DATA4       PIN_B3                                    ////
#define LCD_DATA5       PIN_B4                                    ////
#define LCD_DATA6       PIN_B5                                    ////
#define LCD_DATA7       PIN_B6

#include <lcd.c>


void main()
{
   float voltage = 0;
   
   set_tris_a(0b11111111);
   set_tris_b(0b00000000);
   setup_adc(ADC_CLOCK_INTERNAL);

   setup_adc_ports(ALL_ANALOG);
   lcd_init();
   delay_ms(250);
   lcd_putc("\fReady...\n");
   lcd_gotoxy(1,1);
   printf(lcd_putc,"ADC Example");
   lcd_gotoxy(1,2);
   delay_ms(2000);
   set_adc_channel(0);
   delay_us(20);
   
   while(TRUE)
   {
     voltage=read_adc();
     delay_us(50);
     printf(lcd_putc,"%lu",voltage);
   }

}
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 12:03 pm     Reply with quote

First line of your program should be the processor type, which is not shown in the program you've posted.

You don't say what the error is ! Very hard to diagnose without it.

aside from that several minor details

1) you've included a lot of unnesceeary headers...
2) never use adc_clock_internal.read the ADC section in the datasheet
3) always add 'errors' to the use rs232(...options...)
4) always select PUT, not NOPUT
5) always delay 1000ms before and after doing lcd_init()
6) do not use set_tris.(...) functions, let compiler do it for you
7) change delay in loop to 1 second( LCDs are slow !!)


hth
jay
jayanthd



Joined: 06 Dec 2012
Posts: 47
Location: Banned - pirate

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 12:28 pm     Reply with quote

temtronic wrote:
First line of your program should be the processor type, which is not shown in the program you've posted.

You don't say what the error is ! Very hard to diagnose without it.

aside from that several minor details

1) you've included a lot of unnesceeary headers...
2) never use adc_clock_internal.read the ADC section in the datasheet
3) always add 'errors' to the use rs232(...options...)
4) always select PUT, not NOPUT
5) always delay 1000ms before and after doing lcd_init()
6) do not use set_tris.(...) functions, let compiler do it for you
7) change delay in loop to 1 second( LCDs are slow !!)


hth
jay


Thank you for quick reply. The device header is included in the main.h file. The problem is LCD displays nothing and hence I don't know whether adc is working or not. Here is my project files. Please check it.
http://uppit.com/rq17uzztj382/adc.rar
temtronic



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

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 1:13 pm     Reply with quote

Sorry but your link goes to a site that wants me to download some 'toolbar' and I'm not going to do that.
For small programs like yours, it's best to put the main.h code into main.c,typically it's only 4-10 lines of 'setup'.

At first you said compiling gave an error, now you say the LCD doesn't work....

Typically LCD modules 'don't work' for
1) wrong bias voltage on Vee(typically .6 V should produce black squares)

2) wrong pin designations,those must be before the driver is loaded,unless you're using the defaults listed within the driver

3) Vcc not 5 volts. Seems 99.999% of LCD modules are 5 volt and won't run if tied to 3 volt PICs.


Also noticed...
You've defined 'voltage' to be a float yet print it out as a long unsigned integer. Since read_adc() sends either 8 bit or 10 bit data, 'voltage' should be either an Unsigned INT8 or Unsigned INT16.


hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 1:34 pm     Reply with quote

As a general comment, the order of things in CCS should always be:

Processor definition or the include file containing this.
Fuses
Clock definition
Serial definition if used
Other includes

Some parts of many include files (stdio for example), _require_ the RS232 definitions first. Similarly anything using delays, required the clock definitions first.

In the case given, most of the includes are not being used, so it won't cause a problem, but for any future project it _will_.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Mar 20, 2013 2:07 pm     Reply with quote

Can you post the schematic??

Just in case there is a wiring mistake?
( we all make them from time 2 time ) Very Happy Very Happy Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 3:25 pm     Reply with quote

and (of course), the old comment, do a simple 'flash an LED' test to prove the processor is running (and running at the speed you expect), before trying anything this complex.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 3:51 pm     Reply with quote

Here's a sample program to display the A/D voltage on an LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
jayanthd



Joined: 06 Dec 2012
Posts: 47
Location: Banned - pirate

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 10:54 pm     Reply with quote

asmboy wrote:
Can you post the schematic??

Just in case there is a wiring mistake?
( we all make them from time 2 time ) Very Happy Very Happy Very Happy


Thanks everybody. I have tried all things you said but it doesn't work. Here is my schematic. I am testing in real hardware but made the schematic in Proteus. I have blinked the led and it works.

jayanthd



Joined: 06 Dec 2012
Posts: 47
Location: Banned - pirate

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 10:56 pm     Reply with quote

Ttelmah wrote:
As a general comment, the order of things in CCS should always be:

Processor definition or the include file containing this.
Fuses
Clock definition
Serial definition if used
Other includes

Some parts of many include files (stdio for example), _require_ the RS232 definitions first. Similarly anything using delays, required the clock definitions first.

In the case given, most of the includes are not being used, so it won't cause a problem, but for any future project it _will_.

Best Wishes


My definitions are correct except that include of 16f877.h is in main.h as I used the project wizard to generate the project files.
jayanthd



Joined: 06 Dec 2012
Posts: 47
Location: Banned - pirate

View user's profile Send private message

PostPosted: Wed Mar 20, 2013 10:57 pm     Reply with quote

PCM programmer wrote:
Here's a sample program to display the A/D voltage on an LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1


Where can I get flex_lcd.c? Does that mean lcd.c of CCS C have problems?
SSR



Joined: 09 Nov 2011
Posts: 14

View user's profile Send private message AIM Address

PostPosted: Thu Mar 21, 2013 12:17 am     Reply with quote

jayanthd wrote:
PCM programmer wrote:
Here's a sample program to display the A/D voltage on an LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1


Where can I get flex_lcd.c? Does that mean lcd.c of CCS C have problems?


You don't need to define pins if you are using <lcd.c>. Connect them in order they are defined in the driver file.
Code:

As defined in the following structure the pin connection is as follows:
//     D0  enable
//     D1  rs
//     D2  rw
//     D4  D4
//     D5  D5
//     D6  D6
//     D7  D7
//
//   LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
// #define use_portb_lcd TRUE
SSR



Joined: 09 Nov 2011
Posts: 14

View user's profile Send private message AIM Address

PostPosted: Thu Mar 21, 2013 12:19 am     Reply with quote

Flexible Lcd

http://www.ccsinfo.com/forum/viewtopic.php?t=24661
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 1:28 am     Reply with quote

Are you really using the PIC16F877 ? I never downloaded the datasheet for that chip, meaning the last 10 years no serious question was asked for this chip.

However, only one letter difference, the PIC16F877A is the most popular chip on this forum. One of the changes between these chips is in the ADC configuration...
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 1:43 am     Reply with quote

jayanthd wrote:
Ttelmah wrote:
As a general comment, the order of things in CCS should always be:

Processor definition or the include file containing this.
Fuses
Clock definition
Serial definition if used
Other includes

Some parts of many include files (stdio for example), _require_ the RS232 definitions first. Similarly anything using delays, required the clock definitions first.

In the case given, most of the includes are not being used, so it won't cause a problem, but for any future project it _will_.

Best Wishes


My definitions are correct except that include of 16f877.h is in main.h as I used the project wizard to generate the project files.


Seriously, 'using the wizard', does _not_ make things right. It has a _lot_ of bugs. For instance, it'll use 'SPI_SS_DISABLED' as a setting to the SPI, when nothing else is selected, which is invalid.
The wizard, is also completely dependant on what _you_ tell it. So (for instance), you can say you are running your chip at 40MHz, using an XT crystal. The Wizard won't complain, yet this is completely invalid.
Much better to use the example programs, copy the layouts they use, and ignore the wizard. I'd start by 'shooting the wizard', if you want to get code that works right....
In fact though, the wizard does not arrange things as you show, and this may suggest a problem.

The wizard puts the clock settings into the first definition file, so the order it generates is

Processor definition or the include file containing this.
included in the above Fuses
included in the above Clock definition
included in the above Serial definition if used
Other includes

It keeps the actual loading order exactly as I describe, and does _not_ put the fuse/clock definitions after the includes as you have.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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