Hi, i have been triying to initiate the lCD with the pic18f4550 but i can´t. I dont have and idea.
I paste mi code, if anyone can help. Thanks
I paste mi code, if anyone can help. Thanks
Code:
#include <p18f4550.h>
#define E PORTAbits.RA5
#define RS PORTAbits.RA4
#define D7 PORTAbits.RA0
#define D6 PORTAbits.RA1
#define D5 PORTAbits.RA2
#define D4 PORTAbits.RA3
#define Clean_Display 0x01
#define Go_Home 0x02
#define Autoshift_right 0x07
#define Autoshift_left 0x05
#define All_On 0x0F
#define Display_On 0x0C
#define Cursor_On 0x0E
#define _8Bit_2Lines 0x38
#define _4Bit_2Lines 0x28
#define _4bit_10dots 0x2C
#define DDRAM_Home 0x80 //move cursor display
#define DDRAM_Line2 0xA8 //move cursor display low bit
unsigned char line = 0;
void wait_ms(int tiempo_ms) //Función de esperar un segundo.
{
int temp;
int x;
temp=tiempo_ms;
x=0; //variable utilizada para el tiempo
// INTCON2=0b00000100; //Option - configuracion del preescaler
// T0CON=0b00000001;
do
{
TMR0=6; do{x=x+1;} while (x<550);
x=0;
temp=--temp;
}
while (temp!=0);
}
void LCD_Write_Nibble(unsigned char data) {
if (data & 8) {
D7 = 1;
} else {
D7 = 0;
}
if (data & 4) {
D6 = 1;
} else {
D6 = 0;
}
if (data & 2) {
D5 = 1;
} else {
D5 = 0;
}
if (data & 1) {
D4 = 1;
} else {
D4 = 0;
}
wait_ms(10);
E = 1;
wait_ms(20);
E = 0;
}
void LCD_Write_Byte (char data)
{
LCD_Write_Nibble(data >> 4);
LCD_Write_Nibble(data);
}
/*************************************************************************************************/
/********************* exported Functions **********************/
/*************************************************************************************************/
void LCD_Init(void) {
D4=0;
D5=0;
D6=0;
D7=0;
wait_ms(20);
E = 0;
RS = 0;
LCD_Write_Nibble(0x30);
wait_ms(30);
LCD_Write_Nibble(0x30);
wait_ms(30);
LCD_Write_Nibble(0x30);
wait_ms(30);
LCD_Write_Nibble(0x20);
LCD_Write_Byte(_4Bit_2Lines); // Configure LDC for 4 bits
LCD_Write_Byte(Clean_Display); // Clean display
LCD_Write_Byte(Cursor_On); // Turn on display, cursor
LCD_Write_Byte(DDRAM_Home); // Set the DDRAM position to
}
void LCD_Skip_Line(void) {
RS = 0;
if(line) {
LCD_Write_Byte(DDRAM_Home);
line = 0;
} else {
LCD_Write_Byte(DDRAM_Line2);
line = 1;
}
}
char LCD_Get_Line() {
return line;
}
void LCD_Write_String(char data) {
RS = 1;
LCD_Write_Byte(data);
}
unsigned char mensaje[]={"Hola mundo"};
void main (void){
ADCON1=0x0F;
wait_ms(200);
unsigned char i;
TRISD=0;
TRISB=0;
D4=0;
D5=0;
D6=0;
D7=0;
E=0;
RS=0;
wait_ms(5);
LCD_Init();
wait_ms(5);
i=0;
do
{
LCD_Write_String(mensaje[i++]);
} while (mensaje[I]!=0);
do{}
while(1);
}
Last edited by a moderator: