mepco schlenk engineering college,...

13
MEPCO SCHLENK ENGINEERING COLLEGE, SIVAKASI Vision Envisioning a world Lead by our Engineers, holding a Beacon of Hope and Confidence for Generations to come. Mission To Produce Competent, Disciplined and Quality Engineers & Administrators Through Service Par Excellence Department of Electronics and Communication Engineering Vision To render services to meet the growing global challenges of Engineering Industries and Organizations by Educating Students to become exemplary Professional Electronics and Communication Engineers of High Ethics COURSE INSTRUCTION MANUAL Academic Year: 2011 - 2012 Prepared by: (Mr.J.Senthil Kumar, Asst. Prof./ECE) (Mr.G.Sivasankar, Asst. Prof./ECE)

Upload: others

Post on 20-Mar-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

MEPCO SCHLENK ENGINEERING COLLEGE, SIVAKASI

Vision Envisioning a world Lead by our Engineers, holding a Beacon of Hope and Confidence for Generations to come.

Mission To Produce Competent, Disciplined and Quality Engineers &

Administrators Through Service Par Excellence

Department of Electronics and Communication Engineering

Vision To render services to meet the growing global challenges of Engineering Industries and Organizations by Educating Students to become exemplary Professional Electronics and Communication Engineers of High Ethics

COURSE INSTRUCTION MANUAL

Academic Year: 2011 - 2012

Prepared by:

(Mr.J.Senthil Kumar, Asst. Prof./ECE)

(Mr.G.Sivasankar, Asst. Prof./ECE)

EMBEDDED SYSTEMS

1. An Embedded System is one that has computer hardware with software embedded (firmware)

in it as one of its most important components used for few or dedicated task, which can be

used to monitor, respond, or control an external environment.

2. An Embedded System is any device that includes a programmable computer but is not itself a

general-purpose computer.

3. An Embedded System can be defined as a computer used as a component inside a product

which is hidden into it.

Examples:

1. Cell phone.

2. Printer. Fax machine.

3. Automobile: engine, brakes, dash, etc.

4. Airplane: engine, flight controls, nav/comm.

5. Digital television.

6. Household appliances.etc.,

Pin Diagram of 8051 Microcontroller family

8051

1. BLINKING OF LED Aim:

To blink the LEDs connected to the microcontroller in different patterns Requirements: 8051 Development Kit, 8051 based microcontroller, Universal Programmer, KEIL software. Procedure:

1. Write the code for LED blinking 2. Dump the generated .hex file in the 8051 microcontroller 3. Connect the corresponding port to the LEDs 4. Observe the LEDs blinking 5. Repeat for different blinking patterns

Hardware Details:

Sample Program:

//P1 is connected to 8 LEDs //On /Off all the 8 LEDs at the same time repeatedly #include<REG52.h> void main(void){ unsigned int i; while(1) { P1=0xFF; //ON all LEDs for(i=0;i<30000;i++); //Delay P1=0x00; //OFF all LEDs for(i=0;i<30000;i++); //Delay }

}

Exercises: 1.Write an Embedded C program to blink the alternate LEDs 2.Write an Embedded C program to blink the LEDs serially from Left to Right and Right to Left 3.Write an Embedded C program to display the output of the Arithmetic operations performed by the Microcontroller and display their binary equivalent in the LEDs

2. WORKING WITH PUSH BUTTON SWITCHES Aim:

To work with push button switches and enable a pattern of display in the LEDs connected to the microcontroller. Requirements: 8051 Development Kit, 8051 based microcontroller, Universal Programmer, KEIL software. Procedure:

1. Write the code for push button switches 2. Dump the generated .hex file in the 8051 microcontroller 3. Connect the corresponding port to the LEDs 4. Observe the LEDs blinking 5. Repeat for switches doing different operations

Hardware Details:

Sample Program:

//4 input switches => sw1=P1.0; sw2=P1.1; sw3=P1.2; sw4=P1.3 respectively //output LEDs are connected to P3 #include<REG52.H> void main(void){ P1=0xFF; //Set Port 1 as input port while(1) { while(P1!=0xFF) //Wait for a Key to be pressed { switch(P1) { case 0xFE: //when switch 1 is closed; 1111 1110 (FE) P3=0x55; break; case 0xFD: //when switch 2 is closed; 1111 1101 (FD) P3=0xAA; break; case 0xFB: //when switch 3 is closed; 1111 1011 (FB) P3=0x33; break; case 0xF7: //when switch 4 is closed; 1111 0111 (F7) P3=0x77; break; default: P3=0x44; break; } } } }

Exercises: 1.Write an Embedded C program to get the input through switches to perform the following actions Switch1=>Glow the alternate LEDs Switch2=>Blink LEDs from Left to Right Switch3=>Blink LEDs from Right to Left Switch4=>ON and OFF LEDs after a Delay 2.Write an Embedded C program to get the input through switches to perform the following actions Switch1=>A+B; Switch2=>A-B; Switch3=>A*B; Switch4=>A/B 3.Write an Embedded C program to get the input through switches to perform the following actions

Switch1=>Perform 4 arithmetic operations and display result after a delay Switch2=>Display Binary Up counter 00h to FFh in the LEDs Switch3=>Display Binary Down counter FFh to 00h in the LEDs Switch4=>Convert the Hex number to BCD number

3.SEVEN SEGMENT DISPLAY INTERFACE

Aim: To display numbers and certain characters in a Seven Segment display interfaced with the

microcontroller. Requirements: 8051 Development Kit, 8051 based microcontroller, Universal Programmer, KEIL software. Procedure:

1. Write the code for seven segment display 2. Dump the generated .hex file in the 8051 microcontroller 3. Select the particular segment by making it high 4. Connect the corresponding port to the selected segment 5. Observe the display pattern in the seven segment display 6. Repeat for different patterns display

Hardware Details:

h  g  f  e  d  c  b  a  HEX Code

Display 

   0  0  1  1  1  1 1  1  3F 00  0  0  0  0  1 1  0  06 10  1  0  1  1  0 1  1  5B 20  1  0  0  1  1 1  1  4F 30  1  1  0  0  1 1  0  66 40  1  1  0  1  1 0  1  6D 50  1  1  1  1  1 0  1  7D 60  0  0  0  0  1 1  1  07 70  1  1  1  1  1 1  1  7F 80  1  1  0  1  1 1  1  6F 9

Sample Program:

//P3 => Seven Segment Selection P3.0=seg1; P3.1=seg2; P3.2=seg 3; P3.4=seg4; //P1 => Data Port #include<REG51.h> void main(void){ unsigned int i,j,k; unsigned int display[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned int shift[]={0x01,0x02,0x04,0x08}; //Segment Selection while(1) { for(i=0;i<4;i++) { P3=shift[i]; //Change the segment for(k=0;k<10;k++) { P1=display[k]; //Display the values in the array for (j = 0;j < 35000; j++); //Delay }}}}

Exercises: 1.Write an Embedded C program to display in segment1 0h to Fh and then dispaly the same by enabling other 3 segments one after the other 2.Write an Embedded C program to display the following in the Seven Segment Display after certain dealy in each segment Segment1=>Display Binary Up counter 0h to Fh Segment2=>Display Binary Down counter Fh to 0h Segment3=>Display "GOD IS GREAT" Segment4=>Display "ECE2012" 2.Write an Embedded C program to get the input through switches and display the following in the Seven Segment Display Switch1=>Segment1=>Display Binary Up counter 0h to Fh Switch2=>Segment2=>Display Binary Down counter Fh to 0h Switch3=>Segment3=>Display "ALL THE BEST" Switch4=>Segment4=>Display "HELLO"

4.MATRIX KEYPAD INTERFACE

Aim: To interface matrix keypad wit h the microcontroller and enable different actions for each key

pressed in the keypad. Requirements: 8051 Development Kit, 8051 based microcontroller, Universal Programmer, KEIL software. Procedure:

1. Write the code for the matrix keypad display 2. Dump the generated .hex file in the 8051 microcontroller 3. Connect the keypad by making any of the port as input port 4. Press the keys and observe the display in the seven segment display or LEDs 5. Repeat for different key strokes with different actions

Hardware Details:

Column  Row

HEX  C4  C3  C2  C1  R4 R3 R2 R1  Key No.

 

     Row1   

0xEE  1  1  1  0  1 1 1 0 00xDE  1  1  0  1  1 1 1 0 1

0XFE 0xBE  1  0  1  1  1 1 1 0 20x7E  0  1  1  1  1 1 1 0 3

Row2 0xED  1  1  1  0  1 1 0 1 40xDD  1  1  0  1  1 1 0 1 5

0XFD 0xBD  1  0  1  1  1 1 0 1 60x7D  0  1  1  1  1 1 0 1 7

Row3 0xEB  1  1  1  0  1 0 1 1 80xDB  1  1  0  1  1 0 1 1 9

0XFB 0xBB  1  0  1  1  1 0 1 1 100x7B  0  1  1  1  1 0 1 1 11

Row4 0xE7  1  1  1  0  0 1 1 1 120xD7  1  1  0  1  0 1 1 1 13

0XF7 0xB7  1  0  1  1  0 1 1 1 140x77  0  1  1  1  0 1 1 1 15

Sample Program: //Connections: P2 acting as input port connected to matrix keypad //P1 acting as output port may be connected to LEDs. #include <reg52.h> //Hexa equivalent of each key is assigned in array arr2[] unsigned char arr2[]={0xEE,0xDE,0xBE,0x7E,0xED,0xDD,0xBD,0x7D, 0xEB,0xDB,0xBB,0x7B,0xE7, 0xD7,0xB7,0x77}; //Hexa equivalent of each row is assigned in array arr1[] for row scanning process unsigned char arr1[]={0xFE,0xFD,0xFB,0xF7}; void main() { unsigned int i,j,key; int value; P2=0xff; //Port 2 as input port while(1) { for(i=0;i<=3;i++) // Scanning all the 4 rows to check for any key pressed

{ P2=arr1[i]; // Scanning Row for the key pressed for(j=0;j<2000;j++); // Dealy for Recognizing the Actual Column value = P2; // Actual Key Pressed is now in P2 for(j=0;j<16;j++) { if(value == arr2[j]) // Compare value from P2 to elements of array arr2. { //to find which key has been pressed key = j; //Assign the pressed key value break; //Break Loop after recognizing the actual key pressed } } } if(key==0) { P1=0x00; } else if(key==1) { P1=0x01; } else if(key==2) { P1=0x02; } else if(key==3) { P1=0x03; } else if(key==4) { P1=0x04; } else if(key==5) { P1=0x05; } else if(key==6) { P1=0x06; } else if(key==7) { P1=0x07; } else if(key==8) { P1=0x08; } else if(key==9) { P1=0x09; }

else if(key==10) { P1=0x0A; } else if(key==11) { P1=0x0B; }

else if(key==12) { P1=0x0C; } else if(key==13) { P1=0x0D; } else if(key==14) { P1=0x0E; } else if(key==15) { P1=0x0F; } } } Exercises: 1.Write an Embedded C program to get the input through matix keypad switches to display their corresponding binary values from 0x01 to 0x15 in the LEDs 2.Write an Embedded C program to get the input through matix keypad switches to perform the following actions Switch0=>A+B; Switch5=>A-B; Switch10=>A*B; Switch15=>A/B 3.Write an Embedded C program to get the input through matix keypad switches to perform the following actions Any key in Row1=>Display "GOOD" in any one of the seven segment Any key in Row2=>Blink the LEDs serially from Left to Right and Right to Left Any key in Row3=>Display "ALL THE BEST" in any one of the seven segment Any key in Row3=>Blink the alternative LEDs 4.Write an Embedded C program to design a calculator using the matrix keypad switches

5. LCD INTERFACING Aim:

To interface the LCD display with the microcontroller and enable it to display different alphanumeric characters. Requirements: 8051 Development Kit, 8051 based microcontroller, Universal Programmer, KEIL software. Procedure:

1. Write the code for the LCD and create .hex file 2. Dump the generated .hex file in the 8051 microcontroller 3. Observe the LCD with the alphanumeric characters 5. Repeat for different entry and strings

Hardware Details:

Sample Program: /*Connections: P0 Data lines of LCD Zone. P2^0 - P2^3; P2 lower to control lines of LCD.*/ #include<REG52.H> sbit RS = P2^0; // Register Select sbit RW = P2^1; // RW read write sbit E = P2^2; //enable void delay1 (unsigned int del) // delay function { while(--del);} void lcdcmd(unsigned char k) {

P1=k; RS =0; //register control select RW=0; //write enable E=1; E=0; delay1(500); E=1; } void lcddat(unsigned char k) {

P1 = k; RS = 1; //register control select RW=0; //write enable E=1; E=0; delay1(500); E=1; } void main(void) {

unsigned char arr[15]={'G','O','O','D',' ','B','A','D',' ','U','G','L','Y'}, i; lcdcmd(0x38); lcdcmd(0x38); lcdcmd(0x38); lcdcmd(0x38); //Initialize LCD lcdcmd(0x01); // Clear LCD lcdcmd(0x0E); // Display ON lcdcmd(0x06); // Entry mode - Auto increment while(1){ lcdcmd(0x80); // Address of the first line in the LCD for(i=0;i<13;i++){ lcddat(arr[i]); delay1(500); }}} Exercises: 1. Write an Embedded C Program to display the key pressed from the matrix keypad in the LCD display 2. Write an Embedded C Program for BCD Counter from 00 to 99 and display the same in the LCD display 3. Write an Embedded C Program for calculator using LCD display 4. Write an Embedded C Program to display a string in the reverse order in the second row of the display, starting from the right entry mode.

6. SERIAL COMMUNICATION Aim:

To transmit and receive data serially from the microcontroller to the PC by means of RS-232 interface between the microcontroller and the PC. Requirements: 8051 Development Kit, 8051 based microcontroller, RS-232 cable, Universal Programmer, KEIL software. Procedure:

1. Write the code for the serial communication and create .hex file 2. Dump the generated .hex file in the 8051 microcontroller 3. Observe the received data at the PC terminal 5. Repeat for transmitting from PC to controller and displaying in the LCD

RS232

Hardware Details: Sample Program: //Trasmit and Receive a character to and from the Microcontroller through serial communication #include<REG52.H> void main(void) { unsigned char val; TMOD = 0X20; // Timer 1 - 8 bit Auto Reload mode SCON = 0X50; // 1 stop bits, No parity. TH1 = 0XFD; // 9600 Baud rate TR1 = 1; while(1) { while(!RI); //Waits till 8 bits received in SBUF RI = 0; //Reset Receive Interrupt, to accept next data val = SBUF; //Assign the received value from SBUF P1=val; SBUF = val; //Get ready for transmission while(!TI); //Waits till 8 bits are transmitted TI = 0; //Reset Transmit Interrupt to transmit next data } } Exercises: 1. Write an Embedded C Program to trasmit the key pressed from the matrix keypad to the PC monitor through serial communication 2. Write an Embedded C Program to transmit and receive a character from and to a controller repeatedly 3. Write an Embedded C Program to transmit a string in the reverse order from the controller to the PC

7. STEPPER MOTOR INTERFACE Aim:

To enable rotation of stepper motor clockwise and anti-clockwise depending on the step angles interfaced with the microcontroller Requirements: 8051 Development Kit, 8051 based microcontroller, Stepper motor, ULN2003 IC, Universal Programmer, KEIL software. Procedure:

1. Write the code for the stepper motor interface and create .hex file 2. Dump the generated .hex file in the 8051 microcontroller 3. Connect the stepper motor with the microcontroller thro ULN2003 IC 4. Observe the rotation of the stepper motor clockwise and anticlockwise

Hardware Details:

4 Step Sequence - Full step Mode (1.8o) CW ACW

8 Step Sequence - Half step Mode (0.9o) Step No. Motor Phase Lines Step No. Motor Phase Lines

1 0 1 0 1 1 0 1 0 1 2 1 0 0 1 2 0 0 0 1 3 1 0 1 0 3 1 0 0 1 4 0 1 1 0 4 1 0 0 0

6 0 0 1 0 7 0 1 1 0 `8 0 1 0 0

Sample Program: /*Full Step Mode; P1 lower to Stepper Motor through ULN2003 Transistor array #include<reg52.H> void delay(unsigned int dl) { while(dl--); } void main(void) {

while (1) { P1=0x06; delay(5000); P1=0x0A; delay(5000); P1=0x09; delay(5000); P1=0x05;

delay(5000); } } Exercises: 1. Write an Embedded C Program to run the stepper motor based on the key pressed Key1=>Full step mode clockwise Key2=>Full step mode anticlockwise Key3=>Half step mode clockwise Key4=>Half step mode anticlockwise 2. Write an Embedded C Program to run a stepper motor for 270 degree clockwise and stop it.

8. DC MOTOR INTERFACE Aim:

To enable rotation of DC motor clockwise and anti-clockwise and with full and medium speeds interfaced with the microcontroller Requirements: 8051 Development Kit, 8051 based microcontroller, DC motor, L298 driver IC, Universal Programmer, KEIL software. Procedure:

1. Write the code for the DC motor interface and create .hex file 2. Dump the generated .hex file in the 8051 microcontroller 3. Connect the DC motor with the microcontroller thro L298 IC 4. Observe the rotation of the DC motor with variable speeds

Hardware Details:

Sample Program: /* DC motor ; P1 lower to DC Motor through L298 driver IC*/ #include<reg52.H> void delay(unsigned int dl) { while(dl--); } void main(void) {

int i=0; while (1){ P1=0x01; delay(1150);

} } Exercises: 1. Write an Embedded C Program to run a DC motor in clockwise and anticlockwise direction alternatively. 2. Write an Embedded C Program to run the DC motor at maximum speed and reduce the speed of rotation step by step and finally stop the motor.