View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
LCD 1601A doesnt run |
Posted: Sat Sep 20, 2014 4:36 am |
|
|
Hello folks.
I have a board that I use to be able to run, but now I face some troubles.
It's about LCD 1601A isn't running.
I checked the connections many times, but found nothing disturbing.
Here is the code:
Code: |
#include <16f1508.h>
#FUSES INTRC_IO, NOMCLR, NOWDT, PUT, PROTECT, NOBROWNOUT, NOIESO, NOFCMEN, NOWRT, NOLPBOR, NODEBUG, NOLVP
#use delay (INTERNAL = 16M)
#define INC_BUTT PIN_A5
#define DEC_BUTT PIN_A4
#define ENTER_BUTT PIN_C5
#define LED_R PIN_C3
#define LED_G PIN_C4
#define RELAY PIN_C6
#define T1 PIN_C7
#define T2 PIN_B7
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_A2
#define LCD_E PIN_C2
#define LCD_RS PIN_C0
#define LCD_RW PIN_C1
#include <lcd.c>
void chip_init (void);
void main(void)
{
chip_init();
lcd_gotoxy(1, 1);
printf(lcd_putc,"Wellcome...");
while (TRUE)
{
output_toggle(LED_G);
delay_ms(50);
}
}
void chip_init (void)
{
setup_wdt (WDT_OFF);
setup_spi (SPI_DISABLED );
setup_dac (DAC_OFF);
setup_oscillator (OSC_16MHZ);
delay_ms(500);
lcd_init();
delay_ms(500);
} |
I checked the pulses on the led and the timing is OK exact 100mS period.
But I don't see the message Wellcome... on the screen. I scoped the R/W pin and it never goes low. It should be low in writing mode, isn't it? May be some peripherals weren't disabled correctly/at all?
Some help would be much appreciated! _________________ A person who never made a mistake never tried anything new. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Sep 20, 2014 5:01 am |
|
|
It'll only pulse low for a tiny period. You might simply not be seeing it.
This depends a lot on the abilities of your scope.
You should change some settings:
#define LCD_TYPE 1 //it defaults to 2 lines
#define LCD_LINE_LENGTH 16 //it defaults to 20 characters
Try turning off the PWM.
Then simply do the toggle a line test, on the R/W pin. You need to get this working before trying to actually talk to the LCD. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Sep 20, 2014 7:02 am |
|
|
You probably have to disable the comparators as well, and maybe the NCO.
They use pin RC1 as well.
For some reason most PICs 'default' to enabling the comparators.
also.... you normally do not use the 'protect' fuse until the product is ready to go 'out the door' for sale.Has nothing to do with your problem, just an observation.
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 20, 2014 10:45 am |
|
|
1. Where does the lcd.c file come from ? Is it the lcd.c driver file
that comes with the CCS compiler ? Is it this one:
Quote: | c:\program files\picc\drivers\lcd.c |
Or is it a file that you found on the forum or the net ? If so, post a link to it.
2. What's your CCS compiler version ?
3. LCD 1601A would likely be a 16x1 lcd. The memory map for this
type of lcd has two different styles. One type is a normal incrementing
memory address across the display. The other type has a break in the
middle and re-starts with an offset address. Can you post a link to the
data sheet which shows the Data ram address map for the lcd ?
4. There is a 16x1 Flex driver in the Code Library:
http://www.ccsinfo.com/forum/viewtopic.php?t=30964
If your LCD has the address offset for the 2nd half of the characters,
you should use the 16x1 flex driver. |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sat Sep 20, 2014 1:04 pm |
|
|
Thank you all.
I changed the code and the display so, to exclude the possibility of faulty LCD unit or corrupted driver. No success though.
The display I am using now is WH2002A, and the driver to flex_lcd.c.
I am sure the display works because I ran it on another board using 18F4620.
No problems there. But when I try with 16F1508 nothing good happens.
I modified my code according to your suggestions.
Here is the new code that suppose to work, but doesn't.
Code: |
#include <16f1508.h>
#FUSES INTRC_IO, NOMCLR, NOWDT, PUT, NOBROWNOUT, NOIESO, NOFCMEN, NOWRT, NOLPBOR, NODEBUG, NOLVP
#use delay (internal = 16M)
#define LED PIN_B6
#include <flex_lcd.c>
void chip_init (void);
void main(void)
{
chip_init();
printf(lcd_putc, "\fHello Riko!");
while (TRUE)
{
output_toggle(led);
printf(lcd_putc, "\fHello Riko!");
delay_ms(500);
}
}
void chip_init (void)
{
setup_wdt (WDT_OFF);
setup_spi (SPI_DISABLED );
setup_dac (DAC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_OFF);
SETUP_CWG(0,0,0,0);
setup_nco(0,0);
SETUP_CLC1(CLC_DISABLED);
SETUP_CLC2(CLC_DISABLED);
SETUP_CLC3(CLC_DISABLED);
SETUP_CLC4(CLC_DISABLED);
SETUP_PWM1(PWM_DISABLED);
SETUP_PWM2(PWM_DISABLED);
SETUP_PWM3(PWM_DISABLED);
SETUP_PWM3(PWM_DISABLED);
setup_oscillator (OSC_16MHZ);
delay_ms(500);
output_high(led);
lcd_init();
output_low(led);
delay_ms(500);
}
|
And here is the flex_lcd.c, I altered the pins so!
https://drive.google.com/file/d/0B5Y7MPFIDn9dZ1oxb0c0WWt1MDQ/edit?usp=sharing
Compiler version: (PCB --- PCD) 5.025
Using the standard lcd.c driver this code stops running at lcd_init(); and never enters the infinite loop. Therefore I replaced it with the alternative one (flex_lcd.c). Now it goes into the infinite loop and led is blinking, but nothing appears on the screen. I keep trying workaround this sh*t.
Thank you again! _________________ A person who never made a mistake never tried anything new. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 20, 2014 1:51 pm |
|
|
Quote: | #define LCD_DB4 PIN_C4
#define LCD_DB5 PIN_C5
#define LCD_DB6 PIN_C6
#define LCD_DB7 PIN_C7
#define LCD_E PIN_C2
#define LCD_RS PIN_C0
#define LCD_RW PIN_C1
|
Have you checked all these LCD pins for signal activity with an oscilloscope ?
You could reduce the 500ms delay in your while() loop so it writes to the
lcd more often. Then you could see activity more easily. Check it at the
LCD pins, not the PIC pins. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Sep 20, 2014 3:48 pm |
|
|
This code works with LCD1602 (essentially same display as 1601A) using
16F1507 or the 16F1509 which are the same chip with different
amounts of memory.
If this code doesn't work with 1601 you have a wiring problem or display
(contrast setting?) problem.
Flex_LCD Settings
Code: |
#define LCD_DB4 PIN_c4
#define LCD_DB5 PIN_c5
#define LCD_DB6 PIN_c6
#define LCD_DB7 PIN_c7
#define LCD_E PIN_c2
#define LCD_RS PIN_c0
#define LCD_RW PIN_c1 // NOT USED-TIE DISPLAY R/W to GND!!!
//#define USE_LCD_RW 1 // Be sure to comment this out in Flex_LCD
|
Test Program:
Code: |
#include <16F1507.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 16MHZ)
//
#include <flex_lcd.c>
//==========================
void main()
{
setup_adc_ports(no_analogs);
lcd_init(); // Always call this first.
delay_ms(450);
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
while(1)
{
output_toggle(Pin_C3);
delay_ms(500);
};
}
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sun Sep 21, 2014 7:46 am |
|
|
I cant believe I didn't spot this:
Pin definition into a standard lcd.c:
Code: |
#define LCD_ENABLE_PIN PIN_B4
#define LCD_RS_PIN PIN_B6
#define LCD_RW_PIN PIN_B5
#define LCD_DATA4 PIN_B7
#define LCD_DATA5 PIN_C7
#define LCD_DATA6 PIN_C6
#define LCD_DATA7 PIN_C3
|
Pin definition into flex_lcd.c:
Code: |
#define LCD_DB4 PIN_B7
#define LCD_DB5 PIN_C7
#define LCD_DB6 PIN_C6
#define LCD_DB7 PIN_C3
#define LCD_E PIN_B4
#define LCD_RS PIN_B6
#define LCD_RW PIN_B5 |
The assigned names for the pins are totally different!
I messed up both. Using definition from one into another and vice versa.
It definitely works now. Thank you all guys ! _________________ A person who never made a mistake never tried anything new. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sun Sep 21, 2014 8:01 am |
|
|
When using 'drivers', I found out decades ago to always make a COPY the original driver ! IE copy 'flex_LCD.C' to 'my_flex_LCD.c'. Make any and ALL changes to YOUR copy, that way you'll always have the original to compare code to.
You can also insert 'conditional' code in the driver( CCS does this) that IF you don't assign variables THEN the default values are assigned.
In any case you should NEVER modify the original drivers.
hth
jay |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sun Sep 21, 2014 10:29 am |
|
|
Thank you for the advice, but I haven't change the original version of lcd.c which is the default driver coming along the compiler installation. I only changed the pin assignment into a flex_lcd.c, but it is necessary in order to fit the board requirements. So what do you mean by this: Quote: | you should NEVER modify the original drivers | ? _________________ A person who never made a mistake never tried anything new. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sun Sep 21, 2014 11:51 am |
|
|
It's always best to copy the original and make ANY changes to YOUR copy. It's too easy to delete a line even one word or character and wonder why 'it worked before'!!
Even simply mistyping(easy with fat fingers or a nerve damaged one...) say an 's' for an 'a' can be very bad. Sure it compiles fine...BUT... doesn't run as expected !!
hth
jay |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sun Sep 21, 2014 1:32 pm |
|
|
Yes, I agree. Although my fingers are tiny _________________ A person who never made a mistake never tried anything new. |
|
|
|