Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Vaishakh Chavan
02/14/10 22:42
Modified:
  02/14/10 23:22

Read: 410 times
Mumbai
India


 
#173157 - Help with LCD code ( something vague happening here )
Here is the code that I have written in SPJ for the 89s52 Atmel version chip.
The code after loading on the chip executes only after reset button is pressed a few times. Can someone explain what I'm doing wrong & why the LCD is not initializing or displaying immediately after power up inspite of the exagerated delays included?

Thanks
Monti / Vaishakh


...insert code here
 

#include <Intel8052.h>
#include <standard.h>
// Program is working fine but the LCD does not load the screen after power up.//
// After reset is pressed ( generally two times ) then it's fine //
// Cant figure out what is wrong //

BIT RS P0.0;
BIT RW P0.1;
BIT E P0.2;
BIT LED P2.0;
// data pins to LCD P0.4 to P0.7//
unsigned char p0data;
unsigned char temp;
unsigned char ch;
unsigned char sec_cnt;



interrupt (INT_TMR0) timer0isr () using 1
{
// INT_TMR0 is a #defined constant
// it is defined in STANDARD.H which is #included in this program
// This ISR uses register bank 1
TH0 = 0xd8 ; /*Reload timer */
TL0 = 0xf0 ;
sec_cnt -- ;
if (!sec_cnt)
{
sec_cnt = 1000;
LED = ~LED ;

}
}


void lcd_enable()
{

E=1;
delay(500);
E=0;
delay(2000);
}

void lcd_writecom(unsigned char ch)// writing commands to LCD //
{
unsigned char temp;
temp=ch;
temp= temp & 0xf0;
temp=temp|0x08; // holding P0.3 high //
P0=temp;
lcd_enable();

temp= ( ch << 4s);
// move Lower nibble to higger nibbble //
temp= temp & 0xf0;
temp|=0x08; // holding P0.3 high //
P0=temp;
lcd_enable();
}

void lcd_writetxt(unsigned char ch) // writing data to LCD //
{
unsigned char temp;
temp=ch;
temp= temp & 0xf0;
temp=temp|0x09; // holding P0.3 high & RS set to data mode //
P0=temp;
lcd_enable();

temp= ( ch << 4s);
// move Lower nibble to higger nibbble //
temp= temp & 0xf0;
temp=temp|0x09;
P0=temp;
lcd_enable();
}

void main ()
{
// LCD initialization //
P0=0xff;
delay(5000);
delay(5000);
delay(5000);
delay(5000);
delay(5000);
delay(5000);

p0data=0x08; // unused pin pulled high
P0=p0data;
delay(5000); //lcd_init();// initialize the display
lcd_writecom(0x01);
delay(5000);
delay(5000);
lcd_writecom(0x28);
delay(5000);
lcd_writecom(0x0E);
delay(5000);
lcd_writecom(0x06);
delay(5000);
lcd_writecom(0x0F);
delay(5000);
delay(5000);
delay(5000);
delay(5000);
delay(5000);


TMOD = 0x01 ;
TCON = 0x10 ;
TH0 = 0xd8 ; // Initial value
TL0 = 0xf0 ; // such that Timer0 will overflow every 10 ms
IE = 0x82 ; // enable timer0 interrupt

while(1)
{
lcd_writecom(0x80);
lcd_writetxt('M');
lcd_writetxt('O');
lcd_writetxt('N');
lcd_writetxt('T');
lcd_writetxt('I');
lcd_writecom(0x14);
lcd_writetxt('I');
lcd_writetxt('S');
lcd_writecom(0x14);
lcd_writetxt('K');
lcd_writetxt('I');
lcd_writetxt('N');
lcd_writetxt('G');
if(!LED)
{
lcd_writecom(0xc0);
lcd_writetxt('1');
lcd_writecom(0xc1);
lcd_writetxt('0');
lcd_writecom(0x0c);

}
else
{

lcd_writecom(0xc0);
lcd_writetxt('0');
lcd_writecom(0xc1);
lcd_writetxt('1');
lcd_writecom(0x0c);
}

}

}



List of 13 messages in thread
TopicAuthorDate
Help with LCD code ( something vague happening here )      Vaishakh Chavan      02/14/10 22:42      
   Better attention to detail?      Andy Neil      02/15/10 01:32      
      The LCD works but...      Vaishakh Chavan      02/17/10 01:06      
         Reset; Timing      Andy Neil      02/17/10 01:32      
            Yes I did      Vaishakh Chavan      02/17/10 01:34      
               No, that doesn't follow      Andy Neil      02/17/10 02:09      
                  Flashing LED      Vaishakh Chavan      02/18/10 22:52      
      Hopefull the code will appear in the right place now.      Vaishakh Chavan      02/17/10 01:20      
         built in simulator does not proces "sec_cnt" at all.      Andy Neil      02/17/10 01:33      
            Simulator      Vaishakh Chavan      02/17/10 03:07      
               What tools?      Andy Neil      02/17/10 03:59      
   does the LED blink?      Jan Waclawek      02/15/10 03:14      
      Thank you      Vaishakh Chavan      02/17/10 01:08      

Back to Subject List