You are on page 1of 27

INDEX I Cycle 1. SERIAL COMMUNICATION............................................................2 1(a) SERIAL COMMUNICATION (continuous display of one character)...........

2 1(b) SERIAL COMMUNICATION (display of one name)...................................4 1(c) SERIAL COMMUNICATION (without using arrays display your name).....6 2(b) Real Time Timer..................................................................................... 8 3. LOOK UP TABLE........................................................................11 4. LCD INTERFACE TO 8051...........................................................15 5. ADC& DAC INTERFACE TO 8051.................................................18 5a) ADC....................................................................................................... 18 AIM: To write an 8051 embedded c code for ADC & DAC Interface to 805118 5b) DAC....................................................................................................... 20 6. KEYBOARD...............................................................................23 6a) Keyboard interface to 8051..................................................................23 6b) Interfacing to keyboard using switch case............................................26

1. SERIAL COMMUNICATION 1(a) SERIAL COMMUNICATION (continuous display of one character) AIM: To write an 8051embedded c code for the continuous display of one Character HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to Parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long-haul Communication and most computer networks, where the cost of cable and Synchronization difficulties make parallel communication impractical. Serial Computer buses are becoming more common even at shorter distances, as Improved signal integrity and transmission speeds in newer serial technologies have begun to outweigh the parallel bus's advantage of simplicity (no need for serializer and deserializer, or SerDes) and to outstrip its disadvantages (clock skew, Interconnect density). The migration from PCI to PCI Express is an example. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the Microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include<reg51.h> void main () { TMOD=0x20; SCON=0x50; TH1=0xFD;
2

TR1=1; while (1) { SBUF='A'; while (TI==0); TI=0; } } RESULT: Hence the 8051 embedded c code for the continuous display of one Character is verified

1(b) SERIAL COMMUNICATION (display of one name)


AIM: To write an 8051 embedded c code for the display of one character HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to Parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long-haul Communication and most computer networks, where the cost of cable and Synchronization difficulties make parallel communication impractical. Serial Computer buses are becoming more common even at shorter distances, as Improved signal integrity and transmission speeds in newer serial technologies have begun to outweigh the parallel bus's advantage of simplicity (no need for serializer and deserializer, or SerDes) and to outstrip its disadvantages (clock skew, Interconnect density). The migration from PCI to PCI Express is an example. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the Microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include<reg51.h> #include<stdio.h> void serail_init (void); void serial_init (void) { SCON=0x20; TMOD=0x20;
4

TH1=0xFD; TR1=1; TI=1; } void main (void) { serial_init (); while (1){ printf ("Hello! World\n"); } } RESULT: Hence the 8051 embedded c code for the display of one name is verified

1(c) SERIAL COMMUNICATION (without using arrays display your name)


AIM: To write an8051 embedded c code for the without using arrays display your name HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to Parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long-haul Communication and most computer networks, where the cost of cable and Synchronization difficulties make parallel communication impractical. Serial Computer buses are becoming more common even at shorter distances, as Improved signal integrity and transmission speeds in newer serial technologies have begun to outweigh the parallel bus's advantage of simplicity (no need for serializer and deserializer, or SerDes) and to outstrip its disadvantages (clock skew, Interconnect density). The migration from PCI to PCI Express is an example. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the Microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include<reg51.h> void SerTx (unsigned char); void main (void) { TMOD=0X20;
6

TH1=0XFD; SCON=0X50; TR1=1; while (1) { SerTx ('C'); SerTx ('M'); SerTx ('R'); SerTx ('E'); SerTx ('C'); } } void SerTx (unsigned char x) { SBUF=x; while (TI==0); TI=0; } RESULT: Hence the 8051 embedded c code for the without using arrays display your name is verified

2.TIMERS

2. TIMER

2(b) Real Time Timer


AIM: To study and verify Real time timer HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: Timer is a clock that controls the sequence of an event while counting in fixed intervals of time. A Timer is used for producing precise time delay. Secondly, it can be used to repeat or initiate an action after/at a known period of time. This feature is very commonly used in several applications. An example could be setting up an alarm which triggers at a point of time or after a period of time. Most of the microcontrollers have inbuilt Timers. Timers in a controller not only generate time delays but they can also be used as counters. They are used to count an action or event. The value of counter increases by one, every time its corresponding action or event occurs. Timers in a controller are inbuilt chips that are controlled by special function registers (SFRs) assigned for Timer operations. These SFRs are used to configure Timers in different modes of operations. While working with microcontrollers, it is more than often required to generate time delays. There are two possible ways of generating time delays. First is by using the code, like using for or while loops in a C program. However, the delays provided by the software are not very precise. The other method is to use Timers. Timers provide time delays that are very precise and accurate. Microcontroller has two Timers designated as Timer0 and Timer1. Each of these timers is assigned a 16-bit register. The value of a Timer register increases by one every time a timer counts. Timer takes a time period of one machine cycle to count one. This means that the maximum number of times a timer can count without repeating is 216, i.e., 65536. So the maximum allowed counts in value of Timer registers can be from 0000H to FFFFH. Since 8051 is an 8 bit controller, the registers of 8051 Timers are accessed as two different registers; one for lower byte and other for higher byte. For example, register of Timer0 is accessed as TL0 for lower byte and TH0 for higher byte. Similarly TL1 and TH1 are registers assigned to Timer 1. While using 8051 Timers certain factors need to be considered, like whether the Timer is to be used for time keeping or for counting; whether the source for time generation is

external clock or the controller itself; how many bits of Timer register are to be used or left unused. The registers of Timers are loaded with some initial value. The value of a Timer register increases by one after every machine cycle. One machine cycle duration is the 1/12th of the frequency of the crystal attached to the controller. A register called TMOD is used for configuring the Timers for the desired operation. TMOD is an 8-bit register with following bit configuration: The lower four bits (TMOD.0 TMOD.3) are used to configure Timer 0 while the higher four bits (TMOD.4 TMOD.7) are for Timer 1. When GATE is high, the corresponding Timer is enabled only when there is an interrupt at corresponding INTx pin of AT89C51 controller and Timer control bit is high. Otherwise only setting Timer control bit is sufficient to start the Timer. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: Timer interrupts #include<stdio.h> #include<reg51.h> sbit pin=P1^5; void timer1_int (); void main () { AUXR=0x10; EA=1; timer1_int (); While (1); } Void timer1_int () { TMOD=0x10; TH1=0x4B; TL1=0xFE; TR1=1; ET1=1; } timer1_isr () interrupt 3 {
9

pin=~pin; TF1=0; TH1=0x4B; TL1=0xFE; } Timer 0 Interrupt #include<stdio.h> #include<reg51.h> sbit pin=P1^5; void timer0_int (); void main () { timer0_int (); EA=1; while (1); } void timer0_int () { TMOD=0x02; TH0=0x4B; TL0=0xFE; TR0=1; ET0=1; } timer0_isr () interrupt 1 { pin=~pin; TF0=0; TH0=0x4B; TL0=0Xff; }

10

3. LOOK UP TABLE
AIM: To write an 8051 embedded c code for the look up table HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: A lookup table is a data structure, usually an array or associative array, often used to replace a runtime computation with a simpler array indexing operation. The savings in terms of processing time can be significant, since retrieving a value from memory is often faster than undergoing an 'expensive' computation or input/output operation. The tables may be pre calculated and stored in static program storage or calculated (or "perfected") as part of a programs initialization phase (memorization). Lookup tables are also used extensively to validate input values by matching against a list of valid (or invalid) items in an array and, in some programming languages, may include pointer functions (or Offsets to labels) to process the matching input PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the microcontroller evaluation board 6) Result obtained is viewed in corresponding ports. SOURCE CODE: #include<stdio.h> #include<reg51.h> #include<intrins.h> void start (void); unsigned char ReadNVROM (void); void Stop (void); #define ACK 1 #define NO_ACK 0 #define SLAVE 0xa0
11

#define WRITE 0x00 #define READ 0x01 void DelayUs (int us); unsigned char i; void DelayMs (unsigned int count); sbit SDA=P1^0; sbit SCL=P1^1; write NVROM (NVROM_ARR); void InitSerial (void); unsigned char NVROM_ARR, temp1, temp2; void main () { char AUXR; AUXR=0x10; NVROM_ARR=0x00; while (1) { Write NVROM (NVROM_ARR); NVROM_ARR+=1; DelayMs (5); temp1=ReadNVROM (); temp2=temp1; temp2 &=0xf0; temp2>>=4;if(temp2<=9) temp2 +=0x30; else temp2 +=0x37; SBUF=temp2; while (TI==0); TI=0; while (TI==0); TI=0; temp2=temp1; temp2 &=0x0f; if(temp2<=9) temp2+=0x30; else temp2+=0x37; TI=0; SBUF=0x0D; while (TI==0); TI=0; DelayMs (1000); } } void start (void) { SDA=1; SCL=1;
12

DelayUs (1); SDA=0; DelayUs (1); SCL=0; DelayUs (1); } void Stop (void) { SDA=0; DelayUs (1); SCL=1; DelayUs (1); SDA=1; } void WriteI2C (unsigned char Data) { for (i=0; i<8; i++) { SDA=(Data & 0x80)? 1:0; SCL=1; SCL=0; Data<<=1; } SCL=1; DelayUs (1); SCL=0; } unsigned char ReadI2C (bit ACK_Bit) { unsigned char Data=0; SDA=1; for (i=0; i<8; i++) { SCL=1; Data<<=1; Data= (Data | SDA); SCL=0; DelayUs (1); } If (ACK_Bit==1) SDA=0; else SDA=1; DelayUs (1); SCL=1; DelayUs (1); SCL=0;
13

return Data; } unsigned char ReadNVROM (void) { unsigned char buff; void Start (); WriteI2C (0xa0); WriteI2C (0x00); Start (); WriteI2C (0xa1); buff=ReadI2C (ACK); Stop(); return (buff); } void WriteNVROM (unsigned char buff) { Start(); WriteI2C (0xa0); WriteI2C (0x00); WriteI2C (buff); Stop (); } void InitSerial(void) { SCON=0x52; TMOD=0x20; TH1=0xFD; TR1=1; } void DelayMs (unsigned int count) { unsigned int i; while (count) { i=115; while (i>0)i--; count --; } } void DelayUs (int us) { int i; for (i=0; i<us; i++); } RESULT: Hence the embedded c code for the look up table is verified

14

4. LCD INTERFACE TO 8051


AIM: To write an 8051 embedded c code for LCD display HARDWARE TOOLS: PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: A liquid crystal display (LCD) is a flat panel display, electronic visual display, video display that uses the light modulating properties of liquid crystals (LCs). LCs do not emit light directly. They are used in a wide range of applications, including computer monitors, television, instrument panels, aircraft cockpit displays, signage, etc. They are common in consumer devices such as video players, gaming devices, clocks, watches, calculators, and telephones. LCDs have displaced cathode ray tube (CRT) displays in most applications. They are usually more compact, lightweight, portable, less expensive, more reliable, and easier on the eyes. They are available in a wider range of screen sizes than CRT and plasma displays, and since they do not use phosphors, they cannot suffer image burning. LCDs are more energy efficient and offer safer disposal than CRTs. Its low electrical power consumption enables it to be used in battery-powered electronic equipment. It is an electronically modulated optical device made up of any number of segments filled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produce images in color or monochrome. The most flexible ones use an array of small pixels. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the Microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include <reg51.h>
15

#include <string.h> sbit rs = P2^7; sbit en = P2^5; sbit rw = P2^6; sbit b = P0^7; void writecmd (unsigned char a); void writedat (unsigned char b); void busy (); void writestr (unsigned char *s); void writecmd (unsigned char a) { busy (); rs = 0; rw = 0; P0 = a; en = 1; en = 0; } void writedat (unsigned char b) { busy (); rs = 1; rw = 0; P0 = b; en = 1; en = 0; } void busy () { en = 0; P0 = 0xFF; rs = 0; rw = 1; while (b==1) { en=0; en=1; } en=0; } void writestr (unsigned char *s) { unsigned char l, i; l = strlen(s); for (i=1; i<l; i++) {
16

Writedat (*s); s++; } } main () { P0=0x00; P2=0x00; writecmd (0x3C); writecmd (0x0E); writecmd (0x01); writestr ("Wel-Come to LCD"); writecmd (0xC4); writestr ("Program"); while (1); } RESULT: Hence the embedded c code for LCD display is verified

17

5. ADC& DAC INTERFACE TO 8051 5a) ADC AIM: To write an 8051 embedded c code for ADC & DAC Interface to 8051 HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: An analog-to-digital converter (abbreviated ADC, A/D or A to D) is a device that converts a continuous quantity to a discrete time digital representation. An ADC may also provide an isolated measurement. Typically, an ADC is an electronic device that converts an input analog voltage or current to a digital number proportional to the magnitude of the voltage or current. However, some non-electronic or only partially electronic devices, such as rotary encoders, can also be considered ADCs. The digital output may use different coding schemes. Typically the digital output will be a two's complement binary number that is proportional to the input, but there are other possibilities. An encoder, for example, might output a Gray code. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include <reg51.h> #include <string.h> sbit wr = P3^0; sbit rd = P3^1; sbit d1 = P2^7; sbit d2 = P2^6 ; unsigned char data d; unsigned int a=0, b=0, c=0; void int1 (void) interrupt 1
18

{ EA=0; rd = 0; d=P1; rd=1; a = (d & 0x0F); b = d >> 4; EA=1; } void tmr1 (void) interrupt 3 { c++; TH1=0xEC; TL1=0x77; TF1=0; If ((c%2)==0) { d1=1; d2=0; P0=b; } else { d1=0; d2=1; P0=a; } } main () { P0=0x00; P1=0xFF; TMOD=0x90; TH1=0xEC; TL1=0x77; TR1=1; d1=0; d2=1; P0=a; IE=0x89; wr = 0; wr = 1; while (1); } RESULT: Hence the embedded c code for ADC is verified

19

5b) DAC
AIM: To write an 8051 embedded c code for DAC HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: A DAC converts an abstract finite-precision number (usually a fixed-point binary number) into a physical quantity (e.g., a voltage or a pressure). In particular, DACs are often used to convert finite-precision time series data to a continually varying physical signal. A typical DAC converts the abstract numbers into a concrete sequence of impulses that are then processed by a reconstruction filter using some form of interpolation to fill in data between the impulses. Other DAC methods (e.g., methods based on Delta-sigma modulation) produce a pulse-density modulated signal that can then be filtered in a similar way to produce a smoothly varying signal. As per the NyquistShannon sampling theorem, a DAC can reconstruct the original signal from the sampled data provided that its bandwidth meets certain requirements (e.g., a baseband signal with bandwidth less than the Nyquist frequency). Digital sampling introduces quantization error that manifests as low-level noise added to the reconstructed signal. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the Microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include<reg51.h> void delay1 (); void delay2 (); void sqrarwave (); void triwave (); void stairwave (); void delay1 ()
20

{ int a, b; for (a=0; a<100; a++) for (b=0; b<1000; b++); } void Delay2() { int c; for (c=0; c<1000; c++); } void squarwave () { while (P3==0xFF) { P2=0xFF; Delay2 (); P2=0x00; Delay2 (); } } void triwave () { unsigned char d; while (P3==0xFF) { for (d=0x00;d<0xFF;d++) { P2=d; } For (d=0xFF; d<0x00; d--) { P2=d; } } } void stairwave () { While (P3==0xFF) { P2=0x00; Delay2 (); P2=0x20; Delay2 (); P2=0x40; Delay2 (); P2=0x80;
21

Delay2 (); } } void main () { P2=0x00; P3=0xFF; while (P3=0xFF); switch (P3) { case 0xFE: delay1 (); P3=0xFF; squarwave (); break; case 0xFD: delay1 (); P3=0xFF; triwave (); break; case 0xFB: delay1 (); P3=0xFF; stairwave (); break; } } RESULT: Hence the embedded c code for the DAC is verified.

22

6. KEYBOARD
6a) Keyboard interface to 8051
AIM: To write an 8051 embedded c code for the keyboard HARDWARE TOOLS PC Micro Controller Evaluation Board Power Supply SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches. Following the decline of punch cards and paper tape, interaction via tele printer style keyboards became the main input device for computers, despite the development of alternative input devices, such as the mouse, touch screen, pen devices, character recognition and voice recognition, the keyboard remains the most commonly used and most versatile device used for direct (human) input into computers. A keyboard typically has characters engraved or printed on the keys and each press of a key typically corresponds to a single written symbol. However, to produce some symbols requires pressing and holding several keys simultaneously or in sequence. While most keyboard keys produce letters, numbers or signs (characters), other keys or simultaneous key presses can produce actions or computer commands. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include <REG2051.H> #define KEYPAD P1 #define display P3 void delay (int k)
23

{ int i; TR0=0; for(i=0; i<k; i++) { TH0=0x3c; TL0=0xb0; TF0=0; TR0=1; while (TF0==0); TR0=0; } } void DelayMs (unsigned int); char x; unsigned char keypad[4][3]= { 1 , 2 , 3 ,4 , 5 , 6 ,7 , 8 , 9 ,15, 0 , 15 } ; void main () { unsigned char colloc, rowloc; P3=0x00; TMOD=TMOD&0xF0; TMOD=TMOD|0x01; while (1) { do { KEYPAD=0xF0; colloc=KEYPAD & 0xF0; } while (colloc ==0xF0); // if any key pressed DelayMs (1); // some delay do { colloc=KEYPAD; colloc &=0xF0; } while (colloc==0xF0); // to verify is really key pressed KEYPAD=0xFE; colloc=KEYPAD & 0xF0; if (colloc !=0xF0) { rowloc=0; goto next; } KEYPAD=0xFD;
24

colloc=KEYPAD & 0xF0; if (colloc !=0xF0) { rowloc=1; goto next; } KEYPAD=0xFB; colloc=KEYPAD & 0xF0; if (colloc !=0xF0) { rowloc=2; goto next; } KEYPAD=0xF7; colloc=KEYPAD & 0xF0; rowloc=3; goto next; next: if (colloc==0xE0) display= (keypad [rowloc][0]); else if (colloc==0xD0) display= (keypad[rowloc][1]); else if (colloc==0xB0) display = (keypad [rowloc][2]); } } void DelayMs (unsigned int count) { unsigned int i; while count) { i = 115; while (i>0) i--; count--; } } RESULT: Hence the embedded c code for the keyboard is verified.

25

6b) Interfacing to keyboard using switch case


AIM: To write an 8051 embedded c code for keyboard using Switch Case HARDWARE TOOLS PC Micro Controller Evaluation Board SOFTWARE TOOLS: IDE- Keil vision Programming tool: ATMEL FLIP THEORY: In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches. Following the decline of punch cards and paper tape, interaction via teleprinterstyle keyboards became the main input device for computers. Despite the development of alternative input devices, such as the mouse, touch screen, pen devices, character recognition and voice recognition, the keyboard remains the most commonly used and most versatile device used for direct (human) input into computers. A keyboard typically has characters engraved or printed on the keys and each press of a key typically corresponds to a single written symbol. However, to produce some symbols requires pressing and holding several keys simultaneously or in sequence. While most keyboard keys produce letters, numbers or signs (characters), other keys or simultaneous key presses can produce actions or computer commands. PROCEDURE: 1) Write the code using Keil vision IDE 2) Complete the code 3) Connect the power supply to the evaluation board and switch on the power supply 4) Connect the standard RS232 cross cable between the computers serial port and the board 5) Using the programming tool Atmel flip port the program code on to the microcontroller evaluation board 6) Result obtained is viewed in corresponding ports SOURCE CODE: #include <reg8252.h> #include <stdio.h> char code column [] = {0xbf, 0xdf,0xef}; void keypad (void) interrupt 2 { char x, key; unsigned int k;
26

EX1 = 0; P1=0xff; for (x=0; x<3; x++) { P1=column[x]; For (k=0; k<0xff; k++); if ((P1&0x0f)! =0x0f) { key=P1; switch (key) { case 0xb7: putchar ('1'); break; case 0xd7: putchar ('2'); break; case 0xe7: putchar ('3'); break; case 0xbb: putchar ('4'); break; case 0xdb: putchar ('5'); break; case 0xeb: putchar ('6'); break; case 0xbd: putchar ('7'); break; case 0xdd: putchar ('8'); break; case 0xed: putchar ('9'); break; case 0xbe: putchar ('*'); break; case 0xde: putchar ('0'); break; case 0xee: putchar ('#'); break; } } } for (k=0; k<0xffff; k++); P1=0x0f; EX1=1; } void main (void) { EA=1; EX1=1; IT1=1; P1=0x0f; while (1); } RESULT: Hence the 8051 embedded c code for keyboard using Switch Case is verified

27

You might also like