|
|
View previous topic :: View next topic |
Author |
Message |
elphi
Joined: 17 Apr 2007 Posts: 20 Location: tijuana,bajacalifornia,mexico
|
D0-D3 in an LCD |
Posted: Mon Jul 16, 2007 4:38 pm |
|
|
It's a little embarrassing, but i have a little doubt, i have worked with LCD, and after many mistakes and tests, I know how to work with them, but i still don't know why pins D0-D3 don't are used, or what is their use, are they to obtain other characters or what.
It is only a doubt i don't have any problem whit them. _________________ Every little thing gonna be alright |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Bill Boucher
Joined: 04 Feb 2005 Posts: 34 Location: Chatham,ON,CA
|
|
Posted: Tue Jul 17, 2007 10:24 am |
|
|
While the CCS-provided drivers and examples use the standard parallel character LCD in nibble mode (uses D4 to D7 only for data), another standard mode is byte mode (uses D0 to D7). The byte transfer mode passes the entire byte in a single clock, not two, and so operates a little faster. Obviously the nibble transfer mode is used to reduce the number of required I/O lines by 4 from 11 down to 7. The lower nibble data lines are not used for anything unusual and everything that can be done in byte transfer mode can be done in nibble transfer mode. |
|
|
ulaska
Joined: 16 Jul 2007 Posts: 3
|
|
Posted: Thu Jul 19, 2007 2:58 am |
|
|
when using 16f876a, i have to use port B for LCD.
and PICs "RB0/INT" is connected to LCD- Enable pin.
can we connect the LCD/Enable to the VCC? _________________ newbie in PIC |
|
|
Bill Boucher
Joined: 04 Feb 2005 Posts: 34 Location: Chatham,ON,CA
|
|
Posted: Thu Jul 19, 2007 8:27 am |
|
|
ulaska wrote: | when using 16f876a, i have to use port B for LCD.
and PICs "RB0/INT" is connected to LCD- Enable pin.
can we connect the LCD/Enable to the VCC? |
No. The Enable pin is required to be under PIC control. If you really need to use RB0/INT for something else, you can do this a couple of ways.
1/ edit the LCD functions to point to a different port such as port C and connect your LCD to port C.
2/ edit the LCD function such that the struct puts E on RB3, instead of RB0, as shown below:
Code: | struct lcd_pin_map { // This structure is overlayed
BOOLEAN unused; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
BOOLEAN enable; // low order up. ENABLE will
int data : 4; // be pin B3.
} lcd;
|
Also, for my own convenience while using compiler version 3.212, I modified the original CCS LCD code to support any one of the ports A thru E (although you must ensure your specific PIC has enough pins on the port you choose) by adding a simple definition to your program to indicate the port that you want.
Here is my tested-working port selectable LCD code:
Code: | // Filename: LCD420_Port_Defined.c
// revision:
// By: William Boucher
// Date: Jan.31, 2006
// LCD420_Port_Defined.c copied from CCS driver LCD420.c and modified to allow
// user to specify desired port for LCD connections.
// User must define port number in their parent program as LCD_PORT. The port
// defined must have enough pins to support the usual structure as shown below.
// Ports used would typically include B, C, or D but some devices may be able
// to support other ports.
// For example, the main program may define LCD_PORT_ADDR as 6, port B on PIC16
// series devices. Alternatively, LCD_PORT_ADDR as 0xF81, port B on PIC18F
// series devices. It is up to the user to define the correct port address.
// i.e. #define LCD_PORT_ADDR 0x06 // port B on 16F877A
// i.e. #define LCD_PORT_ADDR 0x07 // port C on 16F877A
// i.e. #define LCD_PORT_ADDR 0x08 // port D on 16F877A
// i.e. #define LCD_PORT_ADDR 0x0F81 // port D on 18F2431
// This driver also uses SET_TRIS_? functions. The user of this driver must
// define the required function that matches the defined port address as
// 1 of the following:
// #define LCD_PORT_TRIS_A
// #define LCD_PORT_TRIS_B
// #define LCD_PORT_TRIS_C
// #define LCD_PORT_TRIS_D
// #define LCD_PORT_TRIS_E
////////////////////////////////////////////////////////////////////////////
//// LCD420.C ////
//// Driver for common 4x20 LCD modules ////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
////////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,1997 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
////////////////////////////////////////////////////////////////////////////
#If (!defined(LCD_PORT_ADDR))
#Error You must define 'LCD_PORT_ADDR value' where [value] is the address of the I/O port connected to the LCD .
#Endif
#If (!defined(LCD_PORT_TRIS_A) && !defined(LCD_PORT_TRIS_B) && (!defined(LCD_PORT_TRIS_C) && !defined(LCD_PORT_TRIS_D) && !defined(LCD_PORT_TRIS_E)))
#Error You must define 1 of the following: LCD_PORT_TRIS_A, LCD_PORT_TRIS_B, LCD_PORT_TRIS_C, LCD_PORT_TRIS_D, LCD_PORT_TRIS_E, to indicate the port that the LCD is connected to.
#Endif
// As defined in the following structure the pin connection is as follows:
// PIN_?0 enable
// PIN_?1 rs
// PIN_?2 rw
// PIN_?4 D4
// PIN_?5 D5
// PIN_?6 D6
// PIN_?7 D7
//
// LCD pins D0-D3 are not used and PIC PIN_?3 is not used.
struct lcd_pin_map { // This structure is overlayed
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
BOOLEAN unused; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;
#byte lcd = LCD_PORT_ADDR // This puts the entire structure
// on to port x (at address defined by LCD_PORT_ADDR)
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.
// The following are used for setting
// the I/O port direction register.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in
BYTE lcdline;
#Separate
BYTE lcd_read_byte() {
BYTE low,high;
#if (defined(LCD_PORT_TRIS_A))
set_tris_a(LCD_READ);
#elif (defined(LCD_PORT_TRIS_B))
set_tris_b(LCD_READ);
#elif (defined(LCD_PORT_TRIS_C))
set_tris_c(LCD_READ);
#elif (defined(LCD_PORT_TRIS_D))
set_tris_d(LCD_READ);
#elif (defined(LCD_PORT_TRIS_E))
set_tris_e(LCD_READ);
#endif
lcd.rw = 1;
delay_cycles(100);
lcd.enable = 1;
delay_cycles(100);
high = lcd.data;
lcd.enable = 0;
delay_cycles(100);
lcd.enable = 1;
delay_cycles(100);
low = lcd.data;
lcd.enable = 0;
#if (defined(LCD_PORT_TRIS_A))
set_tris_a(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_B))
set_tris_b(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_C))
set_tris_c(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_D))
set_tris_d(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_E))
set_tris_e(LCD_WRITE);
#endif
return( (high<<4) | low);
}
#Separate
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(100);
lcd.enable = 1;
delay_cycles(100);
//delay_us(2);
lcd.enable = 0;
}
#Separate
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(100);
lcd.rw = 0;
delay_cycles(100);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
#Separate
void lcd_init() {
BYTE i;
#if (defined(LCD_PORT_TRIS_A))
set_tris_a(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_B))
set_tris_b(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_C))
set_tris_c(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_D))
set_tris_d(LCD_WRITE);
#elif (defined(LCD_PORT_TRIS_E))
set_tris_e(LCD_WRITE);
#endif
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0, LCD_INIT_STRING[i]);
}
#Separate
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
switch(y) {
case 1 : address=0x80;break;
case 2 : address=0xc0;break;
case 3 : address=0x94;break;
case 4 : address=0xd4;break;
}
address+=x-1;
lcd_send_byte(0,address);
}
#Separate
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
lcdline=1;
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,++lcdline); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
#Separate
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
Now, in your program you need these lines:
Code: |
// set up 4x20 LCD I/O structure for LCD420.c driver
#define LCD_PORT_ADDR PORT_D // tells driver what I/O port to use for LCD
#define LCD_PORT_TRIS_D // tells driver what tris port to use for LCD
#include <LCD420_Port_Defined.c> // 4x20 LCD driver
|
Example of how to use it:
Code: | void Print_Encoder(int Col, Row) //show encoder value on LCD
{
lcd_gotoxy(Col,Row);
lcd_putc("Enc: ");
Printf(lcd_putc, "%6ld ", Encoder);
} |
|
|
|
ulaska
Joined: 16 Jul 2007 Posts: 3
|
|
Posted: Thu Jul 19, 2007 9:27 am |
|
|
i use 2x16ch LCD.
but OK i revised the LCD driver, it works
now RB0 pin is free, i can use it for interrupt! (if i can )
thank you very much! _________________ newbie in PIC |
|
|
|
|
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
|