Hola a todos, llevo unos dias intentado sacar algo por el LCD con este dspic y no e sido capaz..., ya me toy empezando a cansar!!!, lo primero que hice fue modificar la libreria k trae el C30 para utilizar el 30f2010, pero no me di cuenta de k solo valia para el controlador LCD PCOG1602B, y no para el hitachi. Despues encontre algo por interne e intente probarlo pero no he sido capaz de sacar nada, parece k no se inicializa el LCD, me aparece la primera linea del LCD en negra, ya nose lo que hacer, aver si alguien me pude ayudar GRACIAASS!!!
#include "p30f2010.h"
_FOSC(XT_PLL8); //PLLx16 y modo XT
_FWDT(WDT_OFF); //WatchDog timer OFF
void lcd_line1(void); //function prototypes
void lcd_line2(void);
void lcd_cmd(unsigned char);
void lcd_char(char);
void e_togg(void);
void lcd_init(void);
void lcd_string(char *);
void lcd_busy(void);
void delay(void);
void beep(int);
#define E LATBbits.LATB1
#define RS LATBbits.LATB0
#define RW LATDbits.LATD0
#define busyflag PORTBbits.RB5
#define RW_TrisBit TRISDbits.TRISD0
#define D7_TrisBit TRISBbits.TRISB5
char sentence1[] = "dsPIC 30F4013 ";
char sentence2[] = "Two UARTs ";
char sentence3[] = "Four 16-bit PWM";
char sentence4[] = "33 interrupts ";
int main(void)
{
ADPCFG = 0xffff; //all digital
TRISB = 0;
TRISC = 0;
TRISD = 0;
RW = 0; //set R/W low
E = 0; //set E low
lcd_busy(); //wait for LCD to settle
lcd_init();
while(1)
{
lcd_line1();
lcd_string(sentence1); //send string to LCD
lcd_line2();
lcd_string(sentence2);
delay();
lcd_line1();
lcd_string(sentence3); //send string to LCD
lcd_line2();
lcd_string(sentence4);
delay();
}
return 0;
}
void lcd_string(char *senpoint)
{
while(*senpoint != '\0')
{
lcd_char(*senpoint);
senpoint++;
}
}
void lcd_busy(void)
{
RW_TrisBit = 1; //make R/W input (read)
D7_TrisBit = 1; //make D7 input
RS = 0; //set RS low
RW = 1; //set R/W high
E = 1; //set E high
while(busyflag); //wait for busy flag to go low
E = 0; //set E low
RW = 0; //set R/W low
TRISB = 0; //make D7 output
RW_TrisBit = 0; //make R/W output (write)
}
void lcd_line1(void)
{
lcd_cmd(0x80);
}
void lcd_line2(void)
{
lcd_cmd(0xc0);
}
void lcd_cmd(unsigned char letter)
{
LATB = letter; //put char in PORTB
lcd_busy();
PORTB = PORTB << 5; //shift over to output high 4 bits on RB9,10,11,12
RS = 0; //RS low
e_togg(); //latch the data
PORTB = PORTB << 4; //shift over to output low 4 bits
RS = 0; //RS low
e_togg(); //latch it
}
void lcd_char(char letter)
{
LATB = letter; //put char in PORTB
lcd_busy();
PORTB = PORTB << 5; //shift over to output high 4 bits on RB9,10,11,12
RS = 1; //RS high
e_togg(); //latch the data
PORTB = PORTB << 4; //shift over to output low 4 bits
RS = 1; //RS high
e_togg(); //latch it
}
void lcd_init(void)
{
LATB = 0x000C; //send 3
e_togg();
lcd_busy();
LATB = 0x000C;
e_togg();
lcd_busy();
LATB = 0x000C;
e_togg();
lcd_busy();
LATB = 0x0008; //send 2 - set 4-bit mode
e_togg();
lcd_busy();
lcd_cmd(0x28); //set 4-bit mode and 2 lines
lcd_busy();
lcd_cmd(0x10); //cursor move & shift left
lcd_busy();
lcd_cmd(0x06); //entry mode = increment
lcd_busy();
lcd_cmd(0x0d); //display on - cursor blink on
lcd_busy();
lcd_cmd(0x01); //clear display
lcd_busy();
}
void e_togg(void)
{
E=1;
E=0;
}
void delay(void)
{
int x,y;
for(x=0;x<50;x++)
{
for(y=0;y<10000;y++){}
}