|
|
View previous topic :: View next topic |
Author |
Message |
pyu
Joined: 04 Feb 2009 Posts: 51
|
pic16F887 & LCD Problem |
Posted: Wed Feb 04, 2009 3:37 am |
|
|
Hi all
I have a RC2004A lcd display (based on KS0066 controller), and a pickit2.
My problem is that there is nothing on my display.
Main.c:
Code: | #include <16F887.h> // header file for the PIC16F887
// includes built-in functions and constants
// for arguments/returns.
#include <math.h>
#include <stdio.h>
// FUSES sets the PIC16F887 Configuration Words. See top of the header file
// 16F887.h for fuse option constants.
#FUSES INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP
#use delay (clock=4000000)
#include <lcd420.c>
void main()
{
//init LCD
lcd_init();
//put char
lcd_putc("\fReady...\n");
}
|
LCD420.C :
Code: |
////////////////////////////////////////////////////////////////////////////
//// LCD420.C ////
//// Driver for common 4x20 LCD modules ////
// As defined in the following structure the pin connection is as follows:
// B0 enable
// B1 rs
// B2 rw
// B4 D4
// B5 D5
// B6 D6
// B7 D7
//
// LCD pins D0-D3 are not used and PIC B3 is not used.
|
++++++++++++++++
Remainder of CCS driver code deleted.
Reason: Forum rule #10:
10. Don't post the CCS example code or drivers, or ask for such code and drivers.
-- Forum Moderator
++++++++++++++++
The connections are (4 bit mode):
RB0 enable
RB1 rs
RB2 rw
RB4 D4
RB5 D5
RB6 D6
RB7 D7
Can anybody help me? What is wrong in my program?
Thx |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 3:28 pm |
|
|
Look at this thread where we talk about the many things that can go
wrong with an LCD connection:
http://www.ccsinfo.com/forum/viewtopic.php?t=36759
Try everything there. Especially look at your connections and the LCD
contrast circuit. If you still have problems then post them here (not
in that thread). |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Wed Feb 04, 2009 4:42 pm |
|
|
LCD KS0066 pins: ( power supply from pickit2 board )
1 - Vss -> GND
2 - Vdd -> +5V
3 - Vo -> connected to 20K pot
4 - RS - pic RB1
5 - RW - pic RB2
6 - E - pic RB0
7 - DB0 - N/C
8 - DB1 - N/C
9 - DB2 - N/C
10 - DB3 - N/C
11 - DB4 - pic RB4
12 - DB5 - pic RB5
13 - DB6 - pic RB6
14 - DB7 - pic RB7
15 - A (+4.2 V for led) - N/C (I don't know for what is this)
16 - K (Power suplly for B/L - N/C (I don't know for what is this)
The LCD has the first line, and the third line with black squares, and the others are clear.
I copy Flex_LCD416.c from there, I edited for my connections:
Code: |
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7
#define LCD_RS PIN_B1
#define LCD_RW PIN_B2
#define LCD_E PIN_B0
|
....
Code: | //for KS0066 LCD
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54 |
And main. c (by PCM programmer):
Code: | #include <16F887.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOCPD
#use delay(clock = 20000000)
#include "Flex_LCD416.c"
//===================================
void main()
{
int8 i;
int8 b1, b2, b3, b4;
setup_adc_ports (NO_ANALOGS);
delay_ms(50);
// The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);
while(1)
{
// Test the clear screen and newline commands.
// Also test that we can write to all 4 lines.
printf(lcd_putc, "\fIts the 1st line");
printf(lcd_putc, "\nIts the 2nd line");
printf(lcd_putc, "\nIts the 3rd line");
printf(lcd_putc, "\nAnd the 4th line");
delay_ms(3000);
// Test some additional characters.
printf(lcd_putc, "\fABCDEFGHIJKLMNOP");
printf(lcd_putc, "\nabcdefghijklmnop");
printf(lcd_putc, "\n1234567890123456");
printf(lcd_putc, "\n!@#$^&*(){}[]:;<");
delay_ms(3000);
}
}
|
The same problem, only 2 line (1 and 3) have black squares :(
LE:
You wrote this:
Quote: | If you get black squares, the LCD is probably not being initialized correctly.
You are using pins B6 and B7 for the LCD. Do you have a debugger or
programmer connected to the board ? It uses those pins. |
I use those pins (B6 and B7 - PicKit2 board). It is possible that my program won't work because of this?
(sorry my english... ) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 4:57 pm |
|
|
Yes, use different pins. Don't use B6 and B7 for the LCD.
Look at the schematic of the 44-pin demo board, on page 39 of
this document.
http://ww1.microchip.com/downloads/en/DeviceDoc/41296B.pdf
You can find some free pins to use. It looks like all of Port D is used
for LEDs, so don't use Port D. Pin A0 is used for trimpot. Pins C0
and C1 are used for a watch crystal. You could move B6 and B7 to
pins E0 and E1. Also, pin B3 is free.
Also, you are using a 4x20 LCD, so you should use the Flex driver for
4x20 LCDs. It's here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268 |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Wed Feb 04, 2009 5:45 pm |
|
|
thanks for the fast reply.
You are right, those pins are used
I change the connections:
Quote: | #define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_E0 //B6
#define LCD_DB7 PIN_E1 //B7
#define LCD_RS PIN_B1
#define LCD_RW PIN_B2
#define LCD_E PIN_B3 //RB0
|
Code: | #define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54
|
Code: | #include <16F887.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOCPD
#use delay(clock = 20000000)
#include "Flex_LCD416.c"
//===================================
void main()
{
int8 i;
int8 b1, b2, b3, b4;
setup_adc_ports (NO_ANALOGS);
delay_ms(50);
// The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);
while(1)
{
printf(lcd_putc, "\fABCDEFGHIJKLMNOP");
printf(lcd_putc, "\nabcdefghijklmnop");
printf(lcd_putc, "\n1234567890123456");
printf(lcd_putc, "\n!@#$^&*(){}[]:;<");
}
}
|
Also RB0 was used ( to a button ).
I changed the library (for 4x20)
The result:
The lcd is showing some strange characters... But not what I want :(
Last edited by pyu on Thu Feb 05, 2009 2:27 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 5:53 pm |
|
|
That image does not show the LCD screen and also it's out of focus. |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Wed Feb 04, 2009 6:14 pm |
|
|
This is because I don't know how to backlight this lcd. ( http://lcd.raystar-optronics.com/comm/upfile/p_080417_01729.pdf ).
I think 15 - A (+4.2 V for led) and 16 - K (Power suplly for B/L) are for powering up the backlight. Can I connect pin 15 to + 5V and pin 16 to ground for doing this? If so, I could do a quality picture. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 04, 2009 6:36 pm |
|
|
Quote: | I have a RC2004A lcd display (based on KS0066 controller) |
How do you know that it's KS0066 compatible ? Where does it say that ?
Also, where is the document that shows the pin names on the LCD ? |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 05, 2009 2:14 pm |
|
|
The 20x4 Flex driver should work with that LCD.
Check your connections very carefully. Maybe try a different LCD. |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Thu Feb 05, 2009 3:32 pm |
|
|
Yes now it's working, it's working. I change two wires
But I have one more question: how can I use backlight for this lcd? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 05, 2009 4:28 pm |
|
|
Here is a web page with an LED series resistor calculator:
http://www.bowdenshobbycircuits.info/led.htm
You can put in these values:
(These numbers come from the RC2004 data sheet in your link)
Code: |
Total LEDs LED voltage LED current Total Voltage
1 4.2 280 5
|
Then press the "Find Resistor" button to calculate the series resistor value
and watts.
I got 3 ohms, and .213 watts, so you really should use a 1/2 watt resistor.
Connect +5v to the 3 ohm resistor, then connect the other side of the
resistor to the "A" pin on the LCD. Connect the "K" pin to ground.
Make sure your voltage regulator and power supply for your board can
supply the extra 280 ma to run the backlight.
----------------
Edit: Updated the link.
Last edited by PCM programmer on Sat Jan 22, 2011 1:24 pm; edited 1 time in total |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Sat Feb 07, 2009 10:54 am |
|
|
Thanks... The backlight it's working now
But now I had another problem :(
I try to make a thermostat with DS18B20 sensor.
I used some sources from http://loginway.net/the-ds18b20-digital-thermometer-and-pic16f877a-microcontroller-on-pic-01-development-board/
main.c:
Code: |
#include <16F887.H>
#device adc=8
#include <math.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOCPD
#use delay(clock = 20000000)
#include "Flex_LCD416.c"
#include "1wire.h"
int i,read_ok;
byte buffer[8];
signed int16 t,t1;
int fTemp=0;
int iWrite=0;
void main()
{
float temperature;
SET_TRIS_B(0x01);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
//setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
delay_ms(50);
// The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();
// Clear the LCD.
printf(lcd_putc, "\f");
//start here
printf(lcd_putc, "\fThis is a test");
printf(lcd_putc, " program!");
delay_ms(1000);
printf(lcd_putc, "\f");
while(1)
{
if(init_1wire())
{
write_1wire(0xcc); //skip ROM
write_1wire(0x44); //convert T
}
if(init_1wire())
{
write_1wire(0xcc); //skip ROM
write_1wire(0xbe); //read scratchpad
for(i=0;i<8;i++)
buffer[i]=read_1wire();
read_ok=1;
}
if(read_ok)
{
t=make16(buffer[1],buffer[0]); //calculate temperature
t=(float)t/16.0; //Calculation 0.1 deg C resolution
printf(lcd_putc, "\f");
printf(lcd_putc, "ok = true");
fTemp = (int)t/16.0;
temperature = (float)t/16.0;
delay_ms(500);
}
lcd_gotoxy(1,1);
//printf(lcd_putc,"Temp= %3.1f \uC", t);
printf(lcd_putc, "\f");
printf(lcd_putc,"Temp1= %2.1f \uC", temperature);
lcd_gotoxy(1,2);
printf(lcd_putc,"X= %3i \ori", iWrite);
lcd_gotoxy(1,3);
printf(lcd_putc,"Temp2= %3.1d \uC", fTemp);
iWrite++;
//\u displays degree sign
delay_ms(500);
}
} |
and 1wire.h:
Code: |
//-----------------------------------------------------
// 1wire.h
//-----------------------------------------------------
//-------------------------data pin definition-----------
#define DQ pin_a1
//I used RA1.
//--------------------------1wire reset-----------------
|
and the result is:
Temp1 = 0.0 uc
Temp2 = 0 uc
x= ... (is not importing)
and ok = true ...
Can you help me with this problem ?
Thanks ;) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 07, 2009 12:44 pm |
|
|
I have not used the DS18B20 sensor. There are many posts on the
forum with sample code for that chip. Use the forum's search page to
find it. There is code in the Code Library forum. |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Mon Feb 09, 2009 2:13 am |
|
|
I made some researches, and in this moment it's showing a 16 time smaller temperature.
I don't know what the problem is, but here
Code: | t=(float)t/16.0; //Calculation 0.1 deg C resolution |
it showing 1.5 deg C, and here
Code: | t=(float)t; //Calculation 0.1 deg C resolution |
It is showing 25 deg C, and a camera thermometer is showing 26 deg.
I will test it with lower and higher temperatures. |
|
|
|
|
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
|