| ??? 02/13/04 21:15 Read: times |
#64753 - C and 8051 |
Hey I am trying to print characters on an LCD using the 8051. I am programming the 8051 in C. So far I have managed to print to lines to the LCD which is a 16*2 LCD. My problem is when I want to clear the LCD and print 2 new lines to it. what happens is that the 2 new lines get mixedup with the old 2 lines of words.
Here is my code so far. #include<aduc812.h> #include<stdio.h> sbit LCD_RS = 0x0B1; //Register Select line = port 3.1 sbit LCD_WR = 0x0B3; //Read/Write line = port 3.3 sbit LCD_EN = 0x0B5; //Enable line = port 3.5 sfr LCD_DATA = 0x080; //Data bus = port 0 sbit busy = 0x087; //busy bit = db7 sfr KEY = 0x0A0; //INPUT PORT 2 void sendcmd(unsigned cmd); void chkbusy(void); //Checks the busy status of the LCD controller void sendchar(unsigned); //Function which sends text to the LCD display void main(void) { data unsigned char buf[16];//Databuffer for text to be displayed data int i=0; for(;;){ sendcmd(0x038); // Initialising the display sendcmd(0x06); //Function set sendcmd(0x02); //Entry set sendcmd(0x0C); //Home //Display on, cursor, etc sprintf(buf, "Jeffrey ");//Move text into the buffer i=0; while (buf[i]!=' ')//Sends text out to LCD display, one charachter at a time { sendchar(buf[i]); i++; } sendcmd(0xC0);//the start of the 2nd line sprintf(buf, "Ryan "); //Move text into the buffer i=0; while (buf[i]!=' ') //Sends text out to LCD display, one charachter at a time { sendchar(buf[i]); i++; } sendcmd(0x01); //Clear LCD????? sprintf(buf, "5 Inglewood"); i=0; while (buf[i]!=' ') { sendchar(buf[i]); i++; } sendcmd(0xC0); sprintf(buf, "Thomondgate "); i=0; while (buf[i]!=' ') { sendchar(buf[i]); i++; } } } /* Function to check the busy status of the LCD controller */ void chkbusy(void) { data int i; data unsigned temp; LCD_DATA = 0x0FF; // configure as ip's LCD_RS = 0x00; // CLEARS RS LINE LCD_WR = 0x01; // SETS R/W LINE i++; i++; i++; i++; do{ LCD_EN = 1; // CLOCKS E HIGH i++; i++; i++; i++; temp = LCD_DATA; i++; i++; i++; LCD_EN = 0; // CLOCKS E LOW i++; i++; } while (busy == 0); } /* Function which sends commands out to the LCD controller */ void sendcmd(unsigned cmd) { data int i; chkbusy(); // CHECKS BUSY FLAG LCD_DATA = cmd; // SENDS TO PORT 0 LCD_WR = 0; //CLEARS R/W LINE LCD_RS = 0; // CLEARS RS LINE i++; LCD_EN = 1; // CLOCKS E HIGH i++; i++; i++; i++; i++; LCD_EN = 0; // CLOCKS E LOW } void sendchar(unsigned ch) { data int i; chkbusy(); LCD_DATA = ch; // SENDS TO PORT 0 LCD_WR = 0; // CLEARS R/W LINE LCD_RS = 1; // SETS RS LINE HIGH FOR DATA i++; LCD_EN = 1;// CLOCKS E HIGH i++; i++; i++; i++; i++; LCD_EN = 0; // CLOCKS E LOW } |
| Topic | Author | Date |
| C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 | |
RE: C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 | |
| RE: C and 8051 | 01/01/70 00:00 |



