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

could't write to LCD

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



Joined: 27 Jul 2007
Posts: 33

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

could't write to LCD
PostPosted: Wed Jan 16, 2008 8:48 am     Reply with quote

Hi to all and thanks for such a great forum. I wrote the below code, but i couldn't able to write it to LCD. The problem may be with the code. I used the Flex_LCD at this forum. Can anyone tell me about the problem please?

PIN configurations of LCD.

#define LCD_DB4 PIN_C4
#define LCD_DB5 PIN_C5
#define LCD_DB6 PIN_C6
#define LCD_DB7 PIN_C7

#define LCD_E PIN_C3
#define LCD_RS PIN_C0
//#define LCD_RW PIN_A2
//#define USE_LCD_RW 1

LCd is an h44780 compatible. Pin3 is connected to +5v over 10k and to GND over 330 ohm. R/W is connected to GND. LCD gets power but i can't see anything.

Code:


#include <18F2520.h>
#device  adc=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
//#include <stdio.h>
#include  "flex_LCD.c"

#use fast_io(a)
#use fast_io(b)
//#use fast_io(c)

#define     BUTON_UP       !input(PIN_B4)
#define     BUTON_DOWN     !input(PIN_B5)
#define     BUTON_ENTER    !input(PIN_B6)
#define     BUTON_BREAK    !input(PIN_B7)

#define     MIN_AMPER   1
#define     MAX_AMPER   49
#define     MIN_VOLTAGE  0
#define     MAX_VOLTAGE  30


#define     MIN_CCP_1   12000
#define     MAX_CCP_1   24500
#define     MIN_CCP_2   37000
#define     MAX_CCP_2   49500


......
//some code in here

unsigned int akim=0;
unsigned int   gerilim=0;
unsigned int16 ADC_TO_BE;
unsigned int16 Total_ADC_I;
unsigned int16 Total_ADC_V;
unsigned int16 READED_I;
unsigned int16 READED_V;

void init_MCU();
unsigned int16 ADC_Compute_I(unsigned int16);
unsigned int16 ADC_Compute_V(unsigned int16);


void main(){
      int   modeSelect=0;
      init_MCU();
     
     
      printf(lcd_putc,"\f UP-Akım modu\n");
      printf(lcd_putc,"\f DOWN-Gerilim modu");
     
      if(BUTON_UP){
         modeSelect=1;//AKIM MODU
         delay_ms(20);
      }
      if(BUTON_DOWN){
         modeSelect=2;  //GERİLİM MODU
         delay_ms(20);
      }

     
      if(modeSelect!=0){
         if(modeSelect==1){
            set_adc_channel(0); 
            delay_us(20);
            ccp_1=65535; //ensures that no false CCP interrupt occurs!
            ccp_2=65535;
            set_timer1(0);
            set_timer3(0);
            enable_interrupts( GLOBAL );             

            while(1){
               printf(lcd_putc,"\fI_set=%d\n",akim);               
               if (BUTON_UP){
                  akim++;
                  delay_ms(20);
                  if(akim>MAX_AMPER){
                     akim=50;
                    }
               }
     
               if(BUTON_DOWN){
                  akim--;
                  delay_ms(20);
                  if(akim<MIN_AMPER){
                     akim=0;
                  }
               }
               
               Total_ADC_I=ADC_Compute_I(akim);
               READED_I=read_adc();
               if (READED_I>Total_ADC_I){
                  CCP_1++;
                  CCP_2=CCP_1+25000;
                     if(CCP_1>MAX_CCP_1)
                        CCP_1=MAX_CCP_1;
                        CCP_2=CCP_1+25000;
               if (READED_I<Total_ADC_I){
                  CCP_1--;
                  CCP_2=CCP_1+25000;
                     if(CCP_1<MIN_CCP_1)
                        CCP_1=MIN_CCP_1;
                        CCP_2=CCP_1+25000;             
               
               }             
           
               }
            }
         }
         
         
         
         
         
         
         
         if(modeSelect==2){

           //........
          //some code in here


}
}}




unsigned int16 ADC_Compute_I(unsigned int16 ampere)
{
   unsigned int16   kademe;
           
   kademe=(unsigned int16)(ampere*18,618181818);
           
   return   kademe;
}



void init_MCU(){
setup_spi(SPI_SS_DISABLED);
           
           
            ext_int_edge(L_TO_H);
            output_low( PIN_A5 );
            setup_ccp1( CCP_COMPARE_INT );
            setup_CCP2( CCP_COMPARE_INT );               
            enable_interrupts( INT_EXT );
            enable_interrupts( INT_CCP1 );
            enable_interrupts( INT_CCP2 );
            enable_interrupts( RTCC_OFF );     
            setup_timer_1( T1_INTERNAL |T1_DIV_BY_2 );/
            setup_timer_2(T2_DISABLED,0,1);
            setup_timer_3 (T3_INTERNAL | T3_DIV_BY_2);
                       
            setup_adc_ports(ALL_ANALOG);
            setup_adc(ADC_CLOCK_INTERNAL);
            set_tris_a(0b00011001);
            set_tris_b(0b11110001);
            delay_ms(20);
            lcd_init();
            delay_ms(1500);
           ccp_1=65535;
           ccp_2=65535;
           
            set_timer1(0);
            set_timer3(0);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 16, 2008 12:37 pm     Reply with quote

Your test program is too complicated. Try this program instead:
Code:

#include <18F2520.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

#include "flex_lcd.c"
   
//==========================
void main()
{
lcd_init();

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}
pokiko



Joined: 27 Jul 2007
Posts: 33

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

PostPosted: Thu Jan 17, 2008 9:51 am     Reply with quote

I tried the code above. Still there is no change. Some data goes to LCD when i look with a scope, but I can't see even black squares. Already nothing.

could there be a problem with port c? Exclamation
Ramyses
Guest







PostPosted: Fri Jan 18, 2008 5:43 pm     Reply with quote

pokiko wrote:
I tried the code above. Still there is no change. Some data goes to LCD when i look with a scope, but I can't see even black squares. Already nothing.

could there be a problem with port c? Exclamation


O problema pode ser a falta de delays na bliblioteca flex_LCD. Eu tinha esse mesmo problema, mas inseri alguns delays na biblioteca e resolveu.
Os sinais são muito rápidos para o LCD entender, por isso os delays

SDS

Translation:
The problem can be the lack of delays in the library flex_LCD. I had this exactly problem, but I inserted some delays in the code and fixed it.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sat Jan 19, 2008 7:36 am     Reply with quote

Hello,
Is the contrast of your LCD is properly set?

Franck.
pokiko



Joined: 27 Jul 2007
Posts: 33

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

thank you
PostPosted: Wed Jan 23, 2008 10:32 am     Reply with quote

i have eliminated the problem. It was about the LCD. thank you Franck26 and Ramyses.
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