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

LCD issue

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



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

LCD issue
PostPosted: Fri Mar 07, 2014 9:41 am     Reply with quote

Hello friends
I come back after some monthes busy on other projects.
I, today, need to built a photometer to qulify my products. So I make the prototype and, of course, it does not work properly ...

Let say my CCS is V4.119
My PIC is a PIC18F2550

I measure the output of an amplified photodiode and want to disply the result on a LCD, but the LCD does not display anything. I tried with a MIDAS MC10808A6W and with a DENSITRON LMR4048B, both using a driver ST7066
(https://www.sparkfun.com/datasheets/LCD/st7066.pdf)

I have read the specs, read again, drunk a coffee cup, read again, and after the week end, read for the 1000th time ...
I verified ten times my prototype.
There surely is something wrong in my application but I cannot found it.

My prog is as follow :

Code:
#include <18F2550.h>

#DEVICE ADC=8
#FUSES WDT32768                 //Watch Dog Timer uses 1:32768 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)

#FUSES NOBROWNOUT               //No brownout reset

#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NODEBUG                  //No Debug mode for ICD

#FUSES NOLVP                    //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration registers not write protected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOWRTB                   //Boot block not write protected


#use delay(clock=20000000)


and


Code:
// Flashmetre
// 24 fevrier 2014

#include "Flashmetre.h"
#include <stdlib.h>
#include "LCD.c"

//variables de debug---------------------------------------------------------

//variables-------------------------------------------------------------------
//int I_Compteur;
int I_Sensibilite;

/**********************************************************************Initialisation
Initialise tout au démarrage
************************************************************************/
void Initialisation()
{
   delay_ms(100);                              // attendre l'établissement de l'alim

   setup_wdt(WDT_ON);
   
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   setup_adc_ports(AN0);
   
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);   // l'horloge bat 50 ns (Quartz de 20MHz)
   enable_interrupts(INT_TIMER3);
   enable_interrupts(GLOBAL);
   
   I_Sensibilite=1;
   
   // initialise l'afficheur
   LCD_Init();
}

void Display_Write_Number(long Value)
{
int32 Calcul;
char Affichage[8];
int I;

   // on commence à gauche
   // au maxi 65 535
   
   Calcul=(int32)Value;
   itoa(Calcul,10,Affichage);

   output_bit(PIN_C7, 1);
   for (I=8;I>0;I--)
   {
      lcd_putc(Affichage[I]);
   }   
   output_bit(PIN_C7, 0);
}   

void Commute_Sensibilite(int Valeur)
{
   switch (I_Sensibilite)
   {
      case 1:
         if(Valeur>0xC0)   // monter en sensibilité 10
         {
            I_Sensibilite=10;
            output_bit(PIN_A4,TRUE);   
            output_bit(PIN_A5,FALSE);
         }
         else Display_Write_Number(Valeur);   
         break;
         
      case 10:
         if(Valeur>0xC0)   // monter en sensibilité 100
         {
            I_Sensibilite=100;
            output_bit(PIN_A4,FALSE);   
            output_bit(PIN_A5,TRUE);
         }
         else if(Valeur<0x15) // descendre en sensibilité 1
         {
            I_Sensibilite=1;
            output_bit(PIN_A4,FALSE);   
            output_bit(PIN_A5,FALSE);
         }
         else Display_Write_Number(Valeur);
         break;
         
      case 100:
         if(Valeur>0xC0)   // probleme
         {
            // do nothing
         }
         else if(Valeur<0x15) // descendre en sensibilité 10
         {
            I_Sensibilite=10;
            output_bit(PIN_A4,TRUE);   
            output_bit(PIN_A5,FALSE);
         }
         else Display_Write_Number(Valeur);
         break;
   }   
}   



#INT_TIMER3
void Counter()            
{
int I_Photo;

   I_Photo=read_adc();   
   Commute_Sensibilite(I_Photo);                  
}   
   

//-------------------------------------------------------------------------------Main
 
void main()
{
     Initialisation();
   
     while(TRUE)
     {
      restart_wdt();                              // resetter le watch dog !
     }
}


and I use the LCD.C delivered with CCS
It uses the 4 bits mode

But ... nothing appear on my LCD screen

Have you an idea where I can look
temtronic



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

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 10:09 am     Reply with quote

Start with the basics..build upon known, working code.

1) create a simple '1Hz flashing LED' program to verify the PIC,wiring,etc. is functional.

2) now, create a simple 'Hello World' program to verify the LCD module, wiring, etc. is correct.

3) once these programs are working THEN try your 'real' program.

some hints...

a) LCD modules usually need about .5V on the 'contrast' pin.normally you put a pot there and adjust as required.

b) always put a delay_ms(500) BEFORE the LCD_init(); function. LCD modules need some time to 'get organized' before the PIC first accesses them

c) look in the examples that CCS supplies to see how they use LCDs.

d) be sure the wiring from PIC to LCD is correct.

e) you may like to try the 'flex_lcd' driver that should be in the 'code library'. It's more flexible and works very well.

f) there should be examples of the 2 basic programs here in this forum, learn to use the 'search' function.


hth
jay
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 11:44 am     Reply with quote

What Jay said - especially the part about the wait before calling init for the LCD - those things wake up slow and if you try to talk to them too soon, they don't talk at all. I also like to display a simple message and firmware version just after init. for a couple of seconds - it gives a quick check to verify you are talking to the LCD (or other display). If you are not getting the start-up message, then there is no point trying to debug the measuring portion. If you have a spare pin, it is handy to pulse it at a 1hz rate or something (like the blinking LED so you can check it with a scope etc. to verify the processor is running (even better if you have an LED connected to the test point).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 11:53 am     Reply with quote

Get the code working before you enable the watchdog.
Understand that sprinkling a watchdog into the code, without handling it properly, does not improve things, and is just another thing to go wrong.
Then is 'ADC_CLOCK_INTERNAL', legal at your clock rate?.
Then your interrupt will be every 1/76th second. LCD's are _slow_. Typically takes about 1/10th to 1/4 second to actually update a displayed value so it can be read....
Then you output 8 characters from the array, even if it may only have a couple of characters in it. You need to be testing for the terminating null, not just looping through everything.
Following Temtronic's suggestions. You need to start with smaller steps.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Mar 07, 2014 12:25 pm     Reply with quote

Is very frustating for us to try to help you. You do not provide information related to if hardware is functional, you posted many lines of code with this main:
Code:

main()
{
     Initialisation();
     while(TRUE)
     {
      restart_wdt();                              // resetter le watch dog !
     }



I must recognize that you are very optimistic, because your code can not be monitored nor debugged, you do not have any hardware marker
in order to know that the loop is running or that the hardware is alive.

It is a good practice to use some unused MCU pins in order to toggle a LED or a short pulse in order to know that the hardware process passed
for a line of code or functions of interest, or that a preset timer have been fired. A single LED pulse of 100ms is enough to know that, a scope
is almost a must in this hardware stage.
Also you can use an available MCU pin in order to transmit char datas with enviromental variables or values through an RS232 converter.

The quote "Divide and Conquer" is attributed to Julius Caesar, but it is very well applicable today and right here.
_________________
Humber
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 10, 2014 9:16 am     Reply with quote

Dear friends
Thanks for all
I will try to answer each of you.

1/ I have a flashing led, in the Display_Write_Number procedure the Led is driven by output_bit(PIN_C7, 1);

2/ regarding the cabling, I think it is correct. I have a potmeter on V0 pin to pilot the contrast. I supply in 5V. I have tried before by piloting in 8 bits, then switched in 4 bits with the file lcd.c given by CCS, as you saw in my listing.
Nothing appears on the screen.

3/ OK I will add a 500ms delay befor lcd_init, I today only have 100ms

4/ OK, my Display_Write_Number function is called every 50ms (checked with led and scope), I will slow this.

5/ my ADC_CLOCK_INTERNAL is good, my crystal is 20MHz and I have verified with my oscilloscope.

I do the items 3 and 4, no positive result.

Thanks for your suggestions
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Mon Mar 10, 2014 9:42 am     Reply with quote

_Read the data sheet_. Section 21.3.

Quote: For 'ADC_CLOCK_INTERNAL' (RC):

"For device frequencies above 1 MHz, the device must be in Sleep for the entire conversion or the A/D accuracy may be out of specification."

ADC_CLOCK_INTERNAL, is _not_ recommended for devices running above 1MHz, unless you put the PIC to sleep (and therefore stop the master clock) for the ADC conversion. You can't see the ADC clock with an oscilloscope, it is internal to the chip, and it is not a problem with the clock as such, but the effect it has when you are running off a fast crystal at the same time...
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