Tampilkan postingan dengan label L293. Tampilkan semua postingan
Tampilkan postingan dengan label L293. Tampilkan semua postingan

Senin, 29 September 2008

L293D Dual H-Bridge Motor Driver


L293D is a dual H-Bridge motor driver, So with one IC we can interface two DC motors which can be controlled in both clockwise and counter clockwise direction and if you have motor with fix direction of motion the you can make use of all the four I/Os to connect up to four DC motors. L293D has output current of 600mA and peak output current of 1.2A per channel. Moreover for protection of circuit from back EMF ouput diodes are included within the IC. The output supply (VCC2) has a wide range from 4.5V to 36V, which has made L293D a best choice for DC motor driver.

A simple schematic for interfacing a DC motor using L293D is shown side.

As you can see in the circuit, three pins are needed for interfacing a DC motor (A, B, Enable). If you want the o/p to be enabled completely then you can connect Enable to VCC and only 2 pins needed from controller to make the motor work.


As per the truth mentioned in the image above its fairly simple to program the microcontroller. Its also clear from the truth table of BJT circuit and L293D the programming will be same for both of them, just keeping in mind the allowed combinations of A and B. We will discuss about programming in C as well as assembly for running motor with the help of a microcontroller.

Displaying data ADC 0804 in 8x7 Segmen as a Decimal


In this lesson will be learn how to display data ADC on 8 x 7 segmen, for a simple task, we assume ADC have input ranges 0 - 5 volt, and then will display data as desimal that must be 3 digit 0 - 255, and each digit would be placed on 3rd, 2nd and 1st 7 segmen.

Figure 2.5.2. Connecting ADC and display to 7 segmen

Step 1st
Build the circuit as shown in figure 2.5.2. As you seen on figure 2.5.2. P3.0 trough P3.7 is connected to DB0 - DB7 ADC0804, and P2.0- P2.7. is connected to transistor driver, and P3.0 trough P3.7. is connected to 7 Segmen. Remember, that all we want to do with this lesson is write data ADC, to 8 x 7 Segmen.

Step 2nd
In this step, you must tipe the assembly program to make your 8 x 7 Segmen shown the data, we assume that you have already known the editor, we used RIDE-51 to edit the program. ( Download File asm : exp252.zip)

      org 0h
hundreds equ 30h
tens equ 31h
ones equ 32h
start: call ADC
call Bin2Dec
call Display2SevenSegmen
sjmp start
;
;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
ADC: mov A,P0
nop
nop
ret
;
;========================================================
;this subroutine is used to convert binary data from ADC
;become decimal 3 digit
;========================================================
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret
;===============================================
;this subroutine is used to convert data ADC to
;8 x 7 segmen
;===============================================
Display2SevenSegmen:
Mov P2,#11111111b
mov A, Hundreds
mov DPTR,#Data7segmen
movc A,@A+DPTR
mov P0,A
clr P2.5
call delay
;
mov A,tens
mov DPTR,#Data7segmen
movc A,@A+DPTR
setb P1.5
mov P0,A
clr P2.6
call delay
;
mov A,ones
mov DPTR,#Data7segmen
movc A,@A+DPTR
setb P1.6
mov P0,A
clr P2.7
call delay
ret
;
delay: mov R0,#0
delay1:mov R2,#0fh
djnz R2,$
djnz R0,delay1
ret
;
Data7segmen:
db 11000000b,11111001b,10100100b,10110000b,10011001b
db 10010010b,10000010b,11111000b,10000000b,10010000b
end

Step 3rd
Safe your assembly program above, and name it with adc2.asm (for example) Compile the program that you have been save by using RIDE-51, see the software instruction.

Step 4th
Download your hex file into the microcontroller by using Microcontroller Laros ATMEL ISP software, see the instruction.After download this hex file you'll see the action of ADC ( of course if your cable connection and your program are corrected )

Display Keypad 4 x 4 with 8x7 Seven Segmen


Continuing your sucsess, will try your knowledge with more complex experiment by read out the keypad 4 x 4 data with 8x7 Seven Segmen.
Figure 2.8.4.Keypad Connection to Microcontroller with 8x7 segmen

Step 1st
Build the circuit as shown in figure 2.8.4. As you seen on figure 2.8.4 P3.0 trough P3.7 is connected to keypad 4 x 4 and 8 x 7 Segmen to read keypad data, connected to P0.0 trough P0.7., P2.0 and P2.1 connected to RS and EN each.

Step 2nd
In this step, you must tipe the assembly program to scan your keypad data, we assume that you have already known the editor, we used RIDE-51 to edit the program. ( Download File asm : exp283.zip )

;the following experiment is used to scan
;keypad 4x4 and result of scan will be released
;to Display 7 Segmen
row1 bit P3.4
row2 bit P3.5
row3 bit P3.6
row4 bit P3.7
col1 bit P3.0
col2 bit P3.1
col3 bit P3.2
col4 bit P3.3
;
keydata equ 70h
keybounc equ 71h
keyport equ P2
org 0h
start: call keypad4x4 ;calling subrutine keypad4x4
Mov A,keydata ;A = keydata
Cjne A,#0FFh,Wr7Seg;
sjmp start ;LOOPING FOREVER PART 1
;
Wr7Seg:
;================================================
;I left the assembly instruction for you to learn
;=================================================
;
delay: mov R0,#0
delay1:mov R2,#50
djnz R2,$
djnz R0,delay1
ret
;
;====================================
; subroutine scan keypad 4x4
;====================================
Keypad4x4:
mov keybounc,#50 ;keybounc = 50
mov keyport,#0FFh ;keyport=P2= FF
clr col1 ;col1= P3.0 = 0
Detect:jb row1,key1 ;jump to Key1 if row=1
djnz keybounc,Detect
mov keydata,#00h ;Keydata =00h
ret
;
key1: jb row2,key2 ;jump to key2 if row2=1
djnz keybounc,key1
mov keydata,#04h ;Keydata = 04h
ret
;
key2: jb row3,key3 ; idem
djnz keybounc,key2
mov keydata,#08h
ret
;
key3: jb row4,key4 ; idem
djnz keybounc,key3
mov keydata,#0Ch
ret
;
key4: setb col1
clr col2
jb row1,key5
djnz keybounc,key4
mov keydata,#01h
ret
;
key5: jb row2,key6
djnz keybounc,key5
mov keydata,#05h
ret
;
key6: jb row3,key7
djnz keybounc,key6
mov keydata,#09h
ret
;
key7: jb row4,key8
djnz keybounc,key7
mov keydata,#0Dh
ret
;
key8: setb col2
clr col3
jb row1,key9
djnz keybounc,key8
mov keydata,#02h
ret
;
key9: jb row2,keyA
djnz keybounc,key9
mov keydata,#06h
ret
;
keyA: jb row3,keyB
djnz keybounc,keyA
mov keydata,#0Ah
ret
;
keyB: jb row4,keyC
djnz keybounc,keyB
mov keydata,#0Eh
ret
;
keyC: setb col3
clr col4
jb row1,keyD
djnz keybounc,keyC
mov keydata,#03h
ret
;
keyD: jb row2,keyE
djnz keybounc,keyD
mov keydata,#07h
ret
;
keyE: jb row3,keyF
djnz keybounc,keyE
mov keydata,#0Bh
ret
;
keyF: jb row4,Nokey
djnz keybounc,keyF
mov keydata,#0Fh
ret
Nokey:mov keydata,#0FFh
ret
;================================
;The end of Keypad 4x4 subroutine
;================================
end

Step 3rd
Safe your assembly program above, and name it with key3.asm (for example) Compile the program that you have been save by using MIDE-51, see the software instruction.

Step 4th
Download your hex file ( key3.hex ) into the microcontroller by using Microcontroller Laros ATMEL ISP software, see the instruction.After download this hex file you'll see the action of Keypad 4 x 4 ( of course if your cable connection and your program are corrected )

Displaying data ADC 0804 in 8x7 Segmen as a Decimal


In this lesson will be learn how to display data ADC on 8 x 7 segmen, for a simple task, we assume ADC have input ranges 0 - 5 volt, and then will display data as desimal that must be 3 digit 0 - 255, and each digit would be placed on 3rd, 2nd and 1st 7 segmen.

Figure 2.5.2. Connecting ADC and display to 7 segmen

Step 1st
Build the circuit as shown in figure 2.5.2. As you seen on figure 2.5.2. P3.0 trough P3.7 is connected to DB0 - DB7 ADC0804, and P2.0- P2.7. is connected to transistor driver, and P3.0 trough P3.7. is connected to 7 Segmen. Remember, that all we want to do with this lesson is write data ADC, to 8 x 7 Segmen.

Step 2nd
In this step, you must tipe the assembly program to make your 8 x 7 Segmen shown the data, we assume that you have already known the editor, we used RIDE-51 to edit the program. ( Download File asm : exp252.zip)

org 0h
hundreds equ 30h
tens equ 31h
ones equ 32h
start: call ADC
call Bin2Dec
call Display2SevenSegmen
sjmp start
;
;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
ADC: mov A,P0
nop
nop
ret
;
;========================================================
;this subroutine is used to convert binary data from ADC
;become decimal 3 digit
;========================================================
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret
;===============================================
;this subroutine is used to convert data ADC to
;8 x 7 segmen
;===============================================
Display2SevenSegmen:
Mov P2,#11111111b
mov A, Hundreds
mov DPTR,#Data7segmen
movc A,@A+DPTR
mov P0,A
clr P2.5
call delay
;
mov A,tens
mov DPTR,#Data7segmen
movc A,@A+DPTR
setb P1.5
mov P0,A
clr P2.6
call delay
;
mov A,ones
mov DPTR,#Data7segmen
movc A,@A+DPTR
setb P1.6
mov P0,A
clr P2.7
call delay
ret
;
delay: mov R0,#0
delay1:mov R2,#0fh
djnz R2,$
djnz R0,delay1
ret
;
Data7segmen:
db 11000000b,11111001b,10100100b,10110000b,10011001b
db 10010010b,10000010b,11111000b,10000000b,10010000b
end

Step 3rd
Safe your assembly program above, and name it with adc2.asm (for example) Compile the program that you have been save by using RIDE-51, see the software instruction.

Step 4th
Download your hex file into the microcontroller by using Microcontroller Laros ATMEL ISP software, see the instruction.After download this hex file you'll see the action of ADC ( of course if your cable connection and your program are corrected )