View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
LCD 4 bit mode |
Posted: Tue May 07, 2019 2:09 am |
|
|
Hardware: PIC18F2520
Microcontroller pins B0 to B3 connected LCD DB4 to DB7;
B4 connected to RS
A5 connected to Enable
Test Program:
Code: |
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=4000000)
#define EN PIN_A5
#define RS PIN_B4
void lcd_init();
void lcd_cmd(unsigned char );
void lcd_data(unsigned char );
void disp_cmd(unsigned char );
void disp_data(unsigned char );
void main()
{
delay_ms(100);
lcd_init();
delay_ms(100);
while(1)
{
disp_cmd(0x80);
printf(disp_data, "TESTING ");
delay_ms(100);
}
}
void lcd_init()
{
disp_cmd(0x02); // To initialize LCD in 4-bit mode.
disp_cmd(0x20); // To initialize LCD in 1 lines, 5x7 dots and 4bit mode.
disp_cmd(0x0C);
disp_cmd(0x01);
disp_cmd(0x06);
disp_cmd(0x80);
}
void lcd_cmd(unsigned char c)
{
output_b(c);
output_low(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
void lcd_data(unsigned char z)
{
output_b(z);
output_high(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
void disp_cmd(unsigned char cmd_value)
{
unsigned char cmd_value1;
cmd_value1 = ((cmd_value>>4) & 0x0F); // Shift 4-bit and mask
lcd_cmd(cmd_value1); // Send to LCD
cmd_value1=(cmd_value & 0x0F);
lcd_cmd(cmd_value1); // Send to LCD
}
void disp_data(unsigned char data_value)
{
unsigned char data_value1;
data_value1 = ((data_value>>4) & 0x0F);
lcd_data(data_value1);
data_value1=(data_value & 0x0F);
lcd_data(data_value1);
}
|
But the display shows nothing. Voltages are +5V. Please help . |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue May 07, 2019 3:28 am |
|
|
Not going to work.
Problem is you are outputting a _byte_ (not four bits) with the output_b
instruction. This will change B4 which carries your RS pin.
Also then means you cannot use B5 to B7 since these will be overridden
by this code.
Look at the flex_lcd driver in the code library forum. It shows how
to output the nibble as separate bits. This code works and allows you
to use any combination of bits required. Much simpler.... |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Tue May 07, 2019 4:09 am |
|
|
Code: | #include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=4000000)
#define LCD_RS PIN_B4
#define LCD_E PIN_A5
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3
#include "flex_lcd.c"
void main()
{
lcd_init();
while(1)
{
lcd_putc("\fHello World\n");
delay_ms(100);
}
} |
still the problem remains the same |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue May 07, 2019 4:40 am |
|
|
Hmm.. I've used the flex_lcd driver for years so I know it works, which leads me to believe it's a hardware problem. Recheck all the wiring connections.
Have you run a '1Hz LED' program to confirm the PIC actually works ?
JAy |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Tue May 07, 2019 4:51 am |
|
|
I have also use flex lcd in the past. But for the hardware connections like below
Code: | #define LCD_RS PIN_B4
#define LCD_E PIN_A5
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3
|
it is not working |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue May 07, 2019 5:17 am |
|
|
All pins with alternate peripherals, need to be disabled. Say the ADC, you'll need 'no analog' to disable it.
Jay |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Tue May 07, 2019 5:24 am |
|
|
Code: | setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_comparator (NC_NC_NC_NC); // Disable comparator |
yes i have did those steps too. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue May 07, 2019 6:11 am |
|
|
Start at the beginning.
First have you tested the processor is actually running?. Basic flash an
LED test.
Then triple check the connections. Actually bus through the pins with a meter.
Make sure each pin can be operated by the processor, and no pins are shorted.
Then have you got a part number for the LCD?. How is the LCD Vo pin
wired?.
Some (most_ modern LCD's accept this wired to Vss. However some types
require a different voltage on this, and in some cases it may even need
a -ve voltage. Nothing may be visible till this voltage is right.
Basically if nothing is displayed by the flex LCD driver, you have a hardware
problem. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed May 08, 2019 10:21 pm |
|
|
Back Again!
I have tested the LED test.
I have tested the LCD code with the below connections.
Working with this setup with flex lcd
Code: |
#define LCD_RS PIN_A2
#define LCD_E PIN_A1
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7 |
I have triple checked the connections also. Now I have changed the code to,
Code: |
#define LCD_RS PIN_A2
#define LCD_E PIN_A1
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3 |
Please check flex lcd once again with this connections.
LCD Datasheet: http://www.orientlcd.com/AMC0801AR_B_Y6WFDY_8x1_Character_LCD_Module_p/amc0801ar-b-y6wfdy.htm |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Wed May 08, 2019 11:23 pm |
|
|
OK.
The only things on the B0 to B3 pins that are not on the B4 to B7 pins,
are the FLT input from the ECCP and the CCP2 input (depending on
your fuses). I'd be suspicious of the ECCP. This does wake up enabled.
So disable this. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed May 08, 2019 11:28 pm |
|
|
Please help how to disable ECCP. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu May 09, 2019 12:01 am |
|
|
No, the ECCP is only on the bigger (40/44pin) chips, so this isn't the
problem.
Have you done the basic 'operate each pin' test?. Small program that toggles
B0 for a second, then B1, then B2, then B3, then loops back and starts
again. Test that each pin does toggle, and the ones next door don't.
If your code can toggle the pins, then the port is working, and the
LCD should work. I'm still suspicious there is something basic like one
of the pins having a whisker stopping it from working properly, or a short
between two pins. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Thu May 09, 2019 12:25 am |
|
|
I have also tried 8 bit mode and it is working perfectly.
I have checked each pins and there is no short. Also I have used new microcontroller which I have it.
I shall check the toggle for B0, B1, B2 and B3. Hope it will also work. I'll try it now.
Thanks Ttelmah for the support. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu May 09, 2019 1:34 am |
|
|
Urgh!. If 8bit mode works, it seems to say all the pins are OK.
This really is strange. What do you change when you adapt between using
the high four bits and the low four bits?. Are the low four bits on the LCD
disconnected?.
If each pin on the port can be correctly operated by a test, and the
connection are right, it 'has' to work!. It's even using one of the better
known controller chips, which makes 'oddities' less likely.
That it works on the high four bits, says that the timings are right. So
you have to be looking for something happening like a pin not actually
going high/low properly. So what is different when you connect to the
low 4 bits?. Is a wire pulled anywhere?. Anything touching or crossing
something in a different way?.
Going away to whimper... |
|
|
|