need help with a project

Thread Starter

foxawy

Joined Dec 10, 2011
14
i put a 1us delay between after every line in the code coz according to the lcd timing diagram its about 300ns, the other group used Lcd_init(&PORTD), but it doesn't work/build in mikro c pro. here is our final code till now , THX FOR THE HELP.
Rich (BB code):
sbit LCD_RS at RA3_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISA3_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D0_Direction at TRISD0_bit;

#define RS PORTA.RA3
#define E PORTA.RA1
#define RW PORTA.RA2


unsigned int temp_res;
void MSDelay(unsigned int d);

void main(void) {
unsigned int t;

char Temp[8];
ADCON0=0x81;
ADCON1=0x8E;
TRISA=0x01;
TRISC=0;
TRISD=0;
TRISE=0;
PORTE=0x1;

do {
    temp_res = ADC_Read(0);   // Get 10-bit results of AD conversion
    temp_res = temp_res *0.486;
    PORTD =  temp_res ;      // Send lower 8 bits to PORTD


    t=PORTD;
    inttostr(t,Temp);
    
    RS=0;                      // initiating the LCD
    RW=0;
    delay_us(1);
    E=1;
    delay_us(1);
    LCD_init();
    delay_us(1);
    E=0;
    delay_us(1);
    
    RS=0;                   // Clearing the LCD Display
    RW=0;
    delay_us(1);
    E=1;
    delay_us(1);
    Lcd_Cmd(_LCD_CLEAR);
    delay_us(1);
    E=0;
    delay_us(1);
    
    RS=1;                    // Writing Temperature to the LCD
    RW=0;
    delay_us(1);
    E=1;
    delay_us(1);
    lcd_out(1,4,"Temp.");
    E=0;
    delay_ms(1);
    
    RS=1;                    // Writing Temperature Value to the LCD
    RW=0;
    delay_us(1);
    E=1;
    delay_us(450);
    lcd_out(2,5,Temp);
    E=0;
    
    if(t>=20 && t<30)
    {
    PORTC=0x2;
    }
    else if(t>=30)
    {
    PORTC=0x2;
    PORTC=0x3;
    
    }
    else
    {
    PORTC=0X0;
    }
    
    RS=0;                   // Removing the cursor
    RW=0;
    delay_us(1);
    E=1;
    delay_us(1);
    Lcd_Cmd(_LCD_CURSOR_OFF);
    delay_us(1);
    E=0;
    delay_us(1);

  } while(1);



}
 

thatoneguy

Joined Feb 19, 2009
6,359
You need 15 uS between init and commands, and another 15uS between commands and text input. Also something like 50uS between power on and init, but that should be covered by the code prior to the LCD stuff.

It should work fine if you extend those 2 delays slightly.
 

Thread Starter

foxawy

Joined Dec 10, 2011
14
i have a bigger problem now , i had a PIC with the a simple "microelektronika" display on it , and works fine i removed it and put another PIC with the project program didn't work so removed it and put back the microelektronica pic ,, it doesn't display.?????
 

thatoneguy

Joined Feb 19, 2009
6,359
Did you move any jumpers or switches?

Did a pin get bent when putting the PIC into the socket?

Was the LCD removed and replaced one pin off?
 
Top