Sunteți pe pagina 1din 8

8051 controller

INTERFACING 162 LCD DISPLAY


Schematic

Above is the quite simple schematic. The LCD panel's Enable and Register Select is connected to the Control Port. The Control Port is an open collector / open drain output. While most Parallel Ports have internal pull-up resistors, there are a few which don't. Therefore by incorporating the two 10K external pull up resistors, the circuit is more portable for a wider range of computers, some of which may have no internal pull up resistors. We make no effort to place the Data bus into reverse direction. Therefore we hard wire the R/W line of the LCD panel, into write mode. This will cause no bus conflicts on the data lines. As a result we cannot read back the LCD's internal Busy Flag which tells us if the LCD has accepted and finished processing the last instruction. This problem is overcome by inserting known delays into our program. The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with all the examples, I've left the power supply out. You can use a bench power supply set to 5v or use a onboard +5 regulator. Remember a few de-coupling capacitors, especially if you have trouble with the circuit working properly

LCD Program:#include sfr ldata=0x80; sbit rs=P2^0;

sbit rw=P2^1; sbit en=P2^2; void lcdcmd(unsigned char value); void lcddata(unsigned char value); void delay(unsigned int time); unsigned int i,j; void main() { lcdcmd(0x38); // to initialize lcd matrix while(1) { lcdcmd(0x01); // clear screen lcdcmd(0x06); // increment curcer lcdcmd(0x0e); // display on cursur blinking lcdcmd(0x83); // force cursor 1st line 4th coloumn lcddata('W'); delay(50); lcddata('e'); delay(50); lcddata('l'); delay(50); lcddata('c'); delay(50); lcddata('o'); delay(50); lcddata('m'); delay(50); lcddata('e'); delay(50); lcddata(' '); lcddata('t'); delay(50); lcddata('o'); lcdcmd(0xc6); //force cursor to 2nd line 6th coloumn delay(50); lcddata('G'); delay(50); lcddata('U'); delay(50); lcddata('Y'); delay(50); lcddata('S'); delay(1000); lcdcmd(0x01); // clear screen lcdcmd(0x80); // force cursor 1st line 1st coloumn lcddata('D');

delay(50); lcddata('e'); delay(50); lcddata('s'); delay(50); lcddata('i'); delay(50); lcddata('g'); delay(50); lcddata('n'); delay(50); lcddata('e'); delay(50); lcddata('d'); delay(50); lcddata(' '); lcddata('b'); delay(50); lcddata('y'); delay(50); lcddata(':'); delay(50); lcddata('-'); lcdcmd(0xc3); // force cursor to 2nd line 3rd coloumn delay(50); lcddata('H'); delay(50); lcddata('A'); delay(50); lcddata('R'); delay(50); lcddata('M'); delay(50); lcddata('A'); delay(50); lcddata('N'); delay(50); lcddata(''); delay(50); lcddata('S'); delay(50); lcddata('i'); delay(50); lcddata('n'); delay(50); lcddata('g');

delay(50); lcddata('h'); lcdcmd(0x0c); // disply on cursor off delay(1000); } } void lcdcmd(unsigned char value) { ldata=value; rs=0; // rs 0 to signify commmand mode rw=0; en=1; delay(1); en=0; } void lcddata(unsigned char value) { ldata=value; rs=1; // rs 1 to signify data mode rw=0; en=1; delay(1); en=0; }void delay(unsigned int time) { for(i=0;i for(j=0;j<1275;j++); }

INTERFACING Seven Segment Display


A seven-segment display (abbreviation: "7-seg(ment) display"), less commonly known as a seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information. In a simple LED package, each LED is typically connected with one terminal to its own pin on the outside of the package and the other LED terminal connected in common with all other LEDs in the device and brought out to a shared pin. This shared pin will then make up all of the cathodes (negative terminals) OR all of the anodes (positive terminals) of the LEDs in the device; and so will be either a "Common Cathode" or "Common Anode" device depending how it is constructed. Hence a 7 segment plus DP package will only require nine pins to be present and connected. LED + 7-Segment Program:#include

unsigned int i; void delay(); void led(); void main() { while(1) { P3=0x03; led(); P3=0x9f; led(); P3=0x25; led(); P3=0x0d; led(); P3=0x99; led(); P3=0x49; led(); P3=0x41; led(); P3=0x1f; led(); P3=0x01; led(); P3=0x09; led(); } } void led() { P1=0x7e; delay(); P1=0xbd; delay();

P1=0xdb; delay(); P1=0xe7; delay(); P1=0xdb; delay(); P1=0xbd; delay(); P1=0x7e; delay(); } void delay() { for(i=0;i<20000;i++) { } }

INTERFACING LEDs
Light emitting diodes, commonly called LEDs, are real unsung heroes in the electronics world. They do dozens of different jobs and are found in all kinds of devices. Among other things, they form the numbers on digital clocks, transmit information from remote controls, light up watches and tell you when your appliances are turned on. Collected together, they can form images on a jumbo television screen or illuminate a traffic light. Basically, LEDs are just tiny light bulbs that fit easily into an electrical circuit. But unlike ordinary incandescent bulbs, they don't have a filament that will burn out, and they don't get especially hot. They are illuminated solely by the movement of electrons in a semiconductor material, and they last just as long as a standard transistor. In communication kit we have solderd 8 LEDs which are fed with Vcc; They are connected to the port of microcontroller through 220 resistances. To glow a LCD we have to connect ground at one terminal of LED as other end is already connected to Vcc itself. So 8051 con troller give 0 to a LED to make it glow LED program:#include int i; void delay(); void main() {

while(1) { P1=0x7f; delay(); P1=0xbf; delay(); P1=0xdf; delay(); P1=0xef; delay(); P1=0xf7; delay(); P1=0xfb; delay(); P1=0xfd; delay(); P1=0xfb; delay(); P1=0xf7; delay(); P1=0xef; delay(); P1=0xdf; delay(); P1=0xbf; delay(); } } void delay() { for(i=0;i<20000;i++) { } }

S-ar putea să vă placă și