Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PIC
hi i want to display string on Lcd. i m doing work on explore 16 board. i stuck with delay can u plz help me..my code is as follow
#include "../../support/PIC24F/h/p24FJ128GA010.h"
#include "lcd_1.h"
#include "delay.h"

_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & ICS_PGx2 & FWDTEN_OFF)
_CONFIG2(IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_ON & FNOSC_PRI & POSCMOD_XT)
 
int main()
{
     init_lcd();
 
     lcd("ABCDEFG");
     
   while (1);
}
/**************************************************/
 
 /************************LCD.h*************************/
 
#include "p24FJ128GA010.h"

 
void Init_LCD( void );		        // initialize display
void lcd_cmd( char cmd );	        // write command to lcd
void lcd_data(unsigned char str );		    // write data to lcd
void lcd_data_string(unsigned char *str);
void lcd(unsigned char str [10]);
/************************************************************************/
 
/***********************LCD.c**********************************/
#include "../../support/PIC24F/h/p24FJ128GA010.h"
#include "lcd_1.h"

 
/*
   For Explorer 16 board, here are the data and control signal definitions
   RS -> RB15
   E  -> RD4
   RW -> RD5
   DATA -> RE0 - RE7
*/
 
// Control signal data pins
#define  RW  LATDbits.LATD5       // LCD R/W signal
#define  RS  LATBbits.LATB15      // LCD RS signal
#define  E   LATDbits.LATD4       // LCD E signal
//#define  E   LATFbits.LATF1       // LCD E signal

// Control signal pin direction
#define  RW_TRIS	TRISDbits.TRISD5
#define  RS_TRIS	TRISBbits.TRISB15
#define  E_TRIS		TRISDbits.TRISD4
//#define  E_TRIS		TRISFbits.TRISF1

// Data signals and pin direction
#define  DATA      LATE           // Port for LCD data
#define  DATAPORT  PORTE
#define  TRISDATA  TRISE          // I/O setup for data Port

 

 
void init_lcd(void)
{
    DATA &= 0xFF00;
    RW = 0;                       // R/W state set low
    RS = 0;                       // RS state set low
    E = 0;                        // E state set low

	/* set data and control pins to outputs */
	 TRISDATA &= 0xFF00;
 	RW_TRIS = 0;                  // RW pin set as output
	RS_TRIS = 0;                  // RS pin set as output
	E_TRIS = 0;                   // E pin set as output

	/* LCD initialization sequence */
	DATA &= 0xFF00;
 	   lcd_cmd(0x0038);
   	 lcd_cmd(0x000E);
   
}
 
void lcd_cmd( char cmd )          // subroutiune for lcd commands
{
//  TRISD &= 0xFF00;              // ensure RD0 - RD7 are outputs
    DATA &= 0xFF00;               // prepare RD0 - RD7
    DATA |= cmd;                  // command byte to lcd
    RW = 0;                       // ensure RW is 0
    RS = 0;
    E = 1;                        // toggle E line
    Nop();
    Nop();
    Nop();
    E = 0;
}
 
void lcd_data(unsigned char str )        // subroutine for lcd data
{
//  TRISD &= 0xFF00;              // ensure RD0 - RD7 are outputs
    RW = 0;                         // ensure RW is 0
    RS = 1;                       // assert register select to 1
    DATA &= 0xFF00;               // prepare RD0 - RD7
    DATA |= str;                 // data byte to lcd
    E = 1;
    Nop();
    Nop();
    Nop();
    E = 0;                       // toggle E signal
    RS = 0;                      // negate register select to 0
}
 
void lcd_data_string(unsigned char *str)
{
    int i=0;
    while(str[i]!='\0');
    {
        lcd_data(str[i]);
        i++;
        delay_sec(2);
    }
}
 
void lcd(unsigned char str[10])
{
 
    lcd_cmd(0x0001);
    lcd_cmd(0x0080);
    lcd_data_string(str);
}
/********************************************************************************/
 
/***************Delay.h*******************/
#include "p24FJ128GA010.h"
#include "lcd_1.h"

#define Fosc 8000000                    // FRC Fosc = 8MHz

 
void delay_sec(unsigned char seconds);
 

/********************************************/
 /**************************************delay.c************************************/
include "p24FJ128GA010.h"
#include "lcd_1.h"
#include "delay.h"

void delay_sec(unsigned char seconds)
{
    unsigned char i,j;
    for(i=0;i<seconds;i++)>
        for(j=0;j<10000;j++);
}
 
/****************************************************************************/
Posted 9-Dec-12 20:03pm
Edited 9-Dec-12 22:35pm
v3
Comments
OriginalGriff at 10-Dec-12 3:10am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Member 9671224 at 10-Dec-12 3:22am
   
what u want more?
OriginalGriff at 10-Dec-12 3:26am
   
"i stuck with delay can u plz help me"
 
Doesn't really tell us much - we have no idea what LCD you are using, what speed it need, what processor speed you are running, what delay you are talking about, where you need it, what value you ned it to be, etc., etc., etc.
 
Think about it: if the code you have pasted was all you had, what would you answer?
Member 9671224 at 10-Dec-12 3:40am
   
okk. i m working on explorer 16 board using MPLABX IDE 1.0. I want to display sting on 16X2 lcd on the board. Fosc is 8MHz. i want delay after sending data to LCD. I m stuck with delay subroutine can u help me?
YvesDaoust at 10-Dec-12 3:47am
   
The answer is platform (OS) dependent. You tell us nothing about it.
Member 9671224 at 10-Dec-12 3:49am
   
there is no any OS

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Declare j to be volatile and time your routine.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100