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

[Solve]Problem with 20x4 LCD

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



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

[Solve]Problem with 20x4 LCD
PostPosted: Wed Apr 15, 2015 3:23 pm     Reply with quote

I have a problem with 20x4 LCD.
I tried write simple text at LCD but it's not working. It's can't enable LCD.
I used PIC18F6722 microcontroller and el-2004d-ybs-r LCD device.

I tried many programs to enable LCD but is couldn't.

Code:

#include "main.h"
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)

#include <flex_lcd.c>

#define LCD_ENABLE_PIN PIN_F1
#define LCD_RS_PIN PIN_F0

#define LCD_DB4_PIN PIN_F5
#define LCD_DB5_PIN PIN_RF4
#define LCD_DB6_PIN PIN_RF3
#define LCD_DB7_PIN PIN_RF2

#define LCD_TYPE 2

//#define USE_LCD_RW   1

void main()
{
   set_tris_f(0);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
   
   delay_ms(50);
   lcd_init();
   delay_ms(50);
   
   printf(lcd_putc, "\f");
     
   while(1)
   {
      lcd_gotoxy(1, 1);
      printf(lcd_putc, "Hello");
   }
}


Sorry for my English.


Last edited by evelikov92 on Wed Apr 22, 2015 11:57 pm; edited 1 time in total
jeremiah



Joined: 20 Jul 2010
Posts: 1339

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 4:27 pm     Reply with quote

All of your #define's have no effect because you did them after the flex_lcd include. Put them before the flex_lcd #include and then see if that helps.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 8:47 pm     Reply with quote

Quote:
#define LCD_ENABLE_PIN PIN_F1
#define LCD_RS_PIN PIN_F0

#define LCD_DB4_PIN PIN_F5
#define LCD_DB5_PIN PIN_RF4
#define LCD_DB6_PIN PIN_RF3
#define LCD_DB7_PIN PIN_RF2

These pin definitions are not used with the flex lcd drivers in the CCS
code library. Those two files use defines like this:
Code:
#define LCD_DB4   PIN_D4
#define LCD_E     PIN_E2

Your defines appear to come from Avrfreaks or Arduino, but they are
not part of any code on the CCS forum or in the CCS directories.
Also, CCS does not use "PIN_RF2". They use PIN_F2.

Use the 20x4 flex lcd driver here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268
Edit the #define statements at the top of the file to match the connections
on your board.
evelikov92



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

PostPosted: Thu Apr 16, 2015 10:54 am     Reply with quote

I change #define in the driver file, I put them before flex_lcd #include, and I fixed wrong misspelled Pins.
And is not working. I don't know could I wrong in finding the right pins (almost sure this is the right pins), or in the my software is wrong.

Code:

#include "main.h"
#use delay(clock=8000000)

#define LCD_ENABLE_PIN PIN_F1
#define LCD_RS_PIN PIN_F0

#define LCD_DB4_PIN PIN_F5
#define LCD_DB5_PIN PIN_F4
#define LCD_DB6_PIN PIN_F3
#define LCD_DB7_PIN PIN_F2

#define LCD_TYPE 2

#include <flex_lcd.c>

void main()
{
   set_tris_f(0);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
   
   delay_ms(50);
   lcd_init();
   delay_ms(50);
   
   printf(lcd_putc, "\f");
   output_high(PIN_D1); // Transistor
   output_high(PIN_C2); // LED
     
   while(1)
   {
      lcd_gotoxy(1, 1);
      printf(lcd_putc, "Hello");
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 16, 2015 11:08 am     Reply with quote

Post the contents of this file:
Quote:
#include "main.h"


Also, are you using the R/W pin on the LCD ?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Apr 16, 2015 12:46 pm     Reply with quote

Hi,

Step #1 of any PIC project is to verify that your PIC is actually running, and running at the intended speed. That may seem odd, but some PICs have a myriad of clock/oscillator options, that it's pretty easy to get it wrong!

The best way to tell if your PIC is running at the correct speed is to flash an LED each time your program starts. Try adding this code to your program and tell us what happens to the LED attached to Pin C2. Time the flashes. they should be 1 second in duration.

Code:

   int8 iIndex;

   // Here we blip the Power LED at power-up to show that the interface is working
   for ( iIndex = 0 ; iIndex < 4 ; iIndex++ )
   {
      output_high(PIN_C2);
      delay_ms(1000);
      output_low(PIN_C2);
      delay_ms(1000);
   }


John
Ttelmah



Joined: 11 Mar 2010
Posts: 19454

View user's profile Send private message

PostPosted: Thu Apr 16, 2015 2:04 pm     Reply with quote

I think he is still missing the correct setup.

Look at what PCM_Programmer said in this paragraph:

"Use the 20x4 flex lcd driver here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268
Edit the #define statements at the top of the file to match the connections
on your board."

and do it as he says. Edit the defines in the file.

Flex_lcd, does not use defines in the main. It expects them to be done inside the file.
evelikov92



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 1:21 am     Reply with quote

PCM programmer wrote:
Post the contents of this file:
Quote:
#include "main.h"


Also, are you using the R/W pin on the LCD ?


Code:

#include <18F6722.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES XINST                    //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K                  //1K words Boot Block size

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


I'm not using R/W pin

ezflyr wrote:

The best way to tell if your PIC is running at the correct speed is to flash an LED each time your program starts. Try adding this code to your program and tell us what happens to the LED attached to Pin C2. Time the flashes. they should be 1 second in duration.


Is correct durations, I trying and is correct time.
evelikov92



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 2:47 am     Reply with quote

I tried in Proteus and it's working. But the real structure (machine) is not working. Thanks a lot for the help.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 4:26 am     Reply with quote

Hi,

At an absolute minimum, change the 'LVP' fuse to 'NOLVP'.

John
temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 6:57 am     Reply with quote

and...
this...
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled

needs to be no !

then
have you proper caps for your 8 Meg xtal....
got MCLR pulled high ?

the list grows....

jay
ic4ru5



Joined: 12 Apr 2015
Posts: 3
Location: Estonia

View user's profile Send private message

PostPosted: Tue Apr 21, 2015 3:39 am     Reply with quote

Double-check your wiring. Proteus isn't good place to prototype your circuit in my small experience but is very good to test code logic of LCD. I mean user interface ecs.
I had same problem recently- my mistakses: MY 420LCD needed 3,3vdc on Vdd pin not 5. still contrast circuit needed 5V with ground pin of potentiometer had to be connected with pin Vee on my LCD.
On my 216 lcd i had potentiometer wired in wrong way.
Double, tripe check your wiring.
Heres my code what is working like a charm. Redefine your flex_lcd420 pins. in my case I commented out RW pin. driver have instructions. For cursor check my code.
Code:
#include <18F2520.h>

#FUSES NOWDT         //NOWDT No Watch Dog Timer
#FUSES INTRC_IO      //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT     //Code not protected from reading
#FUSES NOBROWNOUT    //No brownout reset
#FUSES NOPUT         //No Power Up Timer
#FUSES NOLVP         //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOPBADEN      //PORTB pins are configured as digital I/O on RESET
#FUSES NOXINST       //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=8000000)

//#include <flex_lcd.c>
#include <flex_lcd420.c>

//#define DELAY 1000
#use rs232(baud=9600, XMIT=PIN_C6, RCV=PIN_C7)//for proteus terminal
//-----------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

void main_init(void){
   SET_TRIS_B(0);
   SET_TRIS_A(0b00011111);
   setup_adc(ADC_OFF);
   setup_adc(NO_ANALOGS);
   SETUP_CCP1(CCP_OFF);
   setup_spi(FALSE);
   setup_counters(T0_INTERNAL,WDT_16MS);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   delay_ms(100);
   lcd_init();
   delay_ms(100);
}


#define PUHASTA_LCD     lcd_putc("\f");//lcd_send_byte(0,0x01);  //Puhastab LCD
#define KURSOR_SEES     lcd_send_byte(0,0x0F);//lcd_send_byte(0,0x0E); //kursor sees
#define KURSOR_V2LJAS   lcd_send_byte(0,0x0C); //kursor v2ljas
evelikov92



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 11:59 pm     Reply with quote

I solve the problem. The problem was hardware. Thanks a lot for the help.
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