MICRO CONTROLLER PROGRAMMING & APPLICATIONS UNIT V Mr. S. VINOD LECTURER EEE DEPARTMENT.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Programming the 8051 Microcontroller Dr. Konstantinos Tatas
Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
Week10 Boolean Instructions on the Boolean Instructions  Boolean (or Bit) addressable capability is unique to the 8051  Enables efficient handling.
1 Chapter 3 Jump, Loop, and Call Instructions. 2 Sections 3.1 Loop and Jump Instructions 3.2 Call Instructions 3.3 Time Delay Generation and Calculation.
kashanu.ac.ir Microprocessors 6-1 I/O Devices Switches, LED, LCD Lec note 6.
Msc. Ivan A. Escobar Broitman Microprocessors 1 1 The 8051 Instruction Set.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Microcontroller Intel 8051
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
The 8051 Microcontroller architecture
MICROCONTROLLER INSTRUCTION SET
The 8051 Microcontroller and Embedded Systems
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
CoE3DJ4 Digital Systems Design Chapter 3: instruction set summary.
8051 Programming (Addressing Mode-Instruction Set) Lec note 5
Prof. Cherrice TraverEE/CS-152: Microprocessors and Microcontrollers The 8051 Assembly Language.
1LAKSHMI.B.E.. Full step -clock 2LAKSHMI.B.E. Full step –anti clock 3LAKSHMI.B.E.
CIT 673 Created by Suriyong1 MCS51 ASSEMBLY Language Resources
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
PIT Programming Examples Working with the modes of PIT.
The 8051 Assembly Language Branching & Subroutines
8051 Micro controller. Architecture of 8051 Features of 8051.
The 8051 Microcontroller and Embedded Systems
Lecture Set 4 Programming the 8051.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Keyboard interfacing.
The 8051 Assembly Language. Overview Data transfer instructions Addressing modes Data processing (arithmetic and logic) Program flow instructions.
The 8051 Assembly Language. Overview Introduction Addressing modes Data processing (arithmetic and logic) Data transfer instructions Program flow instructions.
8051 Micro Controller. Microcontroller versus general-purpose microprocessor.
I/O Devices Switches, LED, LCD
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Microprocessors I 8051 Addressing Modes CS Prof. Msc. Ivan A. Escobar
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
CHAPTER ADDRESSING MODES.
LCD AND KEYBOARD INTERFACING
LCD and Keyboard Interfacing
Classification of Instruction Set of 8051
SERIAL PORT PROGRAMMING
Lecture Set 5 The 8051 Instruction Set.
Subroutines and the Stack
ECE,JYOTHI ENGG COLLEGE
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
Data Processing Instructions
EMT 348: Microcontroller Timer/counter
SCHOOL OF ELECTRONICS ENGINEERING Electronics and Communication
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
The 8051 Assembly Language Arithmetic & Logic Instructions
LCD and Keyboard Interfacing
8051 Single Board Computer (SBC) Version 1.0
LCD and Keyboard Interfacing
Timer.
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
Subroutines and the Stack
Microcontroller 8051 Made By: Arun Branch. 4th Sem. I&C Engg.
LCD and Keyboard Interfacing
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
LCD and Keyboard Sepehr Naimi
DMT 245 Introduction to Microcontroller
First Design Key board R L S.
Important 8051 Features On chip oscillator 4K bytes ROM 128 bytes RAM
LCD and Keyboard Interfacing
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
Subroutines and the Stack
Addressing Modes in 8051 MC S. Lourduraj Asst. Prof. of Physics
LCD AND KEYBOARD INTERFACING
PROCESSORS & CONTROLLERS
Presentation transcript:

MICRO CONTROLLER PROGRAMMING & APPLICATIONS UNIT V Mr. S. VINOD LECTURER EEE DEPARTMENT

Data Transfer, Manipulation, Control & I/O instructions Simple programming exercises key board and display interface Closed loop control of servo motor stepper motor control.

1.Program for addition of two 8-bit numbers Algorithm: 1.Clear c – register for carry 2.Get the data immediately 3.Add the two data 4.Store the result in memory pointed by DPTR Program: ORG 4100 CLR C MOV A,# data 1 ADD A,# data 2 MOV DPTR, #4500 DPTR,A HERE:SJMP HERE

2.Subtraction Of Two 8-bit Number ALGORITHM: 1.Clear c – register for carry 2.Get the data immediately 3.Subtract the two data 4.Store the result in memory pointed by DPTR Program: ORG 4100 CLR C MOV A,# data 1 SUBB A,# data 2 MOV DPTR, #4500 DPTR,A HERE:SJMP HERE

3.Multiplication of two 8-bit number ALGORITHM: 1.Get the data in A-reg 2.Get the value to be multiplied in B-reg 3.Multiply the two data 4.The higher order of the result is in B-reg 5.The lower order of the result is in A- reg 6.Store the result PROGRAM: ORG 4100 CLR C MOV A,# DATA1 MOV B,# DATA1 MUL AB MOV DPTR,#4500 INC DPTR MOV A,B HERE: SJMP HERE

4.Division of two 8-bit number ALGORITHM: 1.Get the data in A-reg 2.Get the value to be divided in B-reg 3.divided the two data 4.The quotient is in A-reg 5.The remainder is in B- reg 6.Store the result PROGRAM: ORG 4100 CLR C MOV A,# DATA1 MOV B,# DATA1 DIV AB MOV DPTR,#4500 INC DPTR MOV A,B HERE: SJMP HERE

5.RAM ADDRESSING Program: Bit Addressing SETB PSW.3 MOV R0,#data1 MOV A, #data 2 ADD A,R0 MOV DPTR,#4500 A HERE:SJMP HERE To exhibit the ram direct addressing and bit addressing schemes of 8051 Program: Direct Addressing MOV 30,#data1 MOV A, #data 2 ADD A,30 MOV DPTR,#4500 A HERE:SJMP HERE

6.INTERFACING STEPPER MOTOR

STEPPER MOTOR

INTERFACING STEPPER MOTOR ORG 4100 START:MOV DPTR,#4500 MOV R0,#04 AGAIN;MOVX PUSH DPH PUSH DPL MOV DPTR,#FFCOH MOV R2, #04H MOV R1,# FFH DLY1:MOV R3,#FFH DLY:DJNZ R3, DLY DJNZ R1, DLY1 A POP DPL POP DP INC DPTR DJNZ R0, AGAIN SJMP START DATA: A

7.Find the maximum number from a given 8 bit number MOV DPTR, #2000 MOV R0,#0A MOV R3,#00 AGAIN:MOVX CJNE A,R3, NE AJMP SKIP NE:JC SKIP MOV R3,A SKIP:INC DPTR DJNZ R0, AGAIN

8.Write a program to clear ACC, then add 3 to the accumulator ten time MOVA,#0 MOVR2,#10 AGAIN:ADDA,#03 DJNZR2,AGAIN ;repeat until R2=0 (10 times) MOVR5,A

9.Write a program to copy a block of 10 bytes from RAM location starting at 37h to RAM location starting at 59h MOV R0,#37h; source pointer MOV R1,#59h; dest pointer MOV R2,#10; counter L1: MOV INC R0 INC R1 DJNZ R2,L1

10.Write a program using Timer0 to create a 10khz square wave on P1.0 MOV TMOD,#02H;8-bit auto-reload mode MOV TH0,#-50;-50 reload value in TH0 SETB TR0;start timer0 LOOP:JNB TF0, LOOP;wait for overflow CLR TF0;clear timer0 overflow flag CPL P1.0;toggle port bit SJMP LOOP;repeat END

Liquid Crystal Displays (LCD) These components are “specialized” for being used with the microcontrollers, which means that they cannot be activated by standard IC circuits. They are used for writing different messages on a miniature LCD. HD44780 can display messages in two lines with 16 characters each. It displays all letters of alphabet, greek letters, punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols that user makes up on its own. Automatic shifting message on display (shift left and right), appearance of the pointer, backlight etc.are considered as useful characteristics

Pin description for LCD

LCD command code HEX REGISTER 1clear display screen 2 Return home 4decrement cursor 6increment cursor 5shift display right 7shift display left 8display off, cursor off Adisplay off, cursor on Cdisplay on, cursor off Edisplay on, cursor blinking 10shift cursor position to left 14shift cursor position to right 18shift the entire display to the left 1Cshift the entire display to the right 80force cursor to beginning of 1 st line C0force cursor to beginning of 2 nd line 38 2 line and 5*7 matrix

Sending command and data to Lcds with a time delay To send command to lcd RS= 0, for data RS=1 P1.0 to P1.7 – are connected to LCD data/command P2.0 is connected to RS pin of LCD P2.1 is connected to R/W pin of LCD P2.2 is connected to E pin of LCD

ORG 0H MOV A, # 38H; init. Lcd 2 line, 5*7 matrix ACALL COMNWRT ACALL DELAY MOV A,# 0EH; display on cursor on ACALL COMNWRT ACALL DELAY MOV A,#01H;clear LCD ACALL COMNWRT ACALL DELAY MOV A,#06H;shift cursor right ACALL COMNWRT ACALL DELAY MOV A,#84H;cursor at line 1, position 4 ACALL COMNWRT ACALL DELAY MOV A, # ‘N’; display letter N ACALL DATAWRT ACALL DELAY MOV A,# ‘O’; display letter O ACALL DATAWRT AGAIN:SJMP AGAIN

COMNWRT:MOV P1,A CLR P2.0; RS =0 for command CLR P2.1;R/W =0 for write SETB P2.2; E=1 for high pluse ACALL DELAY CLR P2.2; E=0 RET DATAWRT:MOV P1,A SETB P2.0 ; RS =1 for data CLR P2.1 ;R/W =0 for write SETB P2.2 ; E=1 for high pluse ACALL DELAY CLR P2.2 ; E=0 RET DELAY:MOV R3,#FF MOV R4,#FF DJNZ R4,HERE DJNZ R3,HERE2 RET END

KEY BOARD INTERFACING The key board here we are interfacing is a matrix keyboard. This key board is designed with a particular rows and columns. These rows and columns are connected to the microcontroller through its ports of the micro controller We normally use 8*8 matrix key board. So only two ports of 8051 can be easily connected to the rows and columns of the key board

Scanning and identifying the key To make sure that the preceding key has been released, 0s are output to all rows at once, and the columns are read and checked repeatedly until all the columns are high. When all columns are found to be high, the program waits for a short amount of time before it goes to the next stage of waiting for a key to be pressed. Columns re scanned over and over in an infinite loop until one of them has a 0 on it. Rows are 0 After a key is pressed mp wait for 20ms and then scans the column again To detect which rows the key press belongs to, the mp grounds one row at a time, if it finds that all columns are high, this means that the key press cannot belong to that row, therefore, it grounds the next row and continues After finding the key, it sets up the starting address for the lookup table holding the scan codes To identify the key pressed the mp controller rotates the column bits one bit at time, in to carry flag and checks to see if its low. If zero, it pull the ASCII code for that key from the look-up table. Otherwise it increment the pointer to point the next element of the look-up table.

Ground all row start Read all columns Wait for Debounce Read all columns Ground next row Read all columns Find which is pressed Get scan code from table return yes keys down? All keys open? no keys down? no yes Key press in this row? yes

mov p2,#0ffh k1:mov p1, #0 mov a,p2 ani a, # cjne a,# , k1 k2: acall delay mov a,p2 ani a, # cjne a,# , over sjmp k2 Over1:mov p1, # mov a,p2 ani a, # cjne a,# , row0 mov p1, # mov a,p2 ani a, # cjne a,# , row1 mov p1, # mov a,p2 ani a, # cjne a,# , row2 mov p1, # mov a,p2 ani a, # cjne a,# , row3 ljmp k2 Row0:mov dptr,#kcode0 sjmp find Row1:mov dptr,#kcode1 sjmp find Row2:mov dptr,#kcode2 sjmp find Row3:mov dptr,#kcode3 find:rrc a jnc match inc dptr sjmp find match: clr a movc mov p0,a ljmp k1

Look-up table Org 300h Kcode0:DB ‘0’, ‘1’, ‘2’, ‘3’ Kcode1:DB ‘4’, ‘5’, ‘6’, ‘7’ Kcode2:DB ‘8’, ‘9’, ‘A’, ‘B’ Kcode3:DB ‘C’, ‘D’, ‘E’, ‘F’ end

Servo Motor Control Servo motor are so called “closed feedback” systems. This means that motor comes with control circuit, which senses if motor mechanism is in desired location and if not it continuously corrects an error until motor reaches proper point. Servo motors are widely used in robotics, remote controlled planes, vehicles. So they come in many shapes and sizes, but they operate in almost the same way. Usually Servo motors are controlled by computer, microcontroller or even simple timer circuit. Of course you may find more advanced servos – R/C so called radio controlled. But again, they are same servos just it takes signals from receiver. servo motors are put in plastic box, but inside there is motor itself, gears and motor driving and control circuit

Servo control signals Servo motor shaft is positioned with pulse width modulated signals. So all servos comes with three wires (Power, Ground and Control). So pulses are sent via control wire. Usually in servos with rotation angle 90° signal width vary between 1 and 2ms. If pulse is more wide rotation continues until reaches mechanical limits.

Main program $mod51 org 0000h main:mov a,p0 mov r1,a Anl a,#01h xrl a,#01h jz m1 mov a,r1 anl a,#02h xrl a,#02h jz m1.5 mov a,r1 anl a,#04h xrl a,#04h jz m2 ajmp main

Program for 1ms M1:Mov r6, #01h ; load 10d in r6 Acall delay ; call 1 ms delay Clr p2.0 ; send 0 to port pin Mov r6, #01h ; load 1d in r6 Acall delay ; call 1 ms delay Delay: Lp2: Mov r7, #0FAh Lp1: Nop ; 1 cycle Nop ; 1+1=2 cycles Djnz r7, lp1 ; = 4 cycles Djnz r6, lp2 ; 4×250 = 1000 cycles = 1000 µs = 1 ms ret

Program 2ms M2:Mov r6, #02h ; load 10d in r6 Acall delay ; call 1 ms delay Clr p2.0 ; send 0 to port pin Mov r6, #02h ; load 1d in r6 Acall delay ; call 1 ms delay Delay: Lp2: Mov r7, #0FAh Lp1: Nop ; 1 cycle Nop ; 1+1=2 cycles Djnz r7, lp1 ; = 4 cycles Djnz r6, lp2 ; 4×250 = 1000 cycles = 1000 µs = 1 ms ret

Program 1.5ms M1.5:Mov r6, #02h ; load 10d in r6 Acall delay ; call 1 ms delay Clr p2.0 ; send 0 to port pin Mov r6, #02h ; load 1d in r6 Acall delay ; call 1 ms delay Delay: Lp2: Mov r7, #0FAh Lp1: Nop ; 1 cycle Nop ; 1+1=2 cycles Djnz r7, lp1 ; = 4 cycles Djnz r6, lp2 ; 4×375 = 1000 cycles = = 1.5 ms Lp3: Mov r7, #07Dh Lp4: Nop ; 1 cycle Nop ; 1+1=2 cycles Djnz r7, lp4 ; = 4 cycles Djnz r6, lp3 ; 4×125 = 500 cycles = 500 µs =.5 ms ret

Minimum connection for AT89C51

40 pin base 1 10K MHz1 105 board1 30pf2 8.2KΩ1 10μf1 AT89C /12v transformer1 B.Rectifier1 1000μf