1 / 35

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

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.

temple
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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: • Clear c – register for carry • Get the data immediately • Add the two data • 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: • Clear c – register for carry • Get the data immediately • Subtract the two data • 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: • Get the data in A-reg • Get the value to be multiplied in B-reg • Multiply the two data • The higher order of the result is in B-reg • The lower order of the result is in A- reg • 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: • Get the data in A-reg • Get the value to be divided in B-reg • divided the two data • The quotient is in A-reg • The remainder is in B- reg • 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 To exhibit the ram direct addressing and bit addressing schemes of 8051 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 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 • DATA: • 09 • 05 • 06 • 0A 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

  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 toclear ACC, thenadd 3 to the accumulator ten time MOV A,#0 MOV R2,#10 AGAIN: ADD A,#03 DJNZ R2,AGAIN ;repeat until R2=0 (10 times) MOV R5,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. LCD command code HEX REGISTER 1 clear display screen 2 Return home 4 decrement cursor 6 increment cursor 5 shift display right 7 shift display left 8 display off, cursor off A display off, cursor on C display on, cursor off E display on , cursor blinking 10 shift cursor position to left 14 shift cursor position to right 18 shift the entire display to the left 1C shift the entire display to the right 80 force cursor to beginning of 1st line C0 force cursor to beginning of 2nd line 38 2 line and 5*7 matrix

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  32. Minimum connection for AT89C51

  33. 40 pin base 1 10K 8 11.05MHz 1 105 board 1 30pf 2 8.2KΩ 1 10μf 1 AT89C51 1 230/12v transformer 1 B.Rectifier 1 1000μf 1 7805 1

More Related