CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

LCD on Analog Port

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
melissa creek
Guest







LCD on Analog Port
PostPosted: Sat Feb 15, 2003 12:49 pm     Reply with quote

<font face="Courier New" size=-1>Hi,
Can anyone please solve this. I am trying to run an LCD display off of port a on a 16F873. As far as I know I have disabled the analog and enabled the digital IO on that port but the LCD refuses to initialise.

Any suggestions?
PRE
/*
---------
+5--20-|Vdd |
+5---1-|Mclr |
Gnd---8-|Vss |
Gnd--19-|Vss |
4MHz--10-|Xtal |
4MHz---9-|Xtal |
| |
| 16F873 |
| |
| |
| |
| |
| |
| |
| |
| | ---------
| A0|-15--11-|D4 |
| A1|-16--12-|D5 |
| A2|-17--13-|D6 |
| A3|-18--14-|D7 |
| | | |-3--20K pot (contrast)
| A4|-14---6-|EN |
| A5|-13---4-|RS |
| | | |
| | +5-2-| |
| | Gnd-1-| |
| | Gnd-5-| |
| | | DISPLAY |
--------- ---------
/PRE
*/

#include <16F873.h>
#include <jonsinc.h>
#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT

// LCD STUFF
#define LCD_D0 PIN_A0
#define LCD_D1 PIN_A1
#define LCD_D2 PIN_A2
#define LCD_D3 PIN_A3
#define LCD_EN PIN_A4
#define LCD_RS PIN_A5
#define CLEAR_DISP 0x01
#use delay ( clock=4000000 )
#use standard_io ( A )

// These defines are specifically for a 4x16 line display.
#define LINE_16_1 0x00
#define LINE_16_2 0x40
#define LINE_16_3 0x10
#define LINE_16_4 0x50
// These defines are specifically for a 4x20 line display.
#define LINE_20_1 0x00
#define LINE_20_2 0x40
#define LINE_20_3 0x14
#define LINE_20_4 0x54

// These are prototype statements.
void LCD_SetPosition ( UCHAR cX );
void LCD_PutChar ( UCHAR cX );
void LCD_PutCmd ( UCHAR cX );
void LCD_Init ( void );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );




void main( void )
{

LCD_Init (); // initializes display
LCD_PutCmd ( CLEAR_DISP ); // clears display
LCD_SetPosition ( LINE_16_1 ); // sets cursor at offset 0 in first line
printf ( LCD_PutChar, "Test" ); // displays "Test"
LCD_SetPosition ( LINE_16_2 + 5 ); // sets cursor at offset 5 in second line
printf ( LCD_PutChar, "Test" ); // displays "2nd test"
while ( TRUE ); // halts here
}




// These are the display subroutines.==============================


void LCD_Init ( void )
{
setup_adc(NO_ANALOGS); // make all of port a digital
LCD_SetData ( 0x00 );
delay_ms ( 200 ); // wait enough time after Vdd rise
output_low ( LCD_RS );
LCD_SetData ( 0x03 ); // init with specific nibbles to start 4-bit mode
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 ); // set 4-bit interface
LCD_PulseEnable(); // send dual nibbles hereafter, MSN first
LCD_PutCmd ( 0x2C ); // function set (all lines, 5x7 characters)
LCD_PutCmd ( 0x0C ); // display ON, cursor off, no blink
LCD_PutCmd ( 0x01 ); // clear display
LCD_PutCmd ( 0x06 ); // entry mode set, increment
}

void LCD_SetPosition ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}

void LCD_PutChar ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
output_high ( LCD_RS );
LCD_SetData ( swap ( cX ) ); // send high nibble
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); // send low nibble
LCD_PulseEnable();
output_low ( LCD_RS );
}

void LCD_PutCmd ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
LCD_SetData ( swap ( cX ) ); // send high nibble
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); // send low nibble
LCD_PulseEnable();
}

void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 10 );
output_low ( LCD_EN );
delay_ms ( 5 );
}

void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D0, cX & 0x01 );
output_bit ( LCD_D1, cX & 0x02 );
output_bit ( LCD_D2, cX & 0x04 );
output_bit ( LCD_D3, cX & 0x08 );
}</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11738
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD on Analog Port
PostPosted: Sat Feb 15, 2003 1:04 pm     Reply with quote

:=Hi,
:=Can anyone please solve this. I am trying to run an LCD display off of port a on a 16F873. As far as I know I have disabled the analog and enabled the digital IO on that port but the LCD refuses to initialise.
:=
------------------------------------------------------

The very first question would be, do you have a pull-up
resistor on pin A4 ? That's an open drain output, so
you'll need one. You could use a 4.7K resistor in this
circuit.

Also, your ASCII art doesn't display properly on this board.
You have to use the PRE and /PRE tags.
<a href="http://www.pic-c.com/forum/general/posts/11373.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/11373.html</a>
You could edit your post, and surround the art with those tags.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11739
Hans Wedemeyer
Guest







Re: LCD on Analog Port
PostPosted: Sat Feb 15, 2003 4:46 pm     Reply with quote

Did you forget to set tris_a for the line that need to be Output. i.e. A4 and A5.

I did not see it in your code, did I miss something.

Don't forget to do that pulup resistor as PCM Programmer advised. 10K is fine.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11748
melissa creek
Guest







Re: LCD on Analog Port
PostPosted: Sun Feb 16, 2003 12:20 pm     Reply with quote

Not sure that resistors are required!! I have had this code working on port A of a 16F84 without pullup resistors and the port doesn't have any internally.

Thanks


:=Hi,
:=Can anyone please solve this. I am trying to run an LCD display off of port a on a 16F873. As far as I know I have disabled the analog and enabled the digital IO on that port but the LCD refuses to initialise.
:=
:=Any suggestions?
:=
:=/*
:= ---------
:= +5--20-|Vdd |
:= +5---1-|Mclr |
:= Gnd---8-|Vss |
:= Gnd--19-|Vss |
:= 4MHz--10-|Xtal |
:= 4MHz---9-|Xtal |
:= | |
:= | 16F873 |
:= | |
:= | |
:= | |
:= | |
:= | |
:= | |
:= | |
:= | | ---------
:= | A0|-15--11-|D4 |
:= | A1|-16--12-|D5 |
:= | A2|-17--13-|D6 |
:= | A3|-18--14-|D7 |
:= | | | |-3--20K pot (contrast)
:= | A4|-14---6-|EN |
:= | A5|-13---4-|RS |
:= | | | |
:= | | +5-2-| |
:= | | Gnd-1-| |
:= | | Gnd-5-| |
:= | | | DISPLAY |
:= --------- ---------
:=
:=*/
:=
:=#include <16F873.h>
:=#include <jonsinc.h>
:=#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
:=
:=// LCD STUFF
:=#define LCD_D0 PIN_A0
:=#define LCD_D1 PIN_A1
:=#define LCD_D2 PIN_A2
:=#define LCD_D3 PIN_A3
:=#define LCD_EN PIN_A4
:=#define LCD_RS PIN_A5
:=#define CLEAR_DISP 0x01
:=#use delay ( clock=4000000 )
:=#use standard_io ( A )
:=
:=// These defines are specifically for a 4x16 line display.
:=#define LINE_16_1 0x00
:=#define LINE_16_2 0x40
:=#define LINE_16_3 0x10
:=#define LINE_16_4 0x50
:=// These defines are specifically for a 4x20 line display.
:=#define LINE_20_1 0x00
:=#define LINE_20_2 0x40
:=#define LINE_20_3 0x14
:=#define LINE_20_4 0x54
:=
:=// These are prototype statements.
:=void LCD_SetPosition ( UCHAR cX );
:=void LCD_PutChar ( UCHAR cX );
:=void LCD_PutCmd ( UCHAR cX );
:=void LCD_Init ( void );
:=void LCD_PulseEnable ( void );
:=void LCD_SetData ( unsigned int cX );
:=
:=
:=
:=
:=void main( void )
:= {
:=
:= LCD_Init (); // initializes display
:= LCD_PutCmd ( CLEAR_DISP ); // clears display
:= LCD_SetPosition ( LINE_16_1 ); // sets cursor at offset 0 in first line
:= printf ( LCD_PutChar, "Test" ); // displays "Test"
:= LCD_SetPosition ( LINE_16_2 + 5 ); // sets cursor at offset 5 in second line
:= printf ( LCD_PutChar, "Test" ); // displays "2nd test"
:= while ( TRUE ); // halts here
:= }
:=
:=
:=
:=
:=// These are the display subroutines.==============================
:=
:=
:=void LCD_Init ( void )
:= {
:= setup_adc(NO_ANALOGS); // make all of port a digital
:= LCD_SetData ( 0x00 );
:= delay_ms ( 200 ); // wait enough time after Vdd rise
:= output_low ( LCD_RS );
:= LCD_SetData ( 0x03 ); // init with specific nibbles to start 4-bit mode
:= LCD_PulseEnable();
:= LCD_PulseEnable();
:= LCD_PulseEnable();
:= LCD_SetData ( 0x02 ); // set 4-bit interface
:= LCD_PulseEnable(); // send dual nibbles hereafter, MSN first
:= LCD_PutCmd ( 0x2C ); // function set (all lines, 5x7 characters)
:= LCD_PutCmd ( 0x0C ); // display ON, cursor off, no blink
:= LCD_PutCmd ( 0x01 ); // clear display
:= LCD_PutCmd ( 0x06 ); // entry mode set, increment
:= }
:=
:=void LCD_SetPosition ( unsigned int cX )
:= {
:= // this subroutine works specifically for 4-bit Port A
:= LCD_SetData ( swap ( cX ) | 0x08 );
:= LCD_PulseEnable();
:= LCD_SetData ( swap ( cX ) );
:= LCD_PulseEnable();
:= }
:=
:=void LCD_PutChar ( unsigned int cX )
:= {
:= // this subroutine works specifically for 4-bit Port A
:= output_high ( LCD_RS );
:= LCD_SetData ( swap ( cX ) ); // send high nibble
:= LCD_PulseEnable();
:= LCD_SetData ( swap ( cX ) ); // send low nibble
:= LCD_PulseEnable();
:= output_low ( LCD_RS );
:= }
:=
:=void LCD_PutCmd ( unsigned int cX )
:= {
:= // this subroutine works specifically for 4-bit Port A
:= LCD_SetData ( swap ( cX ) ); // send high nibble
:= LCD_PulseEnable();
:= LCD_SetData ( swap ( cX ) ); // send low nibble
:= LCD_PulseEnable();
:= }
:=
:=void LCD_PulseEnable ( void )
:= {
:= output_high ( LCD_EN );
:= delay_us ( 10 );
:= output_low ( LCD_EN );
:= delay_ms ( 5 );
:= }
:=
:=void LCD_SetData ( unsigned int cX )
:= {
:= output_bit ( LCD_D0, cX & 0x01 );
:= output_bit ( LCD_D1, cX & 0x02 );
:= output_bit ( LCD_D2, cX & 0x04 );
:= output_bit ( LCD_D3, cX & 0x08 );
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 11766
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: LCD on Analog Port
PostPosted: Sun Feb 16, 2003 3:48 pm     Reply with quote

:=Not sure that resistors are required!! I have had this code working on port A of a 16F84 without pullup resistors and the port doesn't have any internally.
:=

Just put in the resistor.
<a href="http://www.winpicprog.co.uk/pic_tutorial_lcd_board.htm" TARGET="_blank">http://www.winpicprog.co.uk/pic_tutorial_lcd_board.htm</a>
<a href="http://www.piclist.com/techref/microchip/portpins.htm" TARGET="_blank">http://www.piclist.com/techref/microchip/portpins.htm</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11769
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: LCD on Analog Port
PostPosted: Sun Feb 16, 2003 4:04 pm     Reply with quote

They are for pin A4 on the 16F873!

:=Not sure that resistors are required!! I have had this code working on port A of a 16F84 without pullup resistors and the port doesn't have any internally.
:=
:=Thanks
:=
:=
:=:=Hi,
:=:=Can anyone please solve this. I am trying to run an LCD display off of port a on a 16F873. As far as I know I have disabled the analog and enabled the digital IO on that port but the LCD refuses to initialise.
:=:=
:=:=Any suggestions?
:=:=
:=:=/*
:=:= ---------
:=:= +5--20-|Vdd |
:=:= +5---1-|Mclr |
:=:= Gnd---8-|Vss |
:=:= Gnd--19-|Vss |
:=:= 4MHz--10-|Xtal |
:=:= 4MHz---9-|Xtal |
:=:= | |
:=:= | 16F873 |
:=:= | |
:=:= | |
:=:= | |
:=:= | |
:=:= | |
:=:= | |
:=:= | |
:=:= | | ---------
:=:= | A0|-15--11-|D4 |
:=:= | A1|-16--12-|D5 |
:=:= | A2|-17--13-|D6 |
:=:= | A3|-18--14-|D7 |
:=:= | | | |-3--20K pot (contrast)
:=:= | A4|-14---6-|EN |
:=:= | A5|-13---4-|RS |
:=:= | | | |
:=:= | | +5-2-| |
:=:= | | Gnd-1-| |
:=:= | | Gnd-5-| |
:=:= | | | DISPLAY |
:=:= --------- ---------
:=:=
:=:=*/
:=:=
:=:=#include <16F873.h>
:=:=#include <jonsinc.h>
:=:=#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
:=:=
:=:=// LCD STUFF
:=:=#define LCD_D0 PIN_A0
:=:=#define LCD_D1 PIN_A1
:=:=#define LCD_D2 PIN_A2
:=:=#define LCD_D3 PIN_A3
:=:=#define LCD_EN PIN_A4
:=:=#define LCD_RS PIN_A5
:=:=#define CLEAR_DISP 0x01
:=:=#use delay ( clock=4000000 )
:=:=#use standard_io ( A )
:=:=
:=:=// These defines are specifically for a 4x16 line display.
:=:=#define LINE_16_1 0x00
:=:=#define LINE_16_2 0x40
:=:=#define LINE_16_3 0x10
:=:=#define LINE_16_4 0x50
:=:=// These defines are specifically for a 4x20 line display.
:=:=#define LINE_20_1 0x00
:=:=#define LINE_20_2 0x40
:=:=#define LINE_20_3 0x14
:=:=#define LINE_20_4 0x54
:=:=
:=:=// These are prototype statements.
:=:=void LCD_SetPosition ( UCHAR cX );
:=:=void LCD_PutChar ( UCHAR cX );
:=:=void LCD_PutCmd ( UCHAR cX );
:=:=void LCD_Init ( void );
:=:=void LCD_PulseEnable ( void );
:=:=void LCD_SetData ( unsigned int cX );
:=:=
:=:=
:=:=
:=:=
:=:=void main( void )
:=:= {
:=:=
:=:= LCD_Init (); // initializes display
:=:= LCD_PutCmd ( CLEAR_DISP ); // clears display
:=:= LCD_SetPosition ( LINE_16_1 ); // sets cursor at offset 0 in first line
:=:= printf ( LCD_PutChar, "Test" ); // displays "Test"
:=:= LCD_SetPosition ( LINE_16_2 + 5 ); // sets cursor at offset 5 in second line
:=:= printf ( LCD_PutChar, "Test" ); // displays "2nd test"
:=:= while ( TRUE ); // halts here
:=:= }
:=:=
:=:=
:=:=
:=:=
:=:=// These are the display subroutines.==============================
:=:=
:=:=
:=:=void LCD_Init ( void )
:=:= {
:=:= setup_adc(NO_ANALOGS); // make all of port a digital
:=:= LCD_SetData ( 0x00 );
:=:= delay_ms ( 200 ); // wait enough time after Vdd rise
:=:= output_low ( LCD_RS );
:=:= LCD_SetData ( 0x03 ); // init with specific nibbles to start 4-bit mode
:=:= LCD_PulseEnable();
:=:= LCD_PulseEnable();
:=:= LCD_PulseEnable();
:=:= LCD_SetData ( 0x02 ); // set 4-bit interface
:=:= LCD_PulseEnable(); // send dual nibbles hereafter, MSN first
:=:= LCD_PutCmd ( 0x2C ); // function set (all lines, 5x7 characters)
:=:= LCD_PutCmd ( 0x0C ); // display ON, cursor off, no blink
:=:= LCD_PutCmd ( 0x01 ); // clear display
:=:= LCD_PutCmd ( 0x06 ); // entry mode set, increment
:=:= }
:=:=
:=:=void LCD_SetPosition ( unsigned int cX )
:=:= {
:=:= // this subroutine works specifically for 4-bit Port A
:=:= LCD_SetData ( swap ( cX ) | 0x08 );
:=:= LCD_PulseEnable();
:=:= LCD_SetData ( swap ( cX ) );
:=:= LCD_PulseEnable();
:=:= }
:=:=
:=:=void LCD_PutChar ( unsigned int cX )
:=:= {
:=:= // this subroutine works specifically for 4-bit Port A
:=:= output_high ( LCD_RS );
:=:= LCD_SetData ( swap ( cX ) ); // send high nibble
:=:= LCD_PulseEnable();
:=:= LCD_SetData ( swap ( cX ) ); // send low nibble
:=:= LCD_PulseEnable();
:=:= output_low ( LCD_RS );
:=:= }
:=:=
:=:=void LCD_PutCmd ( unsigned int cX )
:=:= {
:=:= // this subroutine works specifically for 4-bit Port A
:=:= LCD_SetData ( swap ( cX ) ); // send high nibble
:=:= LCD_PulseEnable();
:=:= LCD_SetData ( swap ( cX ) ); // send low nibble
:=:= LCD_PulseEnable();
:=:= }
:=:=
:=:=void LCD_PulseEnable ( void )
:=:= {
:=:= output_high ( LCD_EN );
:=:= delay_us ( 10 );
:=:= output_low ( LCD_EN );
:=:= delay_ms ( 5 );
:=:= }
:=:=
:=:=void LCD_SetData ( unsigned int cX )
:=:= {
:=:= output_bit ( LCD_D0, cX & 0x01 );
:=:= output_bit ( LCD_D1, cX & 0x02 );
:=:= output_bit ( LCD_D2, cX & 0x04 );
:=:= output_bit ( LCD_D3, cX & 0x08 );
:=:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 11770
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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