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

trying to interface lcd screen

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







trying to interface lcd screen
PostPosted: Tue Jun 24, 2003 11:14 am     Reply with quote

Hello,
I am trying to write a program to test a 2x24 lcd screen using a pic 16f877. The pin connections are as follows:

// A1 enable
// A3 rs
// Gnd rw
// D0 D4
// D1 D5
// D2 D6
// D3 D7

When I run the program, I get a bunch of garbage on the screen.

This is the entire program

// As defined in the following structure the pin connection is as follows:
// A1 enable
// A3 rs
// Gnd rw
// D0 D4
// D1 D5
// D2 D6
// D3 D7
//
// LCD pins D0-D3 ,r/w are not used and PIC B3 is not used.

#include <16F877.h>
#use delay(clock = 4000000)

#BIT LCD_EN = 0x05.1 //maps the enable bit to RA1
#BIT LCD_RS = 0x05.3 //maps the rs bit to RA3
#BYTE PORTA = 0x05 //PORTA IS ADDRESS 5
#BYTE PORTD = 0x08 //PORTD IS ADDRESS 8

#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

void lcd_write(char c)
{
PORTD = (PORTD & 0xF0) | (c >> 4);
LCD_STROBE;
PORTD = (PORTD & 0xF0) | (c & 0x0F);
LCD_STROBE;
delay_us(40);
}


// Clear and home the LCD

void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
delay_ms(2);
}

/* write a string of chars to the LCD */

void lcd_puts(char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

void lcd_putch(char c)
{
LCD_RS = 1; // write characters
PORTD = (PORTD & 0xF0) | (c >> 4);
LCD_STROBE;
PORTD = (PORTD & 0xF0) | (c & 0x0F);
LCD_STROBE;
delay_us(40);
}


/* Go to the specified position*/

void lcd_goto(char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialize the LCD - put into 4 bit mode */

void lcd_init(void)
{
LCD_RS = 0; // write control bytes
delay_ms(15); // power on delay
PORTD = (PORTD & 0xF0) | (0x03); //ATTENTION
LCD_STROBE;
delay_ms(5);
LCD_STROBE;
delay_us(100);
LCD_STROBE;
delay_ms(5);
PORTD = (PORTD & 0xF0) | (0x20); // set 4 bit mode
LCD_STROBE;
delay_us(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x08); // display off
lcd_write(0x0F); // display on, blink curson on
lcd_write(0x06); // entry mode
}

void main(){
/*----------configure all the ports-------*/
Set_Tris_A(0x00); //set port A to outputs
Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
//RB1 (DQin) and RB0(pulse in) inputs
Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
//RC2, RC1, RC0 inputs
Set_Tris_D(0x00); //set port D to outputs
Set_Tris_E(0x00); //set port E to outputs

delay_us(500);
lcd_init();

lcd_clear();
lcd_puts("Hello World");


while(1);
}

Thanks for the help,
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515534
mle
Guest







Ignore. Working fine now
PostPosted: Tue Jun 24, 2003 11:34 am     Reply with quote

Forget it, it works!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515535
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