LABORATORY MANUAL EMBEDDED C LABORATORY. M. Tech I Year I Sem R13 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.

Similar documents
{ int i,j; for(i=0;i<count;i++) for(j=0;j<1275;j++); }

Human Eye Ball recognition system

MEPCO SCHLENK ENGINEERING COLLEGE, SIVAKASI. Department of Electronics and Communication Engineering COURSE INSTRUCTION MANUAL

Serial-out Color Sensor. Overview. Features

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller and Applications Subject Code:

WINTER 14 EXAMINATION Subject Code: Model Answer Page No: 1/ 26

EE 354 September 16, 2016 C Sample Programs

Practical Manual Embedded Systems (Course Code-USIT4P5) For. S.Y.B.Sc. I.T. (Semester IV)

S.J.P.N Trust's. Hirasugar Institute of Technology, Nidasoshi.

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

8051 Interfacing and Applications Microcontroller

EXPERIMENT NO. 02 ELECTRONIC VOTING MACHINE USING 8051.

Bachelor of Engineering in Computer and Electronic Engineering

1. Attempt any three of the following: 15

// sets the position of cursor in row and column

LCD AND KEYBOARD INTERFACING

List any four software development tools used in an embedded system and state the function of each.

C:\CYGNAL\Examples\C8051F02x\C\Edu_Board_Source_Code\Magcard.c

INTERRUPTS PROGRAMMING

LABORATORY MANUAL EMBEDDED SYSTEMS LABORATORY. M. Tech I Year I Sem R15 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.

Interrupts, timers and counters

Microcontroller and Embedded Systems:

CPEG300 Embedded System Design. Lecture Interface with Peripheral Devices

MODEL ANSWER WINTER 17 EXAMINATION Subject Title: Microcontroller and applications

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

a) Attempt any THREE of the following 12 M

T.Y. Diploma : Sem. VI [ET/EN/EX/EJ/IE/IS/IC/DE/EV/MU/IU/ED/EI] Embedded System

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) SUMMER-16 EXAMINATION Model Answer

Modules For Six Months Industrial Training On WIRELESS EMBEDDED SYSTEM DESIGN

based on candidate s understanding. 7) For programming language papers, credit may be given to any other program based on equivalent concept.

Department of Electronics and Instrumentation Engineering Question Bank

ELEG3923 Microprocessor Ch.9 Timer Programming

Q.1. A) Attempt any THREE of the following:

MODEL ANSWER SUMMER 17 EXAMINATION

ELEG3923 Microprocessor Ch.10 Serial Port Programming

Real Time Operating System

Automated Walker with Patient Monitoring Mechanism. Kailash Kumar Jain Munoth. A Report. Presented to the Faculty of

Chapter 6 Serial EEPROM by John Leung

Department of Electronics and Communication Engineering Microprocessors and Microcontrollers Laboratory Description:

8051 Microcontroller

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

FACULTY OF ENGINEERING LAB SHEET

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

PART-A INTRODUCTION TO 8051 MICROCONTROLLER. 8-bit data bus - It can access 8 bits of data in one operation

WIRELESS EMBEDDED SYSTEM DESIGN

Diploma in Embedded Systems

ATMEGA32 MUSIC PLAYER

Lecture 10. Serial Communication

Q 1 a) Attempt any THREE of the following: 12 TMOD.7 TMOD.6 TMOD.5 TMOD.4 TMOD.3 TMOD.2 TMOD.1 TMOD.0 GATE C/T M1 M0 GATE C/T M1 M0

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

Serial communication

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

TEVATRON TECHNOLOGIES PVT. LTD Embedded! Robotics! IoT! VLSI Design! Projects! Technical Consultancy! Education! STEM! Software!

P89V51RD2 Development Board May 2010

Embedded Systems. Software Development & Education Center. (Design & Development with Various µc)

Thomas Liu (Business Manager) //****************************************************************//

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Microprocessors and Microcontrollers (EE-231)

ARM HOW-TO GUIDE Interfacing 7SEG with LPC2148 ARM

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

MCS-51 Serial Port A T 8 9 C 5 2 1

Chapter 8 Interfacing a JHD12864J Graphic Module to AT89S52

Embedded Robotics. Software Development & Education Center

WIZTECH AUTOMATION SOLUTIONS (P) LTD., An ISO 9001:2000 and IAO certified company

acret Ameya Centre for Robotics & Embedded Technology Syllabus for Diploma in Embedded Systems (Total Eight Modules-4 Months -320 Hrs.

17. I 2 C communication channel

EMBEDDED Systems. Functions. MODULE- 1 C programming with data Structure Introduction to C. Array and String. Control Flow Statements In C


8051 Training Kit Lab Book

Timers and interrupts

ARM HOW-TO GUIDE Interfacing Stepper Motor with LPC2148

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

EMBEDDED HARDWARE DESIGN. Tutorial Interfacing LCD with Microcontroller /I

8051 Microcontroller

Microcontroller and Applications

Unit-I. 1. INTRODUCTION TO MICROCONTROLLERS. Micro controller, types, selection of a microcontroller and applications

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

Dragon12 LCD Displays Huang Sections 7.8 Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) ATD_10B8C Block User Guide. Dragon12 LCD Display

MUFFAKHAM JAH COLLEGE OF ENGINEERING AND TECHNOLOGY (Affiliated to Osmania University) Banjara Hills, Hyderabad, Telangana State.

8051 Microcontroller Interrupts

ARM HOW-TO GUIDE Interfacing GLCD with LPC2148 ARM

Microcontroller & Interfacing

80C51 Block Diagram. CSE Overview 1

Program Modeling Concepts:

ARM HOW-TO GUIDE Interfacing GLCD with LPC2148 ARM

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

Embedded Systems. Embedded Programmer. Duration: 2 weeks Rs Language and Tools. Embedded System Introduction. Embedded C programming

The industrial technology is rapidly moving towards ARM based solutions. Keeping this in mind, we are providing a Embedded ARM Training Suite.

Appendix A: Rack Specification Sheet

Robosoft Systems in association with JNCE presents. Swarm Robotics

8051 Serial Communication

PGT302 Embedded Software Technology. PGT302 Embedded Software Technology

LCDs. Embedded Systems Interfacing. 20 September 2011

Transcription:

LABORATORY MANUAL EMBEDDED C LABORATORY M. Tech I Year I Sem R13 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG. BALAJI INSTITUTE OF TECHNOLOGY & SCIENCE Laknepally, Narsampet, Warangal 1

M.TECH. (EMBEDDED SYSTEMS)-R13 Regulations JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD M. Tech I Year I Sem. Embedded Systems EMBEDDED C LABORATORY Note: Minimum of 10 experiments have to be conducted. The following programs have to be tested on 89C51 Development board/equivalent using Embedded C Language on Keil IDE or Equivalent. 1. Program to toggle all the bits of Port P1 continuously with 250 ms delay. 2. Program to toggle only the bit P1.5 continuously with some delay. Use Timer 0, mode 1 to create delay. 3. Program to interface a switch and a buzzer to two different pins of a Port such that the buzzer should sound as long as the switch is pressed. 4. Program to interface LCD data pins to port P1 and display a message on it. 5. Program to interface keypad. Whenever a key is pressed, it should be displayed on LCD. 6. Program to interface seven segment display unit. 7. Program to transmit a message from Microcontroller to PC serially using RS232. 8. Program to receive a message from PC serially using RS232. 9. Program to get analog input from Temperature sensor and display the temperature value on PC Monitor. 10. Program to interface Stepper Motor to rotate the motor in clockwise and anticlockwise directions 11. Program to Sort RTOS on to 89C51 development board. 12. Program to interface Elevator. 2

Experiment no: 1 PROGRAMMING PORTS Program to toggle all the bits of Port P1 continuously with 250 ms delay. 3

#include<reg51.h> void delay(unsigned int msec) //delay function int i,j; for(i=0;i<msec;i++) for(j=0;j<1275;j++); Void main() P1=0x00; While (1) P1=0xff; delay(250); P1=0x00; delay(250); 4

Experiment no: 2 DELAY USING TIMERS Program to toggle only the bit P1.5 continuously with some delay. Use Timer 0, mode 1 to create delay. 5

#include <REGX51.H> void delay(); void main() while(1) P1=0X10; delay(); P1=0x00; void delay() TMOD=0x01; TH1=0Xff; TL1=0Xff; TR1=1; while(tf1==0); TF1=0; TR1=0; 6

Experiment no: 3 SWITCH & BUZZER INTERFACING Program to interface a switch and a buzzer to two different pins of a Port such that the buzzer should sound as long as the switch is pressed. H/w set up: 1. Switch is connected to P1.1 2. Buzzer is connected to P1.2 7

#include <REGX51.H> sbit a=p1^1; sbit a=p1^2; void main() a=b=0; while(1) if(a==1) b=1; else b=0; 8

Experiment no: 4 LCD INTERFACING Program to interface LCD data pins to port P1 and display a message on it. 9

//Program to display String on LCD #include<regx51.h> sfr lcd_data_pin=0x90; // data port P1 sbit rs=p3^0; // Register select pin sbit rw=p3^1; // Read write pin sbit en=p3^6; // Enable pin void delay(unsigned int msec) //delay function int i,j; for(i=0;i<msec;i++) for(j=0;j<1275;j++); void lcd_command(unsigned char comm) // function to send command to LCD lcd_data_pin=comm; en=1; rs=0; rw=0; delay(1); en=0; void lcd_data(unsigned char disp) // function to send data on LCD lcd_data_pin=disp; en=1; rs=1; rw=0; 10

delay(1); en=0; lcd_dataa(unsigned char *disp) // function to send string to LCD int x; for(x=0;disp[x]!=0;x++) lcd_data(disp[x]); void lcd_ini() //Function to inisialize the LCD lcd_command(0x38); delay(5); lcd_command(0x0f); delay(5); lcd_command(0x80); delay(5); void main() lcd_ini(); lcd_dataa("welcome!"); 11

Experiment no: 5 4X3 KEYPAD INTERFACING Program to interface keypad. Whenever a key is pressed, it should be displayed on LCD. 12

// Program to interface controller with controller #include<reg51.h> #define port P1 #define dataport P2 // Dataport for lcd #define key P0 // Port for keypad #define sec 100 sbit rs = port^1; sbit rw = port^2; sbit en = port^3; sbit col1=key^4; sbit col2=key^5; sbit col3=key^6; sbit row1=key^0; sbit row2=key^1; sbit row3=key^2; sbit row4=key^3; void delay(unsigned int msec) //Time delay function int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); 13

void lcd_cmd(unsigned char item) //Function to send command to LCD dataport = item; rs= 0; rw=0; en=1; delay(1); en=0; return; void lcd_data(unsigned char item) //Funtion to send data on LCD dataport = item; rs= 1; rw=0; en=1; delay(1); en=0; return; void lcd_data_string(unsigned char *str) // Function to send string on LCD 14

int i=0; while(str[i]!='\0') lcd_data(str[i]); i++; delay(10); return; void lcd(unsigned char str[10]) // Funtion to Initialize LCD lcd_cmd(0x38); lcd_cmd(0x0e); //delay(sec); lcd_cmd(0x01); //delay(sec); lcd_cmd(0x82); //delay(sec); lcd_data_string(str); void display(int a) //Display functon for LCD 15

switch(a) case 1:lcd("one 1"); break; case 2:lcd("two 2"); break; case 3:lcd("three 3"); break; case 4:lcd("four 4"); break; case 5:lcd("five 5"); break; case 6:lcd("six 6"); break; case 7:lcd("seven 7"); break; case 8:lcd("EIGHT 8"); break; case 9:lcd("NINE 9"); break; case 0:lcd("ZERO 0"); break; case 11:lcd("*"); break; case 12:lcd("#"); 16

break; void check_col1() //Function for checking column one row1=row2=row3=row4=1; row1=0; if(col1==0) display(1); row1=1; row2=0; if(col1==0) display(4); row2=1; row3=0; if(col1==0) display(7); row3=1; row4=0; if(col1==0) display(11); row4=1; 17

void check_col2() //Function for checking column two row1=row2=row3=row4=1; row1=0; if(col2==0) display(2); row1=1; row2=0; if(col2==0) display(5); row2=1; row3=0; if(col2==0) display(8); row3=1; row4=0; if(col2==0) display(0); row4=1; void check_col3() //Function for checking column three row1=row2=row3=row4=1; row1=0; 18

if(col3==0) display(3); row1=1; row2=0; if(col3==0) display(6); row2=1; row3=0; if(col3==0) display(9); row3=1; row4=0; if(col3==0) display(12); //For # row4=1; void main() col1=col2=col3=1; //Input Port while(1) row1=row2=row3=row4=0; if(col1==0) check_col1(); 19

else if(col2==0) check_col2(); else if(col3==0) check_col3(); 20

Experiment no: 6 7 SEGMENT DISPLAY INTERFACING Program to interface seven segment display unit. 21

// Program to interface single seven segment #include<reg51.h> delay_ms(int time) // Time delay function int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++); void main() char num[]=0x40,0xf9,0x24,0x30,0x19,0x12,0x02,0xf8,0x00,0x10;// Hex values corresponding to digits 0 to 9 int c; while(1) for(c=0;c<10;c++) P2=num[c]; delay_ms(200); 22

Experiment no: 7 SERIAL COMMUNICATION TRANSMITTER Program to transmit a message from Microcontroller to PC serially using RS232. 23

#include <REGX51.H> void main() SCON=0x40; TMOD=0x20; TH1=0xFD; TR1=1; SBUF='serial communication transmitter'; while(ti==0); TI=0; while(1); 24

Experiment no: 8 SERIAL COMMUNICATION RECEIVER Program to receive a message from PC serially using RS232. 25

#include <REGX51.H> void main() int i; char a[]="serial communication receiver"; SCON=0x40; TMOD=0x20; TH1=0xFD; TR1=1; for(i=0;a[i]!='\0';i++) SBUF=a[i]; while(ti==0); TI=0; while(1); 26

Experiment no: 9 TEMPERATURE SENSOR INTERFACING Program to get analog input from Temperature sensor and display the temperature value on PC Monitor. 27

//Program to check the working of ADC0804 using LED's on its output port. #include<reg51.h> #define input P0 //Input port to read the values of ADc #define output P2 // Output port, connected to LED's. sbit wr= P1^1; // Write pin. It is used to start the conversion. sbit rd= P1^0; // Read pin. It is used to extract the data from internal register to the output pins of ADC. sbit intr= P1^2; // Interrupt pin. This is used to indicate the end of conversion. It goes low when conversion is complete. void delay(unsigned int msec ) // The delay function provides delay in msec. int i,j ; for(i=0;i<msec;i++) for(j=0; j<1275; j++); void adc() // Function to read the values from ADC and display on the LED's. rd=1; wr=0; delay(1); wr=1; 28

while(intr==1); rd=0; output=input; delay(1); intr=1; void main() input=0xff; // Declare port 0 as input port. while(1) adc(); 29

Experiment no: 10 STEPPER MOTOR INTERFACING Program to interface Stepper Motor to rotate the motor in clockwise and anticlockwise directions 30

// Program to interface Stepper Motor with 8051 Microcontroller (AT89C51) /**** Wave Drive Stepping ****/ #include<regx51.h> sfr stepper=0xa0; void delay(unsigned int count) int i; for(i=0;i<count;i++); void main() while(1) stepper=0x01; delay(350); stepper=0x02; delay(350); stepper=0x04; delay(350); stepper=0x08; delay(350); 31

/*****************************/ /**** Half Drive Stepping ****/ #include<reg51.h> sfr stepper=0xa0; void delay(unsigned int count) int i; for(i=0;i<count;i++); void main() while(1) stepper=0x01; delay(300); stepper=0x03; delay(300); stepper=0x02; delay(300); stepper=0x06; delay(300); 32

stepper=0x04; delay(300); stepper=0x0c; delay(300); stepper=0x08; delay(300); stepper=0x09; delay(300); /*****************************/ 33

EXPERIMENT-11 /****************************************************************************/ /* */ /* RTX_Test.C: A RTX-51 Application */ /* */ /****************************************************************************/ #include <rtx51tny.h> // RTX-51 tiny functions & defines #include <reg52.h> #define LCD_DATA P1 to Port(Port1) //8051 Register //Define LCD_DATA Lines #define LED P0 // Define LED for PORT 0 /***********************Define LCD control pins******************************/ sbit RS = P3^5; //Register Select sbit RW = P3^6; //LCD Read/Write sbitlcd_e = P3^7; //LCD Enable code unsigned char msg[] = (" 8051 MCOS RTOS "); code unsigned char msg1[] = (" MULTITASKING "); //Display the message //void lcd_init(void); voidlcd_cmd(unsigned char); voidlcd_display(unsigned char); /***************************************************************************/ /* Task 0 : RTX-51 tiny Initializ task */ /***************************************************************************/ voidinit(void)_task_ 0 os_create_task (1); // start task 1 INIT_UART os_create_task (2); // start task 2 SEND_UART os_create_task (3); // start task 2 LED Blink os_create_task (4); // start task 2 LCD Display while (1) // endless loop os_wait (K_TMO, 5, 0); // wait for timeout: 5 ticks /**************************************************************************/ /* Task 1 : RTX-51 tiny starts initialize serial port with task 0 */ /**************************************************************************/ 34

voiduart (void) _task_ 1 SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload TH1 = 0xFD; // TH1: reload value for 9600 @ 11.0592MHz TR1 = 1; // TR1: timer 1 run TI = 1; // TI: set TI to send first char of UART /**************************************************************************/ /* Task 2 : RTX-51 tiny starts send UART data with task 0 */ /**************************************************************************/ voiduart_send(void) _task_ 2 while (1) os_wait (K_TMO, 10, 0); SBUF = 'A'; /**************************************************************************/ /* Task 3 : RTX-51 tiny starts LED Blink with task 0 */ /**************************************************************************/ void led(void) _task_ 3 while (1) LED = 0x55; os_wait (K_TMO, 30, 0); LED = 0xAA; os_wait (K_TMO, 30, 0); // endless loop /**************************************************************************/ /* Task 4 : RTX-51 tiny starts LCD Initializaion with task 0 */ /**************************************************************************/ voidlcd(void) _task_ 4 while (1) unsigned char i; // endless loop dot lcd_cmd(0x38); os_wait (K_TMO, 2, 0); lcd_cmd(0x0c); os_wait (K_TMO, 2, 0); lcd_cmd(0x06); //Display On, cursor off //Shift Cursor to right //2x16 Character 5x7 35

os_wait (K_TMO, 2, 0); lcd_cmd(0x01); os_wait (K_TMO, 2, 0); //------------------------------------------- // First Line Message Display //------------------------------------------- lcd_cmd(0x80); os_wait (K_TMO, 2, 0); i=0; while(msg[i]!='\0') lcd_display(msg[i]); i++; os_wait (K_TMO, 4, 0); //Clear display screen //First Line Initialization //------------------------------------------- // Second Line Message Display //------------------------------------------- lcd_cmd(0xc0); os_wait (K_TMO, 2, 0); i=0; while(msg1[i]!='\0') lcd_display(msg1[i]); i++; os_wait (K_TMO, 4, 0); //---------------------------------- // LCD command Function //---------------------------------- voidlcd_cmd(unsigned char cmnd) LCD_DATA = cmnd; RS = 0; RW = 0; lcd_e = 1; os_wait (K_TMO, 2, 0); lcd_e = 0; //---------------------------------- // LCD Data Function //---------------------------------- voidlcd_display(unsigned char dat) //Second Line Initialization 36

LCD_DATA = dat; RS = 1; RW = 0; lcd_e = 1; os_wait (K_TMO, 2, 0); lcd_e = 0; 37