Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "MICRO CONTROLLER PROGRAMMING & APPLICATIONS UNIT V Mr. S. VINOD LECTURER EEE DEPARTMENT."— Presentation transcript:

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

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

3 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 MOVX @ DPTR,A HERE:SJMP HERE

4 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 MOVX @ DPTR,A HERE:SJMP HERE

5 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 MOVX @DPTR,#A INC DPTR MOV A,B MOVX @DPTR,A HERE: SJMP HERE

6 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 MOVX @DPTR,#A INC DPTR MOV A,B MOVX @DPTR,A HERE: SJMP HERE

7 5.RAM ADDRESSING Program: Bit Addressing SETB PSW.3 MOV R0,#data1 MOV A, #data 2 ADD A,R0 MOV DPTR,#4500 MOVX @DPTR, 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 MOVX @DPTR, A HERE:SJMP HERE

8 6.INTERFACING STEPPER MOTOR

9 STEPPER MOTOR

10 INTERFACING STEPPER MOTOR ORG 4100 START:MOV DPTR,#4500 MOV R0,#04 AGAIN;MOVX A,@DPTR PUSH DPH PUSH DPL MOV DPTR,#FFCOH MOV R2, #04H MOV R1,# FFH DLY1:MOV R3,#FFH DLY:DJNZ R3, DLY DJNZ R1, DLY1 MOVX @DPTR, A POP DPL POP DP INC DPTR DJNZ R0, AGAIN SJMP START DATA: 4500 09 4501 05 4502 06 4503 0A

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

12 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

13 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 A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R2,L1

14 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

15 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

16 Pin description for LCD

17

18 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

19 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

20 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

21 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

22 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 8051. 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

23

24 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.

25 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

26 mov p2,#0ffh k1:mov p1, #0 mov a,p2 ani a, #00001111 cjne a,#00001111, k1 k2: acall delay mov a,p2 ani a, #00001111 cjne a,#00001111, over sjmp k2 Over1:mov p1, #11111110 mov a,p2 ani a, #00001111 cjne a,#00001111, row0 mov p1, #11111101 mov a,p2 ani a, #00001111 cjne a,#00001111, row1 mov p1, #11111011 mov a,p2 ani a, #00001111 cjne a,#00001111, row2 mov p1, #11110111 mov a,p2 ani a, #00001111 cjne a,#00001111, 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 a,@a+dptr mov p0,a ljmp k1

27 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

28 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

29 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.

30 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

31 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 ; 1+1+2 = 4 cycles Djnz r6, lp2 ; 4×250 = 1000 cycles = 1000 µs = 1 ms ret

32 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 ; 1+1+2 = 4 cycles Djnz r6, lp2 ; 4×250 = 1000 cycles = 1000 µs = 1 ms ret

33 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 ; 1+1+2 = 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 ; 1+1+2 = 4 cycles Djnz r6, lp3 ; 4×125 = 500 cycles = 500 µs =.5 ms ret

34 Minimum connection for AT89C51

35 40 pin base 1 10K8 11.05MHz1 105 board1 30pf2 8.2KΩ1 10μf1 AT89C511 230/12v transformer1 B.Rectifier1 1000μf1 78051


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

Similar presentations


Ads by Google