Professional Documents
Culture Documents
Interfacing Stepper Motor To 8086 Using 8255
Interfacing Stepper Motor To 8086 Using 8255
Contents
3
3 7
11
11 13
15
15 17
21
21 22
5 8051 Programming
5.1 5.2 Wave generation Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
25 27
6 7 8 9
Interfacing Hex Keyboard with 8086 Timers in Interrupt Mode 8051 timers: Stack Check Mode 8051 timers: Interrupt Mode
29
30 32 35 38
2009
th October,
Introduction
Set Baud Rate
Type BU and press enter Type 5 to set baud rate as 9600
n filename.bin wcs:1000 q
Then type datacom and press enter
set parameters and then transmit lename.bin wait till transmission is complete
;address of the control register ;address of Port B ;control word for Port B as output ;send it to the control register ;load sequence in AL ;send it to Port B ;rotate left once ;call a delay ;repeat the sequence ;delay procedure
;load sequence in AL ;send it to Port B ;rotate right once ;call a delay ;repeat until CX=0 ;delay procedure
3) A program to rotate a stepper motor 90 degrees in the clockwise direction and 180 degrees in the anticlockwise direction four times
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H CR EQU 0C6H PB EQU 0C2H MOV DX, 4 MOV AL, 80H OUT CR, AL ABC: MOV CX, 50 ;CX=50 MOV AL, 66H BACK: OUT PB, AL ROR AL, 1H CALL DELAY LOOP BACK MOV CX, 100 MOV AL, 66H BACK1: OUT PB, AL ROL AL, 1H CALL DELAY LOOP BACK1 DEC DX JNZ ABC DELAY PROC NEAR MOV BX, 0FFFH AGN: DEC BX JNZ AGN RET DELAY ENDP HLT CODE ENDS END
;address of control register ;address of Port B ;control word for Port B as output ;send it to control register ;load sequence in AL ;send it to Port B ;rotate right once ;call a delay ;repeat until CX=0 ;load sequence in AL ;rotate it once, to the left ;call a delay ;repeat until CX=0 ;delay procedure
Procedure: ULN2003 driver IC circuit is setup on breadboard. The input is given using the 26
pin at cable from 8255 board. We are using Port B of 8255 to give input of the driver IC. Pin 9, 10, 11, 12 of the 26 pin connector is found to be Port B using CRO. These pins are connected to pin numbers 1, 2, 3 and 4 of ULN2003. Output is taken from 13, 14, 15 and 16 of ULN2003. Stepper motor have ve input leads and a VCC lead. All 24 permututations are tried to get the anticlockwise rotation of the stepper motor.
Result: Stepper motor was driven as per the requirement and step angle = 7.2o
CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H START: MOV DI, OFFSET TABLE MOV CL, 04 LOOP1: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H DELAY: DEC DX JNZ DELAY INC DI LOOP LOOP1 JMP START TABLE: DB 0AH, 6, 5, 9 HLT CODE ENDS END
CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H ORG 1000H MOV BX, 50 START: MOV DI, OFFSET TABLE MOV CL, 04 LOOP1: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H DELAY: DEC DX JNZ DELAY INC DI LOOP LOOP1 DEC BX JNZ START HLT TABLE: DB 9, 5, 6, 0AH HLT CODE ENDS END
;port address
;load address of table to DI ;to get 200 steps ;output values ;introduce delay
3) A program to rotate a stepper motor 90 degrees in the clockwise direction and 180 degrees in the anticlockwise direction four times
CODE SEGMENT ASSUME CS:CODE, DS:CODE PORT1 EQU 0C0H ORG 1000H MOV AH,4 START: MOV BL, 12 FORWD: MOV DI, OFFSET FORW CALL ROTATE DEC BL JNZ FORWD CALL DELAY MOV BL, 25 REVER: MOV DI, OFFSET REV CALL ROTATE DEC BL JNZ REVER CALL DELAY DEC AH JNZ START ROTATE: MOV CL, 4 REPT: MOV AL, [DI] OUT PORT1, AL MOV DX, 1010H LOOP1: DEC DX JNZ LOOP1 INC DI LOOP REPT RET MOV DX, 0FFFFH DELAY: DEC DX JNZ DELAY RET HLT FORW: DB 9, 5, 6, 0AH REV: DB 0AH, 6, 5, 9 CODE ENDS END
;port address
;procedure for rotating values ;loop for 100 steps ;delay ;loop for repeating 4 times ;procedure to output to port
;delay procedure
Procedure: The 8255 board is given with power transistors already assembled. The output from
8086 trainer kit is taken using a at cable to 8255 board and output is given to motor.
Result: Stepper motor was driven as per the requirement and step angle = 7.2o
10
;select digit position ;give display information ;delay of 2mS ;data pointer incremented ;check if 8 digits are displayed ;if not, repeat ;repeat from first digit ;delay of 2mS
11
;select digit position ;give display information ;call delay procedure ;increment data pointer
;delay procedure
12
13
;pointer to the seven segment codes ;send ;word ;send ;word ;send it to it to it to control register clear display to control register write display RAM to control register
;take corresponding display code ;send it to data register ;call delay procedure
;delay procedure
Procedure: 8279 chip has two portions one for providing scanned display interface for LED and the other for interfacing with keyboards or an array of sensors. In the absence of this chip, the processor is fully involved in the detecting of key press and displaying of words. But with 8279, the processor has to just give the commands and the 8279 takes care of all the activities. In case of a valid key press, the code of the key enters into the FIFO RAM. At the same time, the count in the status register increments. While programming, the key press is detected by checking whether the count in the status register is incremented or not.
14
;set port B = 0H ;call delay procedure ;set port B = 0FFH ;call delay procedure ;delay procedure
Procedure: 6kHz square wave has a time period of 166.66s. So a delay of 83s is called for each ON time and OFF time. For getting square wave at PB7, port B is made output port and output is taken from PB7. Others pins are don't cares. Waveform: Observed frequency = 4.23 kHz; Ton = 118S; Tof f = 118S
15
2) A program to generate a asymmetrical wave of 20% duty cycle at PC7 using BSR mode of 8255
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H MOV AL, 90H OUT 0C6, AL MOV AL, 90H OUT 0C6H, AL BACK: MOV AL, 0FH OUT 0C6H, AL CALL DELAY MOV AL, 0EH OUT 0C6H, AL CALL DELAY CALL DELAY CALL DELAY CALL DELAY JMP BACK DELAY PROC NEAR MOV CX, 20H HERE: NOP LOOP HERE RET DELAY ENDP HLT CODE ENDS END
;set port C = 0FFH ;call delay procedure ;set port C = 0H ;call delay procedure
;delay procedure
Procedure: A square wave of 20% duty cycle means the square wave is ON for
the time period. A delay of some value is created. The delay is called once when the output port is ON and the delay is called four times when the port is OFF. PC7 is set/reset using the BSR mode.
1 th 5 of
16
of of of of
;select counter 0 in mode 3 ;value to be passed to control register ;load count = 115 in AX ;send lower byte of count to counter 0 ;move higher byte of count to AL ;send higher byte of count to counter 0 ;select counter 1 in mode 3 ;value to be passed to control register ;load count = 25 in AX ;send lower byte of count to counter 1 ;move higher byte of count to AL ;send higher byte of count to counter 1 ;select counter 2 in mode 3 ;value to be passed to control register ;load count = 1500 in AX ;send lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2
Procedure: For 8253, a delay procedure is not required. It produces hardware delay which is made use to create the waveforms. Mode 3 of counters 0, 1 & 2 is made use in this program. Counter 0 divides input frequency by 115 to produce a square wave of 13kHz. Similarly, counter 1 and counter 2 divides the input frequency by 25 and 1500 to produce 60kHz and 1kHz respectively. Waveforms: Observed frequency = 17.8 kHz; Ton = 28S; Tof f = 28S
17
18
2) A program to generate an asymmetric square wave at the output of counter 2 using any two modes of the 8253 chip. Use the modes which do not require an L to H transition at the gate. Using Mode 2
DAT SEGMENT CR EQU 0CEH CNT2 EQU 0CCH DAT ENDS COD SEGMENT ASSUME CS: COD, DS: DAT ORG 1000H MOV AL, 0B4H OUT CR, AL MOV AX, 3 OUT CNT2, AL MOV AL, AH OUT CNT2, AL HLT COD ENDS END ;address of control register ;address of counter 2
;control word for counter 2 in mode 2 ;send it to control register ;load count = 3 in AX ;lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2
Using Mode 4
DAT SEGMENT CR EQU 0CEH CNT2 EQU 0CCH DAT ENDS COD SEGMENT ASSUME CS: COD, DS: DAT ORG 1000H AGA: MOV AL, 0B8H OUT CR, AL MOV AX, 3 OUT CNT2, AL MOV AL, AH OUT CNT2, AL JUMP AGA HLT COD ENDS END ;address of control register ;address of counter 2
;control word for counter 2 in mode 4 ;send it to control register ;load count = 3 in AX ;send lower byte of count to counter 2 ;move higher byte of count to AL ;send higher byte of count to counter 2
Procedure: The control word is selected such as to set counter 2 in mode 2 or mode 4. In mode 2, the counter reloads after one cycle. In mode 4, the counter has to be reloaded by the user. The pulse will be high for N cycles and low for one cycle where N = count.
19
Waveforms:
Ton = 5 ; Tof f =
Ton = 7 ; Tof f =
20
4.1 ADC
1) A program to measure the DC voltage at ADC pin and get digital readout.
CODE SEGMENT ASSUME CS:CODE,DS:CODE ORG 1000H MOV AL, 10H OUT 0C8H, AL MOV AL, 18H OUT 0C8H, AL MOV AL, 01 OUT 0D0H, AL MOV AL, 00 MOV AL, 00 MOV AL, 00 MOV AL, 00 OUT 0D0H LOOP: IN AL, 0D8H AND AL, 01 CMP AL, 01 JNZ LOOP IN AL, 0C0H MOV BX, 1100H MOV [BX], AL HLT CODE ENDS END
;make ALE & SC low ;check for EOC ;if EOC port is low, jump ;move data to the memory location
Procedure: ADC creates a digital output depending on the analog input given. Analog signal
is given to the ADC through one of the inut pins. Then ALE and SC are enabled to latch address and to start conversion. After giving a delay ALE and SC are lowered. EOC port is monitored. If it is low then data is taken in and send to memory.
21
4.2 DAC
1) A program to generate a triangular waveform of T = 10ms.
CODE SEGMENT ASSUME CS:CODE,DS:DAT ORG 1000H MOV AL, 0 REPEA: OUT 0C8H, AL CALL DELAY INC AL CMP AL, 45 JNZ REPEA AGN: OUT 0C8H, AL CALL DELAY DEC AL CMP AL, 0 JNZ AGN JMP REPEA DELAY PROC NEAR MOV CX, 26 HERE: LOOP HERE RET DELAY ENDP HLT CODE ENDS END
;AL=0 ;send AL to port A ;call delay ;compare AL with 45H ;if not equal, repeat ;if AL=45H, decrement loop ;call delay ;comapare AL with 0 ;if not 0, continue decrementing ;if AL=0, increment ;delay procedure ;value of N for a small delay
Procedure: DAC converts digital signals into analog form. Depending on the digital input given, a current is generated which is converted into voltage by the DAC. To create a triangular waveform rst the count is incremented by giving a delay after each increment. After a particular value the count is decremented in a similar manner. Time period is calculated depending on the clock. Waveform: T = 9.8ms
22
;AL=0 ;send AL to port A ;call a delay ;compare AL with 24H ;if not equal, repeat ;if AL=0, increment ;delay procedure ;value of N for a small delay
Procedure: DAC converts digital signals into analog form. Depending on the digital input given,
a current is generated which is converted into voltage by the DAC. To create a ramp waveform the count is incremented by giving a delay after each increment. Then this is repeated. Time period is calculated depending on the clock.
Waveform: T = 1.1ms
23
;AL=0 ;send AL to Port A ;call a delay ;add 31 to AL ;send AL to Port A ;call delay ;check whether AL=248 ;if not, repeat addition ;if AL=248, go to START ;delay procedure ;value of N for Delay
Procedure: DAC converts digital signals into analog form. Depending on the digital input given, a current is generated which is converted into voltage by the DAC. To create 8 steps total count is divided by 8. So count is to be incremented by 32 after the delay to get a staircase waveform. Waveform: T = 8.2ms each step of approx. 1ms
24
5 8051 Programming
Experiment 5 17th September, 2009
25
2) A program to generate a asymmetric wave with ON time 1 ms and OFF time 0.3 ms.
MAIN: HERE: ORG 0000H SETB P1.3 ACALL DELAY ACALL DELAY ACALL DELAY CLR P1.3 ACALL DELAY SJMP HERE MOV R2,#2 MOV R3,#153 DJNZ R3,AGAIN DJNZ R2,THERE RET ;make P1.3 = 1 ;call delay ;call delay ;call delay ;make P1.3 = 0 ;call delay ;infinite loop ;delay loop for 0.3 msec
END
26
5.2 Miscellaneous
1) A program to add two 64 bit numbers which are in consecutive locations in RAM and store it in RAM.
MAIN: ORG 0000H
MOV R0,#31H MOV R1,#8H MOV DPTR,#40H REPEAT1: CLR A ;loop for moving the 1st number into RAM MOVC A,@A+DPTR MOV @R0,A INC DPTR INC R0 DJNZ R1,REPEAT1 MOV R0,#51H MOV R1,#8H MOV DPTR,#60H REPEAT2: CLR A ;loop for moving the 2nd number into RAM MOVC A,@A+DPTR MOV @R0,A INC DPTR INC R0 DJNZ R1,REPEAT2 CLR C MOV R2,#08 MOV R0,#31H MOV R1,#51H SETB PSW.3 ;select register bank 1 MOV R0,#61H CLR PSW.3 ;select register bank 0 AGAIN: MOV A,@R0 ADDC A,@R1 ;adding the 2 numbers INC R0 INC R1 SETB PSW.3 MOV @R0,A ;sum is moved into RAM and stored INC R0 CLR PSW.3 DJNZ R2,AGAIN ORG 40H DATA1: DB 24H,0AEH,32H,38H,0C0H,32H,0DEH,32H ORG 60H DATA2: DB 54H,0EH,0FCH,81H,2AH,93H,93H,88H END
27
2) A program to store a word `INDIAN' in ROM. Read it from ROM and display it at Port 0. Display one character at a time with a delay between successive displays.
MAIN: BACK: ORG 0000H MOV DPTR,#500H MOV R2,#06 CLR A MOVC A,@A+DPTR MOV P0,A ACALL DELAY INC DPTR DJNZ R2,BACK SJMP HERE MOV R2,#45 DJNZ R2,AGAIN RET ORG 50H DB `I',`N',`D',`I',`A',`N' ;delay procedure ;loop for moving each character to P0 ;DPTR points to the character being displayed
DAT: END
28
3) Write a look up table in ROM for the cubes of decimal numbers. In another ROM location, store the squares. Depending on the status of pin P0.0, get the squares/cubes displayed at Port 1 LEDs.
MAIN: START: ORG 0000H SETB P0.0 JNB P0.0,Square JB P0.0,Cube MOV DPTR,#500H MOV R2,#10 CLR A MOVC A,@A+DPTR MOV P1,A ACALL DELAY INC DPTR DJNZ R2,BACK11 SJMP START MOV DPTR,#700H MOV R2,#08 CLR A MOVC A,@A+DPTR MOV P1,A ACALL DELAY INC DPTR DJNZ R2,BACK SJMP START MOV R2,#60 MOV R3,#255 MOV R4,#255 DJNZ R4,HERE DJNZ R3,AGAIN DJNZ R2,THERE RET ORG 500H DB 0,1,4,9,16,25,36,49,64,81 ORG 700H DB 0,1,8,27,64,125,216,243 ;loop for displaying the contents of DAT2 ;loop for displaying the contents of DAT1 ;setting P0.0 as input port ;if P0.0=0 jump to square ;if P0.0=1 jump to cube
SQUARE: BACK11:
CUBE: BACK:
29
A program to identify a key pressed on hex keyboard interfaced through 8255 to 8086.
CODE SEGMENT ASSUME CS:CODE, DS:CODE ORG 1000H ROW_0 DB 0,1,2,3 ROW_1 DB 4,5,6,7 ROW_2 DB 8,9,0AH,0BH ROW_3 DB 0CH,0DH,0EH,0FH CR EQU 0C6H PA EQU 0C0H PB EQU 0C2H MOV AL, 82H OUT CR, AL MOV AL, 0 OUT PA, AL KEYP: IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP CALL DELAY IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP ROW0: MOV AL, 0FEH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW1 LEA SI, ROW_0 JMP COL_ID ROW1: MOV AL, 0FDH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW2 LEA SI, ROW_1
;address of the control register ;address of Port A ;address of Port B ;8255 control word ;send to control register ;send zeros to all the rows ;read in the columns ;mask the upper nibble ;compare with 0FH ;if equal, no key pressed ;if key press ,wait for debounce time ;after the delay, confirm the key press ;read in the columns ;mask the upper nibble ;compare with 0FH ;if equal, no key pressed ;send `0' to Row0 alone ;read in the columns ;mask the upper nibble ;compare with 0FH ;no key press in Row0, so check Row1 ;not equal, SI to point to Row0 data ;go to finding the column ;send `0' to Row1 alone and repeat steps
30
JMP COL_ID ROW2: MOV AL, 0FBH OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ ROW3 LEA SI, ROW_2 JMP COL_ID ROW3: MOV AL, 0F7H OUT PA, AL IN AL, PB AND AL, 0FH CMP AL, 0FH JZ KEYP LEA SI, ROW_3 COL_ID: SHR AL, 1 JNC FOUND INC SI JMP COL_ID FOUND: MOV BX, 1500H MOV AL, [SI] MOV [BX], AL DELAY PROC NEAR MOV CX, 6000 AGN: LOOP AGN RET DELAY ENDP CODE ENDS END
;to identify the column ,shift right ;if no carry, column is found ;otherwise point SI to next data of row ;go back to finding the column ;get the data pointed by SI into AL ;this is the pressed key, store in KEY ;delay for key debounce
Procedure: The rows and columns are connected to lower four bits of Port A and Port B
respectively. The key press is detected by rst sending zero to all rows and the columns are read. If no key is pressed we get 1111 from PB3 to PB0 else we get a zero corresponding to the column which contains the key pressed. Now to recongnise the row containing the key, the rows are grounded one by one. The columns are read. When the value read is less than 1111, then the row grounded gives the required row. To ensure the a key press detected is valid, key debounce time is given and checked again. If even then the key press is detected the key press is a valid one.
31
1) A program to generate two square waves of frequency 5kHz and 13kHz simultaneously using timers in interrupt mode.
ORG 0000H LJMP NEXT ORG 000BH CPL P1.3 RETI ORG 001BH CPL P2.3 RETI ORG 0030H MOV TMOD,#22H MOV IE,#8AH MOV TH0,#048H MOV TH1,#0B9H SETB TCON.4 SETB TCON.6 SJMP WAIT ;interrupt vector for timer 0 ;toggle P1.3 ;interrupt vector for timer 1 ;toggle P2.3
MAIN:
NEXT:
WAIT: END
;set both the timers in mode 2 ;enable timer0 and timer1 overflow interrupt ;load TH0 value ;load TH1 value ;start timer 0 ;start timer 1
32
33
MAIN: RPT:
AGAIN:
BACK:
END
34
1) A program to generate a symmetric square wave of 11 kHz on any port pin using timer 0 in mode 1.
MAIN: HERE:
ORG 0000H MOV TMOD,#01H MOV TH0,#0FFH MOV TL0,#0ADH CPL P1.3 ACALL DELAY SJMP HERE SETB TCON.4 JNB TCON.5,AGAIN CLR TCON.4 CLR TCON.5 RET ;start timer 0 ;set when rolling over from 0FFFFH to 0000H ;stop timer 0 ;timer 0 in mode 1
DELAY: AGAIN:
END
35
2) A program to generate an asymmetrical square wave with ON time 15 ms and OFF time of 3 ms on pin P0.5 using timer 1 in mode 2.
ORG 0000H MOV TMOD,#20H MOV TH1,#00H SETB P0.5 MOV R2,#5 ACALL DELAY DJNZ R2,HERE CLR P0.5 ACALL DELAY SJMP REP MOV R0,#22 SETB TCON.6 JNB TCON.7,BAK CLR TCON.6 CLR TCON.7 DJNZ R0,AGAIN RET ;start timer 1 ;timer 1 mode 2
END
36
3) A program to a square wave whose one cycle consists of one square wave of period 30 ms followed by three square waves of 10 ms each.
ORG 0000H MOV TMOD,#01H SETB P0.2 ACALL DELAY ACALL DELAY ACALL DELAY CLR P0.2 ACALL DELAY ACALL DELAY ACALL DELAY MOV R0,#3 SETB P0.2 ACALL DELAY CLR P0.2 ACALL DELAY DJNZ R0,BACK SJMP HERE MOV TH0,#0DCH MOV TL0,#03AH SETB TCON.4 JNB TCON.5,AGAIN CLR TCON.4 CLR TCON.5 RET ;timer 0 mode 1
MAIN: HERE:
BACK:
DELAY:
AGAIN:
;start timer 0 ;set when rolling over from 0FFFFH to 0000H ;stop timer 0
END
37
1) A program to generate a symmetric square wave of 25 KHz at any port pin using timer 1 in mode 1.
ORG 0000H LJMP START ORG 001BH CPL P1.0 MOV TH1,#0FFH MOV TL1,#0E3H RETI ORG 0030H MOV TMOD,#10H MOV IE,#88H MOV TH1,#0FFH MOV TL1,#0E3H SETB TCON.6 SJMP HERE ;goto label START ;ISR corresponding to timer 1 ;compliment P0.0 ;load timer
MAIN:
START:
;timer 1 in mod 1 ;enable timer 1 interrupt ;load the timer ;start timer ;wait for interrupt
HERE: END
38
2) A program to generate a square wave with ON time of 2 ms and OFF time of 0.5 ms using timer 0 in mode 1.
ORG 0000H LJMP START ORG 000BH JB P1.7,ONE SETB P1.7 CLR P1.0 MOV TH0,#0F1H MOV TL0,#0ACH RETI CLR P1.7 SETB P1.0 MOV TH0,#0FCH MOV TL0,#06AH RETI ORG 0050H CLR P1.7 MOV TMOD,#01H MOV IE,#82H MOV TH0,#0FCH MOV TL0,#6AH SETB TCON.4 SJMP HERE ;ISR corresponding to timer 0 ;jump if P1.7 = 1 ;set P1.7 ;clear P1.0 ;delay for 2 ms
MAIN:
ONE:
START:
;clear P1.7 ;timer 0 in mod 1 ;enable timer 0 interrupt ;load timer ;start timer 0 ;wait for interrupt
HERE: END
39
MAIN:
SKIP: START:
HERE: END
40