getting LCD program to work?

Status
Not open for further replies.

MrDEB

Well-Known Member
Using the LCD hello world routine from
Swordfish Tutorial - LCD
Using swordfish basic
Have computer #2 with pickit2, swordfish prg and mplab.
Programed the 18F452 (It said sucessful in the pickit2 prg.
Now how do I get the display to show hellow world. Somewhere in pickit2 or mplab it has a RUN??
NOTE can not get pickit2 loaded back on computer #1. tried removing previous but ?
so I now have computer #2 with all pic related stuff. Can't seem to get computer #2 to connect to internet via usb?? so I edit in swordfish, save to cd then copy to computer #2.
working on a usb hub so computers can communicate with each other.
 
disconnected from junebug then attached battery
LCD shows several white long thin rectangles that change
must be doing somethig?
tried adjusting the pot
no black digits or ??
 
am I supposed to have a connection to the backlight terminals on the LCD?
also when using Junebug, I press F10 (compile n program I get a message that I need to reset the targer device. Am assuming this is just MCLR? Tried pressing my MCLR button and still get message.
 
not sure if this is of any help.............if you dont have a backlight you can leave pin15-16 unconnected. make sure you have the pins the right way round (i been caught out by this), also make sure the tutor switches on the bug are all off. again i doubt its much help to you but worth a try.
also i have included a pdf that might help.
 

Attachments

  • Alphanumeric LCDs&.pdf
    1 MB · Views: 221
I did some searching and came up with this link to SURE ELECTRONICS
**broken link removed** 15 & 16 pins are to be connected. Not sure why the schematic shows two 471ohm resistors in parallel when a single 330 ohm would do according to ohms law.
I lit up the backlight and now have a bunch of rectangles with little squares in each. Tried adjusting the 5k pot for contrast but to no avail. Looking at page 11 of the link it shows two resistors in series (47K,10K) with a 10K pot connected at the junction.
I just have a 5K pot connected as per the schematic Swordfish Tutorial - LCD
Need to change as I have 5v at pin 3 of the LCD regardless of pot setting.
I think its working though as the display is toggling every few seconds.
 
schematic& code

maybe I am missing something?
I get 2-rows of 16 white retangles as pictured in schematic
Code:
Device = 18F4520
Clock = 20
 
// some LCD options...
#option LCD_DATA = PORTD.4              // Assign the LCD connections
#option LCD_EN = PORTD.3                //
#option LCD_RS = PORTD.2                //
 
// import LCD library...
Include "LCD.bas"
Include "convert.bas"
Dim Variable As Word
 
// Start Of Program...
DelayMS(150)                            // Let the LCD warm up
LCD.Cls                                 // Clear the LCD screen
LCD.WriteAt(1,1,"Hello World")          // Send some text to the LCD
Variable = 0                            // Clear the "Variable" register
While True
    Inc(Variable)                       // Increment the "Var1" register
    // Convert to a string,
    //  and always display 5 characters   
    LCD.WriteAt(2,1,Convert.DecToStr(Variable,5))  
 
    DelayMS(1000)                       // Delay for 1 second                
Wend

[code/]
 

Attachments

  • test board1..PNG
    34 KB · Views: 246
seems like its not initialized at all

Also clock is 10mhz in schem and 20mhz in code

why does MCLR have diode?

If you see those squares i assume that the POWER is OK and CONTRAST is OK/CHANGE_ABLE

Ensure that the connections are ok and also adjust the contrast and see if you can get anything...
 
Last edited:
I don't know if this will help you but here is the code I used recently to connect a PICkit2 with 16f690 to an LCD.

Code:
#include <stdio.h>
#include <pic.h>
#include <htc.h>
#include "lcd_prog.c"
	__CONFIG(INTIO & WDTDIS	& PWRTEN & BORDIS);

void init (void);

/*******************************************/
// MAIN - LCD COMMUNICATION
/*******************************************/

void main (void)
	{
	char i;
	
	init();
	init_display();

char txt[]="PUT_TEXT_HERE";
for(i=0;i<15;i++){
print_data(txt[i]);
if(i==8){
print_instr(0xC0);
}
}
	}

/*******************************************/
// INIT - RUN AT STARTUP
/*******************************************/
void init (void)
	{	
		// Init values
		PORTC=0;
		PORTA=0; // RA0 is output 
		
		ANSEL=0;
		
		// Port directions, PIN # is on LCD
		TRISC0 = 0; //-> PIN 11 (DATA, DB4)
		TRISC1 = 0; //-> PIN 12 (DATA, DB5)
		TRISC2 = 0; //-> PIN 13 (DATA, DB6)
		TRISC3 = 0; //-> PIN 14 (DATA, DB7)
		TRISC4 = 0; //-> PIN 6 (E)
		TRISC5 = 0; //-> PIN 4 (RS)
		TRISA0 = 0; //-> PIN 5 (R/W) or connect to ground
	}

Code:
// lcd_prog.c

/*******************************************/
// Prototypes
/*******************************************/
void init_display(void);
void print_data(char data);
void print_instr(char instr);
void E(void);
void delay(void);
void long_delay(void);

/*******************************************/
// Definitions 
/*******************************************/
#define CLEAR 0x01

/*******************************************/
// Function that initiate the display
/*******************************************/
void init_display(void)
	{
		// See the datasheet flow chart for the procedure below
		// This part initiates the LCD in 4-bit mode...
		long_delay();
		long_delay();
		PORTC=0x03;
		E();
		PORTC=0x03;
		E();
		PORTC=0x03;
		E();
		PORTC=0x02;
		E();
	
		// Set LCD properties...
		print_instr(0x28);	// 2: Dual line (even though it is single line)
		print_instr(0x0F);	// 3: Display on, cursor, blink
		print_instr(CLEAR);	// 4: Clear
		print_instr(0x06);	// 5: Entry mode set

	}
// LCD is now initialized...

/*******************************************/
// Print chars to LCD with 4-bit method
/*******************************************/
void print_data(char data)
	{
		PORTC = (data>>4) & 0x0F;
		RC5=1; // RS
		E();

		PORTC = data & 0x0F;
		RC5=1; // RS
		E();
	}

/*******************************************/
// Print instruction to LCD with 4-bit method
/*******************************************/
void print_instr(char instr)
	{
		PORTC = (instr >> 4) & 0x0F;
		E();
		PORTC = instr & 0x0F;
		E();
	}

/*******************************************/
// Toggle E to execute command/instruction
/*******************************************/
void E(void)
	{
		delay();
		RC4=0;
		delay();
		RC4=1;	
		delay();
		RC4=0;
		delay();
	}

/*******************************************/
// short delay
/*******************************************/
void delay(void)
	{
		unsigned int del;
		for(del=0;del<2000;del++){;}
	}

/*******************************************/
// long delay, used at init...
/*******************************************/
void long_delay(void)
	{
		unsigned int j;
		for(j=0;j<60000;j++){;}
	}
 
update on lack of progress

The schematic was migated from the air cannon schematic that pre-scaled the 10mhz to 20mhz. Am using a 10mhz crystal
Using pickit2 I erased the PIC but get an error that says starting address not blank 0x000000
using a junebug to program. checked communication. says ok
Wondering if maybe I need to disconnect the LCD while programming?
NOTE I have to jump U5V to +5V in order to power the lcd off the Junebug (suggested by Junebug provider at Blueroom Electronics.
I noticed that looking from the side I can see what looks like letters. Tried adjusting contrast but to no avail.
Going to try and disconnect the PIC from the LCD (switch the Vcc and Enable or just the Vcc?)
Future plans are to install a 18 pin socket and swap PIC connections to the LCD. But need to get the LCD working first.
I double checked connection, etc.
I am thinking it has to do with having to jump the Vcc in order for Junebug to power off the USB?
 
So maybe having the LCD connected is causing a write failure or incomplete write?
Thinking about inserting a switch to turn the power off to just the LCD then program.
going to try that
 
I inserted a switch between 5vCC and Vcc on LCD and the backlight.
I have to insert jumper on Junebug and then Pickit2 reconizes the device
It programs the device. I see the rectangles changing but no actual numerials or letters, just rectangles. The Pic must be being programed but maybe not right or the LCD is defective?
Adjusting contrast does nothing.
May copy and paste Emilo9s code and see?
 
Atomsoft I like your backpack. Do you program the pic first then plug the backpack in?
Kinda worried about damaging the Junebug with power connected to the PIC via additional power.
Contemplating disconnecting the LCD, inserting a header then pluging the LCD into the header via a molex plug (A backpack like you have.
Wondering if The orginal code used a 18F4520 but I am using a 18F452. Only thing I did was remove the 0 and change the 20mhz to 10mhz.
The 4520 is basically the same as a 452??
 
not sure but if you drop the speed then the delays need to be speed up...

a delay for 100mS at 20mhz is 500,000 cycles
AND
a delay for 100mS at 10mhz is 250,000 cycles
 
Last edited:
Got a solution maybe (suggested by Jon at **broken link removed**
I still have a voltage regulator in the circuit when trying to program the PIC and powering the PIC with the USB via the Junebug.
Can I just attach the battery to the circuit as well as the Junebug at the same time?
 
Well it is apparently getting programed but the contrast does not do anything.
Getting 2 "0"s and a changing rectangle.
Not getting any voltage erros or any other errors. Going to proceed and get an LED to flash. Got to start somewhere.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…