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

is there any wrong in my lcd code for picdem 2plus with 18f

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







is there any wrong in my lcd code for picdem 2plus with 18f
PostPosted: Fri Nov 06, 2009 11:27 am     Reply with quote

Code:
#include <p18F452.h>
#include <delays.h>
#include "lcd.h" // Include file is located in the project directory
#define LCD_RS PORTDbits.RD4 // Register Select on LCD
#define LCD_EN PORTDbits.RD6 // Enable on LCD controller
#define LCD_WR PORTDbits.RD5 // Write on LCD controller


//--- Function for writing a command byte to the LCD in 4 bit mode --------

void lcd_write_cmd(signed char cmd)
{
unsigned char temp2;


LCD_RS = 0; // Select LCD for command mode
Delay10TCYx(4); // 40us delay for LCD to settle down
temp2 = cmd;
temp2 = temp2 >> 4; // Output upper 4 bits, by shifting out
//lower 4 bits
PORTD = temp2 & 0x0F; // Output to PORTD which is connected
//to LCD
Delay1KTCYx(10);

//lcd_strobe(); // E pulse to strobe in data
LCD_EN = 1; // E = 0
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
LCD_EN = 0; // E = 1
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle

Delay1KTCYx(10);
temp2 = cmd; // Re-initialise temp2
PORTD = temp2 & 0x0F; // Mask out upper 4 bits
Delay1KTCYx(10);
//lcd_strobe();
LCD_EN = 1; // E = 0
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
LCD_EN = 0; // E = 1
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle

Delay1KTCYx(10);
}

void lcd_write_data(char data)
{
char temp1;
LCD_RS = 1; // Select LCD for data mode
Delay10TCYx(4);
temp1 = data;
temp1 = temp1 >> 4;
PORTD = temp1 & 0x0F;
LCD_RS = 1;
Delay1KTCYx(10); //_-_ strobe data in

//lcd_strobe();
LCD_EN = 1; // E = 0
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
LCD_EN = 0; // E = 1
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle

Delay1KTCYx(10);
temp1 = data;
PORTD = temp1 & 0x0F;
LCD_RS = 1;
Delay1KTCYx(10); //_-_ strobe data in

LCD_EN = 1; // E = 0
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
LCD_EN = 0; // E = 1
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle

Delay1KTCYx(10);
}

/*//-- Function to generate the strobe signal for command and character------
void lcd_strobe(void) // Generate the E pulse
{
LCD_EN = 1; // E = 0
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
LCD_EN = 0; // E = 1
Delay1KTCYx(10); // 10ms delay for LCD_EN to settle
}
*/
//---- Function to initialise LCD module ----------------------------------
void lcd_init(void)
{
TRISD = 0x00;
PORTD = 0x00; // PORTD is connected to LCD data pin
LCD_EN = 0;
LCD_RS = 0; // Select LCD for command mode
LCD_WR = 0; // Select LCD for write mode
Delay10KTCYx(250); //
Delay10KTCYx(250); //
Delay10KTCYx(250); //
Delay10KTCYx(250);


lcd_write_cmd(0x33);
lcd_write_cmd(0x32);
lcd_write_cmd(0x28); // 001010xx – Function Set instruction
// DL=0 :4-bit interface,N=1 :2
//lines,F=0 :5x7 dots
lcd_write_cmd(0x0E); // 00001110 – Display On/Off Control
//instruction D=1 :Display on,
// C=1 :Cursor on,B=0 :Cursor Blink on
lcd_write_cmd(0x06); // 00000110 – Entry Mode Set
//instruction I/D=1 :Increment Cursorposition, S=0 : No display shift
lcd_write_cmd(0x01); // 00000001 Clear Display instruction
Delay1KTCYx(20); // 20 ms delay
}


void main(void)
{
lcd_init(); // Initialise LCD module
LCD_RS = 1; // Select LCD for character data mode
Delay1KTCYx(1); // 1 ms delay
while(1)
{
lcd_write_cmd(0x80); // Move cursor to line 1 position 1
lcd_write_data(0x41); // write "A" to LCD
lcd_write_data(0x42); // write "B" to LCD
lcd_write_data(0x43); // write "C" to LCD
lcd_write_cmd(0xC0); // Move cursor to line 2 position 1
lcd_write_data(0x31); // write "1" to LCD
lcd_write_data(0x32); // write "2" to LCD
lcd_write_data(0x33); // write "3" to LCD
while(1); //stop here for now
}
}
pyae54silver
Guest







ANY ONE CAN HELP PLS
PostPosted: Fri Nov 06, 2009 11:31 am     Reply with quote

Though there is no error in program and i can download it to my mcu but it didn't show any thing on lcd.. is there anything wrong.. anyone can help me pls thz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 06, 2009 11:35 am     Reply with quote

The main thing wrong is that this is C18 code and you're on the CCS
forum. You need to be on the C18 forum:
http://www.microchip.com/forums/tt.aspx?forumid=3
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