Mutad0r
Junior Member level 3
- Joined
- Feb 13, 2013
- Messages
- 28
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,608
/*CONFIGURATION*/
#pragma config OSC=INTOSCPLL
#pragma config WDTEN = OFF
#pragma config XINST = OFF
#define _XTAL_FREQ 8000000
/*INCLUDES*/
#include <stdio.h>
#include <stdlib.h>
#include <p18cxxx.h>
#include <pconfig.h>
#include <xc.h>
#include <I2C.h>
#include <plib.h>
#define RW_PIN LATDbits.LATD1 /* PORT for RW */
#define TRIS_RW TRISDbits.TRISD1 /* TRIS for RW */
#define RS_PIN LATDbits.LATD0 /* PORT for RS */
#define TRIS_RS TRISDbits.TRISD0 /* TRIS for RS */
#define E_PIN LATDbits.LATD2 /* PORT for E */
#define TRIS_E TRISDbits.TRISD2 /* TRIS for E */
void Onetime_Setup(void);
void I2COMM(void);
void init_LCD(void);
void LCD_DATA(unsigned char DB7,unsigned char DB6,unsigned char DB5,unsigned char DB4)
{
LATDbits.LATD7=DB7;
LATDbits.LATD6=DB6;
LATDbits.LATD5=DB5;
LATDbits.LATD4=DB4;
RW_PIN=0;
E_PIN=1;
__delay_us(500);
E_PIN=0;
}
int main()
{
Onetime_Setup();
init_LCD();
while(1)
{
///////////////////
RS_PIN=1;
LCD_DATA(0,1,0,0);
__delay_ms(1);
RS_PIN=1;
LCD_DATA(1,0,0,0);
__delay_ms(1);
//////////////
///////////////////
RS_PIN=1;
LCD_DATA(0,1,1,0);
__delay_ms(1);
RS_PIN=1;
LCD_DATA(0,1,0,1);
__delay_ms(1);
//////////////
///////////////////
RS_PIN=1;
LCD_DATA(0,1,1,0);
__delay_ms(1);
RS_PIN=1;
LCD_DATA(1,1,0,0);
__delay_ms(1);
//////////////
///////////////////
RS_PIN=1;
LCD_DATA(0,1,1,0);
__delay_ms(30);
RS_PIN=1;
LCD_DATA(1,1,0,0);
__delay_ms(1);
///////////////////
RS_PIN=1;
LCD_DATA(0,1,1,0);
__delay_ms(1);
RS_PIN=1;
LCD_DATA(1,1,1,1);
__delay_ms(1);
//////////////
//////////////
} //WHILE(1) END
} //MAIN() END
//--------------------------PERSONAL FUNCTIONS------------------------------
void Onetime_Setup() //Setup at start of main()
{
//SETUP PORTS//
TRISA=0b11111111;
TRISB=0b11111111;
TRISC=0b11111111;
TRISD=0b00001000;
//PORT SETUP END//
RW_PIN=0;
E_PIN=0;
RS_PIN=0;
}
void init_LCD(void){
__delay_ms(30);
__delay_ms(30);
//INITIALIZE
RS_PIN=0;
LCD_DATA(0,0,1,1);
__delay_ms(30);
RS_PIN=0;
LCD_DATA(0,0,1,1);
__delay_ms(10);
RS_PIN=0;
LCD_DATA(0,0,1,1);
__delay_ms(5);
//SET 4BIT, LINES, FONT
RS_PIN=0;
LCD_DATA(0,0,1,0);
__delay_ms(2);
RS_PIN=0;
LCD_DATA(1,0,0,0);
__delay_ms(2);
//wHATEVAS
RS_PIN=0;
LCD_DATA(0,0,0,0);
__delay_ms(2);
RS_PIN=0;
LCD_DATA(1,1,0,0);
__delay_ms(2);
RS_PIN=0;
LCD_DATA(0,0,0,0);
__delay_ms(2);
RS_PIN=0;
LCD_DATA(0,0,0,1);
__delay_ms(2);
RS_PIN=0;
LCD_DATA(0,0,0,0);
__delay_ms(2);
///final
RS_PIN=0;
LCD_DATA(0,1,1,1);
__delay_ms(2);
}
#include <p18cxxx.h>
/*CONFIGURATION*/
#pragma config OSC=INTOSCPLL
#pragma config WDTEN = OFF
#pragma config XINST = OFF
#define _XTAL_FREQ 8000000
/*INCLUDES*/
#include <stdio.h>
#include <stdlib.h>
#include <p18cxxx.h>
#include <pconfig.h>
#include <xc.h>
#include <I2C.h>
#include <plib.h>
#define RW_PIN LATDbits.LATD1 /* PORT for RW */
#define TRIS_RW TRISDbits.TRISD1 /* TRIS for RW */
#define RS_PIN LATDbits.LATD0 /* PORT for RS */
#define TRIS_RS TRISDbits.TRISD0 /* TRIS for RS */
#define E_PIN LATDbits.LATD2 /* PORT for E */
#define TRIS_E TRISDbits.TRISD2 /* TRIS for E */
void Onetime_Setup(void);
void I2COMM(void);
void init_LCD(void);
void LCD_DATA(unsigned char dat) // function to send data
{
RW_PIN=0;
RS_PIN = 1;
dat = dat & 0xF0; // send higher nibble first
PORTD |=dat; // ORing with control lines and data
E_PIN=1;
__delay_us(500);
E_PIN=0;
dat = dat << 4;
dat = dat & 0xF0; // send lower nibble second
PORTD |=dat; // ORing with control lines and data
E_PIN=1;
__delay_us(500);
E_PIN=0;
}
void LCD_COMMAND(unsigned char dat)
{
RW_PIN=0;
RS_PIN = 0;
dat = dat & 0xF0; // send higher nibble first
PORTD |=dat; // ORing with control lines and data
E_PIN=1;
__delay_us(500);
E_PIN=0;
dat = dat << 4;
dat = dat & 0xF0; // send lower nibble second
PORTD |=dat; // ORing with control lines and data
E_PIN=1;
__delay_us(500);
E_PIN=0;
}
int main()
{
Onetime_Setup();
init_LCD();
while(1)
{
} //WHILE(1) END
} //MAIN() END
//--------------------------PERSONAL FUNCTIONS------------------------------
void Onetime_Setup() //Setup at start of main()
{
//SETUP PORTS//
TRISA=0b11111111;
TRISB=0b11111111;
TRISC=0b11111111;
TRISD=0b00001000;
//PORT SETUP END//
RW_PIN=0;
E_PIN=0;
RS_PIN=0;
}
void init_LCD(void){
__delay_ms(30);
//INITIALIZE
__delay_ms(30);
LCD_COMMAND(0x03);
__delay_ms(30);
LCD_COMMAND(0x03);
__delay_ms(30);
LCD_COMMAND(0x03); // use such function to send coomands
__delay_ms(30);
LCD_COMMAND(0x02);
__delay_ms(30);
LCD_COMMAND(0x28);
__delay_ms(30);
LCD_COMMAND(0x01);
__delay_ms(30);
LCD_COMMAND(0x0c);
__delay_ms(30);
}
but all I get from the LCD is all the pixels in the top row lit.
Zip and post your Proteus file.
Ground RW pin as u don't need RW pin for writing operation. Also try with D0-D4 instead of D4-D7 initially then change hardware pin after ur LCD work,
/*
* File: newmain.c
* Author: Maarek Aabmets
*
* Created on 4. maaliskuuta 2013, 9:49
*/
/*CONFIGURATION*/
#pragma config OSC=INTOSCPLL
#pragma config WDTEN = OFF
#pragma config XINST = OFF
#define _XTAL_FREQ 8000000
/*INCLUDES*/
//#include <inputread.h> //Personal Header
#include <stdio.h>
#include <stdlib.h>
#include <p18cxxx.h>
#include <pconfig.h>
#include <xc.h>
#include <I2C.h>
#include <plib.h>
#define RW_P LATDbits.LATD1 /* PORT for RW */
#define RS_P LATDbits.LATD0 /* PORT for RS */
#define E_P LATDbits.LATD2 /* PORT for E */
void Onetime_Setup(void);
void I2COMM(void);
void init_LCD(void);
void LCD_DATA(unsigned char);
void LCD_COMM(unsigned char);
unsigned char TEMP, REPEAT;
int main()
{
REPEAT=0;
while (REPEAT<100)
{
__delay_ms(30);
REPEAT++;
}
REPEAT=0;
Onetime_Setup();
init_LCD();
LCD_DATA(0b00110001);
LCD_DATA(0b00110010);
LCD_DATA(0b00110011);
LCD_DATA(0b00110100);
LCD_DATA(0b00110101);
LCD_DATA(0b00110110);
LCD_DATA(0b00110111);
while(1)
{
} //WHILE(1) END
} //MAIN() END
//--------------------------PERSONAL FUNCTIONS------------------------------
void Onetime_Setup() //Setup at start of main()
{
//SETUP PORTS//
TRISA=0b11111111;
TRISB=0b11111111;
TRISC=0b11111111;
TRISD=0b00001000;
//PORT SETUP END//
RW_P=0;
E_P=0;
RS_P=0;
}
void init_LCD(void)
{
/////////INITIALS
PORTD= 0b00110000;
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_ms(30);
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_ms(30);
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_ms(30);
/////////INITIALSEND NOW S ET 4 BIT MODE
PORTD= 0b00100000;
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_ms(30);
//////NOW IS 4 BIT MODE
LCD_COMM(0b00101000);
__delay_ms(30);
LCD_COMM(0b00001000);
__delay_ms(30);
LCD_COMM(0b00000001);
__delay_ms(30);
LCD_COMM(0b00000110);
__delay_ms(30);
LCD_COMM(0b00001111);
__delay_ms(30);
}
void LCD_DATA(unsigned char BYTE)
{
TEMP= BYTE & 0b11110000;
PORTD= TEMP;
RS_P=1;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_us(500);
BYTE = BYTE << 4;
TEMP= BYTE & 0b11110000;
PORTD= TEMP;
RS_P=1;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_us(500);
}
void LCD_COMM(unsigned char BYTE)
{
TEMP= BYTE & 0b11110000;
PORTD= TEMP;
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_us(500);
BYTE = BYTE << 4;
TEMP= BYTE & 0b11110000;
PORTD= TEMP;
RS_P=0;
RW_P=0;
E_P=1;
__delay_us(500);
E_P=0;
__delay_us(500);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?