View previous topic :: View next topic |
Author |
Message |
hadeelqasaimeh
Joined: 05 Jan 2006 Posts: 105
|
|
Posted: Fri Apr 06, 2007 6:10 pm |
|
|
hi pcm
i wonder if i can use PIN A4 and PIN A5 as independent input or output
i try but it not work independently
thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 07, 2007 11:15 am |
|
|
You didn't post the PIC that you're using. When you have a hardware-
specific question, you should post the PIC type.
On many PICs, the pin driver for Pin A4 is "open drain". It doesn't have
the ability to drive the pin to a high level. It can only drive it to a low
level. If you set the pin to be at a high level with the output_high()
function, the output will be "floating". You can fix this by adding an
external pull-up resistor to the pin. You can use 4.7K.
On some PICs, pin A5 is an "input only" pin. It doesn't have the
ability to drive the output in any way. So it can't be used with the
Flex LCD driver. |
|
|
hadeelqasaimeh
Joined: 05 Jan 2006 Posts: 105
|
|
Posted: Sat Apr 07, 2007 11:49 pm |
|
|
i use 16f877a |
|
|
applecon2000
Joined: 29 Jul 2007 Posts: 31 Location: UK
|
ask for help |
Posted: Tue Jul 31, 2007 8:26 pm |
|
|
Dear sir, can you explain the following code in LCD.C
"void lcd_init(void)
{
int8 i;
output_low(LCD_RS);
#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif
output_low(LCD_E);
delay_ms(15);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}
}
"
i do not understand the meaning of "for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
"
why we need to set those parameters for LCD initialization?
please explain the purpose for me
I do thank you for your reply. _________________ Enjoy our EEE |
|
|
applecon2000
Joined: 29 Jul 2007 Posts: 31 Location: UK
|
sorry for my question |
Posted: Tue Jul 31, 2007 8:38 pm |
|
|
for my question shown above:
Could u just explain the meaning of the code :for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
......................................#
what's the purpose of first "for(i=0 ;i < 3; i++)" and the code of "lcd_send_nibble(0x02); "
thanks a lot and sorry about my previous problem _________________ Enjoy our EEE |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pokiko
Joined: 27 Jul 2007 Posts: 33
|
|
Posted: Fri Aug 03, 2007 7:26 am |
|
|
Could you give an example for 4 bit LCD by using flexlcd driver and pic18f2520 for hd44780 16x2 LCD which will write to screen just "hello". The pin congiguration have to be as follows.
LCD PIC
D7 -- RB7
D6 -- RB6
D5 -- RB5
D4 -- RB4
E -- RB3
RS -- RB2
RW is grounded. PIC's RB0 and RB1 is used for another aim. crystal oscillator is 20 MHZ.
what kind of configuration i have to make in driver.
thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 03, 2007 12:07 pm |
|
|
At the start of the Flex_LCD.c file, edit the pin list so it looks like this:
Code: | #define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7
#define LCD_E PIN_B3
#define LCD_RS PIN_B2
|
Because you have the R/W pin on the LCD connected to ground, you
need to comment out the following line in the Flex_LCD.c file, as shown:
Code: | //#define USE_RW_PIN 1 |
Here is a demo program to display "Hello World" on the LCD:
Code: |
#include <18F2520.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#include "Flex_LCD.c"
//=======================
void main()
{
lcd_init();
lcd_putc("Hello World");
while(1);
} |
|
|
|
BrunoCF
Joined: 14 Aug 2007 Posts: 2 Location: SP - Brasil
|
Thanks |
Posted: Tue Aug 14, 2007 5:00 am |
|
|
Thank you for the code. Worked just fine for me. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Fri Aug 17, 2007 8:38 am |
|
|
I have purchased the PICDEM 2 PLus board and i am using the Flex_lcd driver for the lcd. However, i am finding that if i try to write more than 7 characters on a line, it locks up the PIC.
#include <18F4520.h>
#device adc=8
#include <stdio.h>
#include <math.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#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 NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <Flex_LCD>
void 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_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while (true)
{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_C2);
delay_ms(1000);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
//output_high(PIN_C2);
delay_ms(1000);
printf("Hello\n\r");
output_high(PIN_D7);
lcd_init();
printf(lcd_putc,"\fRawson\n");
printf(lcd_putc,"Accurat");
}
}
Does anyone have any idea what i am doing wrong? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 17, 2007 9:07 am |
|
|
Quote: | #FUSES XINST //Extended set extension |
This fuse setting will cause the program to run erratically.
Change it to NOXINST. Do this in all your programs for PICs that
have that fuse. |
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Fri Aug 17, 2007 12:12 pm |
|
|
Thanks for the input. Do you have any ideas on why i can only do 7 characters? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 17, 2007 12:40 pm |
|
|
1. The 'XINST' fuse could be the cause of it doing only seven characters.
Make sure you change it to 'NOXINST' in all your programs.
It's essential.
2. Post the list of #define statements that show the connections
between the LCD and the PIC. These #define statements are at
the start of the Flex_lcd.c driver, and must match the connections
on your PIC board.
3. Your test program is too complicated. Try a very simple program.
Example:
Code: |
#include <18F4520.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include "flex_lcd.c"
//==========================
void main()
{
lcd_init();
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
while(1);
} |
|
|
|
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Fri Aug 17, 2007 3:17 pm |
|
|
I changed the setting to NOXINST and it still performed the same. Here are my defines from the flex_lcd file.
// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver. Change these
// pins to fit your own board.
#define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_E PIN_D6
#define LCD_RS PIN_D4
#define LCD_RW PIN_D5
// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.
#define USE_LCD_RW 1
//========================================
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 17, 2007 3:52 pm |
|
|
Based on those pin numbers, you are apparently using the new "Rohs
update" version of the PicDem2-Plus board.
That version of the board can be identified by a surface-mount pad
pattern at the bottom of the proto-typing area on the board. The older
version of the board doesn't have that surface-mount area on it.
If you have the new Rohs version of the board you need to use the
test program shown below. Notice how it adds a #define statement
for the LCD power pin, and it adds two new lines at the start of main().
Those lines are essential for the new Rohs version of the PicDem2-Plus.
Here are the pin assignments that you must set at the top of the Flex
driver. Also, for the "Rohs" PicDem2-Plus board, you must comment
out the "#define USE_LCD_RW 1" line, as shown below.
Code: |
// These are the pin assignments used for the "Rohs"
// PicDem2-Plus:
#define LCD_DB4 PIN_D0
#define LCD_DB5 PIN_D1
#define LCD_DB6 PIN_D2
#define LCD_DB7 PIN_D3
#define LCD_E PIN_D6
#define LCD_RS PIN_D4
#define LCD_RW PIN_D5
// The following line must be commented out for
// the "Rohs" board.
// #define USE_LCD_RW 1
|
Test program for "Rohs" version of PicDem2-Plus board:
Code: |
#include <18F4520.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#define LCD_POWER PIN_D7
#include "Flex_LCD.c"
//============================
void main()
{
output_high(LCD_POWER); // Turn on power to LCD
output_low(LCD_RW); // Set R/W pin on LCD to a low level
lcd_init(); // Initialize the LCD
lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");
while(1);
} |
|
|
|
|