View previous topic :: View next topic |
Author |
Message |
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
lcd 2x16 with pic |
Posted: Sat Jun 27, 2015 12:10 am |
|
|
any can give me a sample program to interface lcd 2x16 with pic16f676
_________________ Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Jun 27, 2015 4:47 am |
|
|
CCS supplies an LCD driver in the 'examples' folder. As well there is the 'flex_lcd' driver here in the 'code library'. Both work fine with the common 4/8 bit mode LCDs.
Jay |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
its worked |
Posted: Sun Jun 28, 2015 8:15 pm |
|
|
Thanks _________________ Thanks |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
Trouble Again |
Posted: Tue Jun 30, 2015 11:13 pm |
|
|
I have trouble with hardware implementation of interfacing lcd with pic16f676 i don't know whats happened. it works good in pic simulator but won't work in hardware.
My question is is that possible to interface lcd with pic16f676 _________________ Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Wed Jul 01, 2015 1:17 am |
|
|
Of course it is. You have already been told the answer.
Just about every single poster here will at some point have interfaced such an LCD, and many of them will have interfaced hundreds of different types. Most starting with the code you have been pointed to.
Remember though this only works with LCD's that are clones of the 'standard' Hitachi driver. Probably 90% of LCD's but unless you are sure, you need to find the data sheet for _your_ LCD.
It's the old thing. Work one step at a time.
First simulators will 'accept what you tell them' about the PIC receiving a clock and power. Real chips won't. The connections need to be right. This is why the _first_ thing you need to do, is verify your chip actually is running, and running at the right speed. Search here for 'flash an LED'. The number of posts you will find, should make it plain that this is a) important, and b) the first thing you need to do. You need to get the connections and fuses _right_ before the real chip will run. The simulator is much more forgiving.
Then, your connections to the LCD, need to match the connections you are programming. The drivers (both lcd.c, and flex_lcd.c), both allow you to change the pins used. Flex is more 'flexible' here, allowing less pins to be used if required. Start by reading the comments in these files. The first fifty lines or so of lcd.c, tell you how the lcd has to be connected, and how the code has to be modified to suit your connection. Flex also contains similar instructions.
Then remember the contrast pin. The voltage needed on this, depends on the exact LCD involved (actually the chemistry of the crystal itself). So LCD's from the same manufacturer in different colours will often require different voltages. The displays will (in many cases) not display _anything_ till this voltage is right. Many modern displays allow this to be just grounded (0v). However a lot of older displays and some colours require -ve voltages on this pin. The simulator knows _nothing_ about these contrast requirements. You need to read the data sheet for _your_ display, and set this correctly. |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
Trouble |
Posted: Fri Jul 03, 2015 12:59 am |
|
|
In pic16f676 i have only 2 ports and both have (A0-A5,C0-C5). It doesn't support rs232 communication. I tried lcd interface in this chip now i am getting a special characters apart from desired message. Is that any problem on shifting the data.......
I am adding my header also
Code: |
#use delay(clock=4000000)
void cmd();
void data();
void init();
void lcd_send_nibble(int8 nibble);
#define LCD_DB4 PIN_c0
#define LCD_DB5 PIN_c1
#define LCD_DB6 PIN_c2
#define LCD_DB7 PIN_c3
#define LCD_RS PIN_A5
#define LCD_RW PIN_A4
#define LCD_E PIN_A0
void cmd()
{
output_low(LCD_RS);
output_low(LCD_RW);
output_high(LCD_E);
delay_ms(10);
output_low(LCD_E);
}
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
}
void data()
{
output_high(LCD_RS);
output_low(LCD_RW);
output_high(LCD_E);
delay_ms(20);
output_low(LCD_E);
}
void init()
{
int i;
delay_ms(20);
for(i=0;i<3;i++)
{
lcd_send_nibble(0x30>>4);
cmd();
delay_ms(10);
lcd_send_nibble(0x30);
cmd();
delay_ms(10);
}
lcd_send_nibble(0x20>>4);
cmd();
delay_ms(1);
lcd_send_nibble(0x20);
cmd();
delay_ms(1);
lcd_send_nibble(0xf0>>4);
cmd();
delay_ms(10);
lcd_send_nibble(0xf0);
cmd();
delay_ms(10);
cmd();
delay_ms(20);
lcd_send_nibble(0x00);
cmd();
delay_ms(10);
}
|
main code
Code: |
#include<16f676.h>
#include <lcd_4.h>
#fuses INTRC_IO,NOWDT, NOPROTECT, BROWNOUT,NOWDT, PUT
#use delay(clock=4000000)
void main()
{
char a[6]="hello";
int i=0;
init();
delay_ms(20);
lcd_send_nibble(0x08);
cmd();
delay_ms(20);
lcd_send_nibble(0x00);
cmd();
delay_ms(20);
while(i<6)
{
delay_ms(20);
lcd_send_nibble((a[i]>>4));
data();
delay_ms(50);
lcd_send_nibble(a[i]);
data();
delay_ms(20);
i++;
}
} |
The flexi_lcd is not working for this controller and the hardware connections are fine.
Sorry for troubling you again and again...
I need Support
_________________ Thanks |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Fri Jul 03, 2015 5:31 am |
|
|
I may be missing it (I'm half asleep), but typically, you need to wait 500ms or so at start-up for the LCD to power up, then you need to call lcd_init(). If you don't pause at the start and then call the lcd_init routine, you will get garbage.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Jul 03, 2015 7:33 am |
|
|
Hi,
Huh??? Your implementation looks nothing like the Flex_LCD example in the code library! If you are going to 'roll your own', expect 'odd' results! Use the code exactly as written, modified for your hardware, and report back!
Also, without splitting hairs, all PICs support RS232 communications! You should learn to use a serial port for diagnostics!
John |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
Rs232 implementation |
Posted: Fri Jul 03, 2015 7:01 pm |
|
|
Hi,
I am actually thought that only the pics having tx and receive pin have the ability to support rs232. So sorry for my mistake can you give me a small example code to implement rs232 for diagnostic purpose.............. _________________ Thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Jul 03, 2015 8:47 pm |
|
|
Hi,
You need to spend some time reading the CCS manual, which includes the hardware and code examples to use RS232 serial communications!
Good Luck!
John |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
|
Posted: Fri Jul 03, 2015 8:54 pm |
|
|
Thanks for this kind information ...... _________________ Thanks |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Mon Jul 06, 2015 3:37 am |
|
|
did you find an example for RS232 comm. or do you need more help with this? |
|
|
berlin vince joe V S
Joined: 26 Jun 2015 Posts: 16
|
|
Posted: Tue Jul 07, 2015 9:44 pm |
|
|
i can't find rs232. can you help me........ _________________ Thanks |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Tue Jul 07, 2015 11:56 pm |
|
|
ok. The PIC16F676 doesn't have a hardware UART so the compiler should create the code for you.
Open the help file (or press F11 in MPlab) and look for #use rs232
This will give you all the options of the command.
Here is an example (put this near the top of the program) :
#use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)
to send a char (for debugging) use putc() or printf() . These are also documented in the help file. |
|
|
|