??? 02/15/10 04:42 Modified: 02/15/10 05:22 Read: times |
#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); } } } |
Topic | Author | Date |
Help with LCD code ( something vague happening here ) | 01/01/70 00:00 | |
Better attention to detail? | 01/01/70 00:00 | |
The LCD works but... | 01/01/70 00:00 | |
Reset; Timing | 01/01/70 00:00 | |
Yes I did | 01/01/70 00:00 | |
No, that doesn't follow | 01/01/70 00:00 | |
Flashing LED![]() | 01/01/70 00:00 | |
Hopefull the code will appear in the right place now. | 01/01/70 00:00 | |
built in simulator does not proces "sec_cnt" at all. | 01/01/70 00:00 | |
Simulator | 01/01/70 00:00 | |
What tools? | 01/01/70 00:00 | |
does the LED blink? | 01/01/70 00:00 | |
Thank you | 01/01/70 00:00 |