View previous topic :: View next topic |
Author |
Message |
dngyan
Joined: 23 Apr 2010 Posts: 11
|
Problem interfacing 6722 with a 16x2 lcd |
Posted: Fri Apr 23, 2010 10:12 pm |
|
|
Hi PCM programmer and others,
I'm using CCS 6722 development kit interfacing with a 16x2 lcd (ADM1602k). tried both flex_lcd.c and lcdd.c, I still couldn't make the lcd working.
the only change to your original flex_lcd.c was
Code: | #define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_RS PIN_A3
#define LCD_RW PIN_A2
#define LCD_E PIN_A1
|
I'm not sure if it's related with 6722's freq. which is 20MHz or my pin setting is not right.
Many thanks, |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE |
Posted: Sat Apr 24, 2010 5:22 am |
|
|
Is the PIC working ?? |
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
Re: RE |
Posted: Sat Apr 24, 2010 12:44 pm |
|
|
it's working for sure, I can make led flashing and interacts with UART
arunb wrote: | Is the PIC working ?? |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Sun Apr 25, 2010 6:03 pm |
|
|
Thank you for responding, I'd like to provide more information so maybe someone can help me.
First of all, I checked my wiring which should be fine, backlight is on, contrast is changing in the first line when I change the contrast voltage.
By using flex_lcd.c and commenting out USE_LCD_RW (stuck in lcd_init() when I use lcd.c), I can see first line go white then clear (my lcd is adm1602k white on black, and there is a one second delay before and after lcd_init()).
Still I couldn't get any character from the screen:(
My wiring (only place I changed flex_lcd.c)
Code: | #define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
|
and here is my simple program:
Code: |
#include <18F6722.h>
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)
//#include "lcdd.c"
#include "flex_lcd.c"
void main()
{
output_low(PIN_A5);
delay_ms(1000);
lcd_init();
delay_ms(1000);
//lcd_putc("Hello 1\n");
//lcd_putc("World 2");
while(1)
{
output_low(PIN_A5);
delay_ms(10);
output_high(PIN_A5);
delay_ms(1000);
lcd_putc("Hello");
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Sun Apr 25, 2010 10:13 pm |
|
|
Sorry for the mistake, if this is the case, I couldn't use 6722 board (5v) interfacing with this LCD?
I will get a 3.3v board and try again.
|
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Mon Apr 26, 2010 11:00 pm |
|
|
Ok, tested again with a 6627 3.3v board. Still no luck, pretty much appreciated if you can help me.
Wiring for data pin is still the same:
Code: |
#define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_RS PIN_D4
#define LCD_RW PIN_D5
#define LCD_E PIN_D6
|
Other wires :
Code: |
VSS -> GND
VDD -> 3.3v
V0 -> potentiometer -> 3.3v
|->GND
LED+ -> 85om -> 3.3v
LED- -> GND
|
and here is my test program:
Code: |
#include <18F6627.h>
#device ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT //No brownout reset
#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 NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#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 NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=8000000)
#include "FlexLcd.c"
int main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
set_tris_d(0x00);
delay_ms(500);
lcd_init(); //Inicia LCD
delay_ms(500);
printf(lcd_putc,"Hello you\n");
printf(lcd_putc,"PIC16F887");
do {
//printf(lcd_putc,"Hello you\n");
delay_ms(100);
output_low(PIN_G0);
delay_ms(10);
output_high(PIN_G0);
} while(1);
return 0;
} |
dngyan wrote: | Sorry for the mistake, if this is the case, I couldn't use 6722 board (5v) interfacing with this LCD?
I will get a 3.3v board and try again.
|
|
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Mon Apr 26, 2010 11:03 pm |
|
|
is there any chance my lcd is broken? I can see the backlight is on, and when I change contrast, backlight seems changing. Can't figure out why it doesn't work, so frustrated |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 26, 2010 11:13 pm |
|
|
Quote: | Wiring for data pin is still the same:
Code:
#define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_RS PIN_D4
#define LCD_RW PIN_D5
#define LCD_E PIN_D6 |
Do you guarantee that you are actually using pins DB4 to DB7 on the LCD
and not accidently using pins DB0-DB3 ? The upper 4 pins on the LCD's
data bus must be used. Check it one more time.
Quote: | #FUSES H4
#use delay(clock=8000000) |
Here you have it set for the 4x PLL, but your #use delay is set at 8 MHz.
What is the frequency of your external crystal or oscillator ?
Also, have you ever made this PIC board do anything, such as blink an
LED, or do RS-232 output to the PC ? You said this is a new board, so
I have to ask.
This isn't necessary. In Standard I/O mode (which is the default mode)
the compiler sets the correct TRIS as needed.
Quote: | printf(lcd_putc,"PIC16F887"); |
You're using an 18F6627 but this line says 16F887.
Quote: | setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
set_tris_d(0x00); |
This whole block of code isn't necessary. It doesn't really do anything,
and can be deleted.
==> Post your compiler version. |
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Tue Apr 27, 2010 8:12 am |
|
|
Thanks for the instant response PCM Programmer. After making the following change, it's still not working.
1. I'm sure I'm using DB4-DB7 which is closer to the LED+ and LED-
2. I'm not sure about the internal oscillator, but the board did work with other peripherals such as RS232 and as you can see in my while loop, the led (RG0) can be seen flashing on the board.
3. The compiler version is 4.013
4. After clearing the code and current chip model print, here is my testing code:
Code: | #include <18F6627.h>
#device ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT //No brownout reset
#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 NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#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 NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=8000000)
#include "FlexLcd.c"
int main()
{
delay_ms(500);
lcd_init(); //Inicia LCD
delay_ms(500);
printf(lcd_putc,"Hello you\n");
printf(lcd_putc,"PIC16F6627");
do {
delay_ms(100);
output_low(PIN_G0);
delay_ms(10);
output_high(PIN_G0);
} while(1);
return 0;
} |
|
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Tue Apr 27, 2010 8:23 am |
|
|
Still suspecting the voltage type (5v/3.3v) of my LCD. The order I did from sparkfun.com was a 5v white on black model:
http://www.sparkfun.com/commerce/product_info.php?products_id=709
but the label on the back side of LCD said "ADM1602K-NSW-FBS/z". Like what you suggested a 3.3v model will be "ADM1602K-NSW-FBS-3.3v" in the label. So it's really confusing.
By the way, when I use a 6722 evaluation board (5v model) with LCD, I can see the first line of the screen slowly go white then slowly go black every time I reset my PIC board (does that mean it is been initialized?). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 27, 2010 2:28 pm |
|
|
Based on the CrystalFontz page, you have the 5 volt version of the LCD.
Quote: | 3. The compiler version is 4.013 |
That's a very early version of v4, and is known to be buggy.
When using lcd_putc() with printf, it sends a 0x00 byte to the LCD at the
end of the string. It might have other bugs.
Quote: | 2. I'm not sure about the internal oscillator |
I wasn't asking about the internal oscillator. I was asking about the
external crystal that is installed on the board. Earlier in the
thread you said this:
Quote: | I'm using CCS 6722 development kit |
On the page for that kit, if you enlarge the photo of the board, they show
a cylinder type crystal connected to the main oscillator pins on the PIC.
http://www.ccsinfo.com/product_info.php?products_id=18F6722kit
CCS won't say, on the webpage, what the crystal frequency is.
It looks like this crystal:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=XC961-ND
Read the markings on the crystal and post the crystal frequency. |
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Wed Apr 28, 2010 10:49 am |
|
|
Thanks,
* Ok, then I have to go back with the 6722 evaluation board (5v) since I have a 5v lcd
* I see another copy of my compiler is 4.084, is that better?
* For the external oscillator, the 3v board (6627) I'm using is without external oscillator and that's why the frequency is 8MHz. The external oscillator on the evaluation board is 20MHz, after I checked the document. I have another test program for 6722, I will post it later if things still go wrong.
What I will do is to upgrade my compiler and testing. Thank you again for your help:) |
|
|
dngyan
Joined: 23 Apr 2010 Posts: 11
|
|
Posted: Wed Apr 28, 2010 7:41 pm |
|
|
well, failed again:(
I'm using 6722 evaluation board this time, and I can change the contrast. I'm sure the external oscillator is 20MHz. And the compiler is upgraded to 4.032. Hope my test program can give you some clue.
Code: |
#include <18F6722.h>
#fuses HS,NOWDT,NOLVP,NOPUT,BROWNOUT
#use delay(clock=20000000)
#include "flex_lcd.c"
void main()
{
output_low(PIN_A5);
delay_ms(500);
lcd_init();
delay_ms(500);
lcd_putc("Hello 1\n");
lcd_putc("World 2");
while(1)
{
output_low(PIN_A5);
delay_ms(10);
output_high(PIN_A5);
delay_ms(1000);
}
} |
|
|
|
|