Jump to content

Recommended Posts

Hello,

 

I'm trying to use a lcd-display on a pic16f872 microcontroller. I think I have connected the display correctly because it clears when I call for lcd_clear(); (connected to PORTC and the control bits to PORTA). But the problem is that I'm not sure which function to call when I want to write a sentence on the display. My question is: Which function do I have to use to write to de LCD and with which parameters do I have to call it?

The code I've written so far:

 

#include <system.h>
//Target PIC16F872 configuration word
#pragma DATA _CONFIG, _PWRTE_OFF & _WDT_OFF & _HS_OSC & _CP_OFF & _LVP_OFF & _DEBUG_OFF & _BODEN_ON
//Set clock frequency
#pragma CLOCK_FREQ	20000000

/*
This is what I've copied from the lcd header file:
*/

#define LCD_ARGS 	2,		/* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
	1, 				/* Use busy signal: 1 = use busy, 0 = use time delays */\
	PORTC, TRISC, 		   /* Data port and data port tris register */ \
	PORTA, TRISA, 			/* Control port and control port tris register */ \
	0,				/* Bit number of control port is connected to RS */ \
	1,				/* Bit number of control port is connected to RW */ \
	2 				/* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // include the LCD template code
//--------------------------------------------------------------------------------------------------------------------
void main()
{
  trisc=0x00;
  adcon1   = 0x7; //digital
  pie1	   = 0x00;
  sspstat   = 0x00;
  sspcon   = 0x00;
  sspcon2 = 0x00;
  delay_s(3);
  char banana= 255;

  lcd_setup();			 //
  lcd_clear();			  //Is this good???
  lprintf("%c",banana);//
  while(1){} 

}

Link to post
Share on other sites

jostie,

Hello,

 

I'm trying to use a lcd-display on a pic16f872 microcontroller. I think I have connected the display correctly because it clears when I call for lcd_clear(); (connected to PORTC and the control bits to PORTA). But the problem is that I'm not sure which function to call when I want to write a sentence on the display. My question is: Which function do I have to use to write to de LCD and with which parameters do I have to call it?

The code I've written so far:

 

#include <system.h>
//Target PIC16F872 configuration word
#pragma DATA _CONFIG, _PWRTE_OFF & _WDT_OFF & _HS_OSC & _CP_OFF & _LVP_OFF & _DEBUG_OFF & _BODEN_ON
//Set clock frequency
#pragma CLOCK_FREQ	20000000

/*
This is what I've copied from the lcd header file:
*/

#define LCD_ARGS	 2,		/* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
	1,				 /* Use busy signal: 1 = use busy, 0 = use time delays */\
	PORTC, TRISC,			/* Data port and data port tris register */ \
	PORTA, TRISA,			 /* Control port and control port tris register */ \
	0,				/* Bit number of control port is connected to RS */ \
	1,				/* Bit number of control port is connected to RW */ \
	2				 /* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // include the LCD template code
//--------------------------------------------------------------------------------------------------------------------
void main()
{
  trisc=0x00;
  adcon1   = 0x7; //digital
  pie1	   = 0x00;
  sspstat   = 0x00;
  sspcon   = 0x00;
  sspcon2 = 0x00;
  delay_s(3);
  char banana= 255;

  lcd_setup();			 //
  lcd_clear();			  //Is this good???
  lprintf("%c",banana);//
  while(1){} 

}

Looks good but %c is not supported, use:

...
char banana[2];
banana[ 1 ] = 0; // null terminate
banana[ 0 ] = 65; // the character 'A'
lprintf("%s", banana );
...

Regards

Dave

Link to post
Share on other sites

I got it quite wrong.

Looks good but %c is not supported, use:

...
char banana[2];
banana[ 1 ] = 0; // null terminate
banana[ 0 ] = 65; // the character 'A'
lprintf("%s", banana );
...

Regards

Dave

The lprintf will only output a formatted numerical value, or just a string, so use:

...
char banana[2];
banana[ 1 ] = 0; // null terminate
banana[ 0 ] = 65; // the character 'A'
lprintf( banana );
...

Link to post
Share on other sites
  • 4 weeks later...

Dave,

 

sorry for my late reaction but I thought it wasn't posted because internet was knocked out... <_<

 

Now I have a new problem. I have bought the extra plugins pack, I thought that was much easier... :)

 

The following code doesn't work....it probably is a little dumb thing I think but I can't find it.

 

#include <system.h>

//Target PIC16F628a configuration word
#pragma DATA _CONFIG, _PWRTE_ON & _WDT_OFF & _HS_OSC & _CP_OFF & _LVP_OFF & _BOREN_OFF & _DATA_CP_OFF //& _MCLRE_
//Set clock frequency
#pragma CLOCK_FREQ	20000000
#define MAX 255

#define LCD_ARGS 	2,	/* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \
	1, 				/* Use busy signal: 1 = use busy, 0 = use time delays */\
	PORTB, TRISB, 	/* Data port and data port tris register */ \
	PORTA, TRISA, 	/* Control port and control port tris register */ \
	3,				/* Bit number of control port is connected to RS */ \
	2,				/* Bit number of control port is connected to RW */ \
	1 				/* Bit number of control port is connected to Enable */

#include <lcd_driver.h> // include the LCD template code

void main()
{
 trisa=0xFF;
 trisb=0xFF;
 cmcon = 0x07; 
 vrcon = 0x00;
 pie1  = 0x00;
 pir1  = 0x00;

 LCD_Setup();

 while(1)
 {
  lprintf("aap");
 }  
}

 

Sourceboost gives an error about LCD_setup(), error: unknown identifier. I tried a lot of things. I want the code to work for a pic16f628a, the example is designed for the 16f84.

 

PS. Did I already mentioned I'm from Holland(ow yes Amsterdam!) so there can be mistakes in my English.

 

Ow and btw Happy Christmas!

Edited by jostie
Link to post
Share on other sites
I'm not familiar with using LCDs, but I think that it's meant to be lcd_setup rather than LCD_setup, from looking at lcd_drive.h

 

Twomers,

 

You're bloody right! I looked in the 4bit example for lcd in sourceboost and there was LCD_Setup(); used wíth capitals, so I thought I had to use that...Bit stupid actually.

But thank you! <_<

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...