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
So, I have searched the forum, and asked my teacher, and everything seems to be correct,but it doesn¨t work!
I have a 3,3v PIC Communicating with a 5v LCD in 4-bit mode, I'm using 5v tolerant pins and the lcd logic has minimum of 2.2V.
I have measured all the pins and they all rise and fall as they should, but all I get from the LCD is all the pixels in the top row lit. I'm at a loss of what to do at this point, and hope someone spots whatever I have done wrong.
I have a 3,3v PIC Communicating with a 5v LCD in 4-bit mode, I'm using 5v tolerant pins and the lcd logic has minimum of 2.2V.
I have measured all the pins and they all rise and fall as they should, but all I get from the LCD is all the pixels in the top row lit. I'm at a loss of what to do at this point, and hope someone spots whatever I have done wrong.
Code:
/*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);
}