|
|
View previous topic :: View next topic |
Author |
Message |
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
lcd |
Posted: Sat Dec 18, 2010 5:49 am |
|
|
hi
I'm again now stuck with my lcd program.
I'm using 18f4550 uc, with 4line lcd.
My program works in Isis simulator very well, but not in real pcb.
I checked and rechecked my connection its alright.
??? Is the problem I don't know.
Here's my program:
Code: |
#include <18F4550.H>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not 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 NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O 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 NOMCLR //Master Clear pin used for I/O
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1 //No System Clock Postscaler
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES NOVREGEN //USB voltage regulator enabled
#FUSES NOICPRT //ICPRT disabled
#use delay(clock=8000000)
#include <Flex_LCD4204550.c>
void main()
{
lcd_init();
Delay_ms(500);
lcd_gotoXY(1,1);
printf(lcd_putc, "Hellow");
while(1)
{
lcd_gotoXY(1,1);
printf(lcd_putc, "Hellow");
output_high(PIN_D2);
delay_ms(500);
output_low( PIN_D2);
output_high(PIN_D3);
delay_ms(500);
output_low( PIN_D3);
/*
output_high(PIN_B2);
delay_ms(500);
output_low( PIN_B2);
output_high(PIN_B3);
delay_ms(500);
output_low( PIN_B3);
output_high(PIN_B1);
delay_ms(500);
output_low( PIN_B1);
*/
output_high(PIN_D6);
delay_ms(500);
output_low( PIN_D6);
}
}////////main End |
my lcd program is the most useful flex driver
Code: |
// Flex_LCD420.c
#define LCD_DB4 PIN_B3
#define LCD_DB5 PIN_B4
#define LCD_DB6 PIN_B5
#define LCD_DB7 PIN_B6
#define LCD_RS PIN_B0
#define LCD_RW PIN_B1
#define LCD_E PIN_B2
#define USE_RW_PIN 1
// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines(or more)
int8 lcd_line;
int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Set mode: 4-bit, 2+ lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
//-------------------------------------
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));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}
//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.
#ifdef USE_RW_PIN
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;
output_high(LCD_E);
delay_us(1);
retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
output_low(LCD_E);
delay_us(1);
return(retval);
}
#endif
//---------------------------------------
// Read a byte from the LCD and return it.
#ifdef USE_RW_PIN
int8 lcd_read_byte(void)
{
int8 low;
int8 high;
output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return( (high<<4) | low);
}
#endif
//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_RW_PIN
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif
if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);
#ifdef USE_RW_PIN
output_low(LCD_RW);
delay_cycles(1);
#endif
output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
void lcd_init(void)
{
int8 i;
lcd_line = 1;
output_low(LCD_RS);
#ifdef USE_RW_PIN
output_low(LCD_RW);
#endif
output_low(LCD_E);
// Some LCDs require 15 ms minimum delay after
// power-up. Others require 30 ms. I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);
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 50 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_RW_PIN
delay_ms(5);
#endif
}
}
//----------------------------
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
switch(y)
{
case 1:
address = LCD_LINE_1_ADDRESS;
break;
case 2:
address = LCD_LINE_2_ADDRESS;
break;
case 3:
address = LCD_LINE_3_ADDRESS;
break;
case 4:
address = LCD_LINE_4_ADDRESS;
break;
default:
address = LCD_LINE_1_ADDRESS;
break;
}
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
//-----------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
lcd_line = 1;
delay_ms(2);
break;
case '\n':
lcd_gotoxy(1, ++lcd_line);
break;
case '\b':
lcd_send_byte(0,0x10);
break;
default:
lcd_send_byte(1,c);
break;
}
}
//------------------------------
#ifdef USE_RW_PIN
char lcd_getc(int8 x, int8 y)
{
char value;
lcd_gotoxy(x,y);
// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();
output_low(LCD_RS);
return(value);
}
#endif |
please anyone help me to rid out of the problem |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
another information |
Posted: Sat Dec 18, 2010 5:52 am |
|
|
I use smartpro for burning uc
and the configuration bit are
debug disable
pwrt disable
fosc3 enable
fosc2 enable
fosc1 disable
regards misel |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sat Dec 18, 2010 6:16 am |
|
|
First, what is your crystal?. There is a very odd mix of oscillator selections, that are almost certainly unecessary. You don't need a PLL fuse if you are not using the PLL, for example, or USB clock selections, etc...
Then, enable the PUT. In general, unless you must get the processor up in the least time, this is more reliable.
Then move your delay at the start, in front of lcd_init. LCD's quite commonly take longer to wake than the original Hitachi chipset, and this is unlikely to be 'known' by the simulator.
Are you sure the LCD is not coming up?. What does it show?. If nothing, are you sure your Vee line has a suitable voltage for the display you are using?.
Best Wishes |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply |
Posted: Sat Dec 18, 2010 6:47 am |
|
|
My new fuse config is here
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not 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 NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O 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 NOMCLR //Master Clear pin used for I/O
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPLL1 //Divide By 5(20MHz oscillator input)
#FUSES NOCPUDIV1 //No System Clock Postscaler
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES NOVREGEN //USB voltage regulator enabled
#FUSES NOICPRT //ICPRT disabled
|
Vee voltage is .5v
But lcd still shows boxes.
Oh I'm using 8MHZ crystal externally.
Thanks for reply
regards misel |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 18, 2010 5:05 pm |
|
|
Quote: |
#define LCD_DB4 PIN_B3
#define LCD_DB5 PIN_B4
#define LCD_DB6 PIN_B5
#define LCD_DB7 PIN_B6
#define LCD_RS PIN_B0
#define LCD_RW PIN_B1
#define LCD_E PIN_B2
|
Pins B6 and B7 are used by the ICD debugger. Don't use those pins
for the LCD. |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply |
Posted: Sat Dec 18, 2010 10:28 pm |
|
|
Yaa when I change my pin B6 lcd seem to be ok but its necessary for me to use B6. Is there any way to disable ICD ? I am finding still got no ans.
Thanks for helping me.
regards
Misel |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
For PCM Programmer |
Posted: Sat Dec 18, 2010 11:04 pm |
|
|
thanks for the reply.
is there any way to disable ICD??????
and i use B6 as data pin for lcd.
Thanks Regards
Misel |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 18, 2010 11:24 pm |
|
|
Yes, you can disable the ICD by unplugging it from the board. |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
For PCM Programmer |
Posted: Sun Dec 19, 2010 12:06 am |
|
|
I am doing all my work on project board theres no connection with PB6 and PB7,
I tried by using that command
output_B(0xff);
and measure by multimeter.
and got no output in PB6 and PB7.
I wanna know that is there any way by using software I can disable ICD and can use PB6 and PB7 as normal I/O pin.
Regards
Misel |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Dec 19, 2010 4:38 am |
|
|
Debug (and high voltage ICSP, which uses the same pins) should be being turned off and the pins available for normal use, by the NODEBUG, fuse, and the voltage on the MCLR pin. What is connected to MCLR?. What compiler version?. Are you sure your programmer is not changing the configuration bits (on some programmers, there is a separate 'debug' setting, and this overrides the fuse from the code...
Load the code into MPLAB, make sure the tick box is set to load the configuration bits from the code, and verify that debug _is_ turned off by the code. If so, your problem is with your programmer.
Make sure that you have something attached to the MCLR pin. When 'NOMCLR' is selected, the pin should not be allowed to float. Though if it does the code will normally just 'not work'. It is 'bad practice' to let any pin float, but particularly so, this one.
Best Wishes |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply for Ttelmah |
Posted: Sun Dec 19, 2010 11:40 pm |
|
|
Thanks for the reply.
I'm sending my code and fuse bit configuration of my Smartpro programmer:
Code: |
void main()
{
Delay_ms(500);
disable_interrupts(GLOBAL); // all interrupts OFF
while(1)
{
output_B(0xff);
}
}////////main End
|
[img]
http://www.flickr.com/photos/57228036@N05/5276588880/
[/img]
I get output on port bit as:
0b00111111
I can't find the reason. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Mon Dec 20, 2010 3:23 am |
|
|
You have not answered several things, or said if you have done them. _What compiler version_. Critical....
However I took the following code, Using the supplied 'flash an LED' example, from CCS, compiled it on 4.114, and loaded it with Mach X, onto a 4550, and it ran fine:
Code: |
#include <18F4550.h>
#FUSES NOWDT, CPUDIV1, HS, NOFCMEN, PUT, NOBROWNOUT, NOPBADEN, NOLPT1OSC, NOMCLR, STVREN, NOLVP, NOXINST, NODEBUG, NOPROTECT, NOCPB, NOCPD, NOWRT, NOWRTC, NOWRTB, NOWRTD, NOEBTR, NOEBTRB, ICSP1
#use delay(clock=8000000)
#define LED PIN_B7
void main(void) {
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_comparator(NC_NC_NC_NC);
//Example blinking LED program
while(true){
output_low(LED);
delay_ms(1000);
output_high(LED);
delay_ms(1000);
}
}
|
So, test this on your system, then if it doesn't work, two possibilities:
Compiler version.
Programmer.
Best Wishes |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply |
Posted: Mon Dec 20, 2010 11:01 pm |
|
|
Sir I'm doing it, sorry for replying so late.
Regards
misel |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
reply |
Posted: Mon Dec 27, 2010 3:10 am |
|
|
Sir I have same problem now.
Now another problem is added.
Now same thing is happening in C5 pin. I can't access that pin
regards
misel |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: reply |
Posted: Mon Dec 27, 2010 9:41 am |
|
|
misel0019 wrote: | Sir I have same problem now.
Now another problem is added.
Now same thing is happening in C5 pin. I can't access that pin
|
Wait.
Did you try TTelmah's example? Did it work?
You completely avoided that in your following posts.
Tell us if it worked first.
Did the LED blink?
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
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
|