haronraziq
Newbie level 6
- Joined
- Apr 3, 2011
- Messages
- 14
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,449
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 // 4 bit example #include<reg51.h> #define LCD P1 //port 1 #define LCD_EN 0x80 #define LCD_RS 0x20 //LCD Commands #define LCD_SETMODE 0x04 #define LCD_SETVISIBLE 0x08 #define LCD_SETFUNCTION 0x28 #define LCD_SETDDADDR 0x80 void delayms(unsigned char); void delayus(unsigned char); void lcd_init(); void lcd_reset(); void lcd_cmd (char); void lcd_data(unsigned char); void lcd_str (unsigned char*); void main (void) { lcd_init(); lcd_cmd(0x80); // ist line address lcd_str(" i love "); lcd_cmd(0xC0); // 2nd line address lcd_str("romel"); while(1); } void delayus(unsigned char delay){ while(delay--); } void delayms(unsigned char delay){ while(delay--) delayus(149); } void lcd_reset() //reset LCD { LCD = 0xFF; delayms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delayms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delayms(5); LCD = 0x03+LCD_EN; LCD = 0x03; delayms(5); LCD = 0x02+LCD_EN; LCD = 0x02; delayms(5); } void lcd_init () //initialize LCD { lcd_reset(); lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font. lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink. lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift. lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h. } void lcd_cmd (char cmd) { LCD = ((cmd >> 4) & 0x0F)|LCD_EN; LCD = ((cmd >> 4) & 0x0F); LCD = (cmd & 0x0F)|LCD_EN; LCD = (cmd & 0x0F); delayus(250); delayus(250); } void lcd_data (unsigned char dat) { LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS); LCD = (((dat >> 4) & 0x0F)|LCD_RS); LCD = ((dat & 0x0F)|LCD_EN|LCD_RS); LCD = ((dat & 0x0F)|LCD_RS); delayus(250); delayus(250); } void lcd_str (unsigned char *str) //display string to LCD { while(*str){ lcd_data(*str++); } }
**broken link removed**
void
lcd_init()
{
char init_value;
//ADCON1 = 0x06; // Disable analog pins on PORTA//
init_value = 0x3;
TRISC=0;
TRISD=0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(15); // wait 15mSec after power applied,
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2; // Four bit mode
LCD_STROBE();
lcd_write(0x2; // Set interface length
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}
I really appreciate your helping me on this project.
Is the C language for the Keill similar to Hi-tech C?
---------- Post added at 23:47 ---------- Previous post was at 23:45 ----------
Also, the above code is generated for what kind of microcontroller?
#define LCD_EN 0x80
#define LCD_RS 0x20
EN = P0.7
RS = P0.5 P0.7 has address 0x87 and p0.5 has address 0x85
sorry hussain your answer is wrong.....
though i have not touched 8051 from past 6 years i am dam sure you are wrong
the correct answer is
0x80 address corresponds to p0.0 and 0x20 address corresponds to p3.0
so the connected port is P0.0 and P3.0 for rs and en
what the code is doing is performing the operation on port1 which is defined "LCD"LCD = 0x03+LCD_EN;
LCD = 0x03;
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?