Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help in code for pic24f controller

Status
Not open for further replies.

malhi

Newbie level 6
Joined
Nov 13, 2008
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
i have made a code for interfacing LCD with pic24fj128ga010
but i do not have output as a string. i am getting it as numericals which is changing randomly...
i am not able to solve it...........please have i look :!:
---------------------------------------------------------------------------------
#include "p24FJ128GA010.h"
#include "lcd.h"
#include "delay.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
unsigned int temp_count;

const char mytext[] = " PIC24F Demo ";
const char mytext1[] = "hi how r u?";





/****************************************************************************/
/***** LCD SUBROUTINE *****/

void Init_LCD( void ) // initialize LCD display
{
// 15mS delay after Vdd reaches nnVdc before proceeding with LCD initialization
// not always required and is based on system Vdd rise rate
Delay(Delay_15mS_Cnt); // 15ms delay

/* set initial states for the data and control pins */
LATE &= 0xFF0F;
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 */
TRISE &= 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

/* 1st LCD initialization sequence */
DATA &= 0xFF0F;
// DATA |= 0x0038;
DATA |= 0x0000;
E = 1;
Nop();
Nop();
Nop();
E = 0; // toggle E signal
Delay(Delay_5mS_Cnt); // 5ms delay

DATA &= 0xFF0F;
DATA |= 0x0020;
E = 1;
Nop();
Nop();
Nop();
E = 0; // toggle E signal
Delay(Delay_5mS_Cnt); // 5ms delay


}


void lcd_cmd( char cmd ) // subroutiune for lcd commands
{
// TRISD &= 0xFF00; // ensure RD0 - RD7 are outputs
DATA &= 0xFF0F; // 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;
Delay(Delay_5mS_Cnt); // 5ms delay

cmd=cmd<<4;

DATA &= 0xFF0F; // 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;
Delay(Delay_5mS_Cnt); // 5ms delay

}


void lcd_data( char data ) // 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 &= 0xFF0F; // prepare RD0 - RD7
DATA |= data; // data byte to lcd
E = 1;
Nop();
Nop();
Nop();
E = 0; // toggle E signal
RS = 0; // negate register select to 0
Delay_Us( Delay200uS_count ); // 200uS delay
Delay_Us( Delay200uS_count ); // 200uS delay

data=data<<4;
DATA |= data; // data byte to lcd
E = 1;
Nop();
Nop();
Nop();
E = 0; // toggle E signal
RS = 0; // negate register select to 0
Delay_Us( Delay200uS_count ); // 200uS delay
Delay_Us( Delay200uS_count ); // 200uS delay



}

int main(void)
{

/* Initialize LCD Display */
Init_LCD();

/* Welcome message */
home_clr();
puts_lcd( (char*) &mytext[0], sizeof(mytext) -1 );
line_2();
puts_lcd( (char*) &mytext1[0], sizeof(mytext1) -1 );

}



void puts_lcd( unsigned char *data, unsigned char count )
{
while (1)
{
lcd_data( *data++ );
count --;
}
}
void Delay( unsigned int delay_count )
{
temp_count = delay_count +1;
asm volatile("outer: dec _temp_count");
asm volatile("cp0 _temp_count");
asm volatile("bra z, done");
asm ("repeat #1500" );

// asm volatile("do #3200, inner" );
asm volatile("nop");
// asm volatile("inner: nop");
asm volatile("bra outer");
asm volatile("done:");
}


void Delay_Us( unsigned int delayUs_count )
{
temp_count = delayUs_count +1;
asm volatile("outer1: dec _temp_count");
asm volatile("cp0 _temp_count");
asm volatile("bra z, done1");
asm ("repeat #3200" );

// asm volatile("do #1500, inner1" );
asm volatile("nop");
// asm volatile("inner1: nop");
asm volatile("bra outer1");
asm volatile("done1:");
}

:cry::cry::cry:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top