View previous topic :: View next topic |
Author |
Message |
evelikov92
Joined: 10 Mar 2015 Posts: 23
|
[Solve]Problem with 20x4 LCD |
Posted: Wed Apr 15, 2015 3:23 pm |
|
|
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: 1355
|
|
Posted: Wed Apr 15, 2015 4:27 pm |
|
|
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
|
|
Posted: Wed Apr 15, 2015 8:47 pm |
|
|
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
|
|
Posted: Thu Apr 16, 2015 10:54 am |
|
|
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
|
|
Posted: Thu Apr 16, 2015 11:08 am |
|
|
Post the contents of this file:
Also, are you using the R/W pin on the LCD ? |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Apr 16, 2015 12:46 pm |
|
|
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: 19545
|
|
Posted: Thu Apr 16, 2015 2:04 pm |
|
|
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
|
|
Posted: Fri Apr 17, 2015 1:21 am |
|
|
PCM programmer wrote: | Post the contents of this file:
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
|
|
Posted: Fri Apr 17, 2015 2:47 am |
|
|
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
|
|
Posted: Fri Apr 17, 2015 4:26 am |
|
|
Hi,
At an absolute minimum, change the 'LVP' fuse to 'NOLVP'.
John |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Apr 17, 2015 6:57 am |
|
|
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
|
|
Posted: Tue Apr 21, 2015 3:39 am |
|
|
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
|
|
Posted: Wed Apr 22, 2015 11:59 pm |
|
|
I solve the problem. The problem was hardware. Thanks a lot for the help. |
|
|
|