Tampilkan postingan dengan label LCD. Tampilkan semua postingan
Tampilkan postingan dengan label LCD. Tampilkan semua postingan

Senin, 29 September 2008

Writing "Hello World" to LCD Character in the Upper Left firs Line.


In this lesson, you can try to write word " Hello World " in first line of LCD Character.

Step 1st
Build the circuit as shown in figure 2.11. As you seen on figure 2.11. P0.0 trough P0.7 is connected to DB0 - DB7,and P2.0- P2.1. is connected to RS and EN each. Remember, that all we want to do with this lesson is write " Hello World ", in the first line of LCD Character, below the schematic


Step 2nd
In this step, you must tipe the assembly program to make your LCD Character shown the word, we assume that you have already known the editor, we used RIDE-51 to edit the program.

       org 0h
start: call init_LCD
mov R1,#80h
call write_inst
mov R1,#'H'
call write_data
mov R1,#'e'
call write_data
mov R1,#'l'
call write_data
mov R1,#'l'
call write_data
mov R1,#'o'
call write_data
mov R1,#' '
call write_data
mov R1,#'W'
call write_data
mov R1,#'o'
call write_data
mov R1,#'r'
call write_data
mov R1,#'l'
call write_data
mov R1,#'d'
call write_data
EndChar:
sjmp Endchar

Init_lcd:
mov r1,#00000001b ;Display clear
acall write_inst ;
mov r1,#00111000b ;Function set,
;Data 8 bit,2 line font 5x7
acall write_inst ;
mov r1,#00001100b ;Display on,
;cursor off,cursor blink off
acall write_inst
mov r1,#00000110b ;Entry mode, Set increment
acall write_inst
ret
;
Write_inst:
clr P2.0 ; RS = P2.0 = 0, write mode instruction
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr P2.1 ; EN = 0 = P2.1
ret
;
Write_data:
setb P2.0 ; RS = P2.0 = 1, write mode data
mov P0,R1 ; D7 s/d D0 = P0 = R1
setb P2.1 ; EN = 1 = P2.1
call delay; call delay time
clr p2.1 ; EN = 0 = P2.1
ret
;
delay: mov R0,#0
delay1:mov R7,#0fh
djnz R7,$
djnz R0,delay1
ret
;
end

Step 3rd

Safe your assembly program above, and name it with lcd1.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 ( lcd1.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 the 7 segmen ( of course if your cable connection and your program are corrected ).

Moving Display


In this lesson, we are going to drive 8 x7 segmen, in this way you can write eight character on multi 7 segmen. We used a multiplexing methode to transfer data for driver transistor consequtively.

Step 1st
Build the circuit as shown in figure 2.3.5. As you seen on figure 2.3.5. P2.0 trough P2.7 is connected to driver transistor, and all eight 7 segment is connected to P0.0 trough P0.6 parallelly. Remember, that all we want to do with this lesson is to write ( k-O-n-P-U-t-E-r ) to 1st, 2nd, 3rd, 4th, 5th, 6th, 7th and 8th 7 segmen each sifting the word to the left.

Step 2nd
In this step, you must tipe the assembly program to make your 7 segmen shown some number on 7 segmen, we assume that you have already known the editor, we used RIDE-51 to edit the program.

       org 0h
Begin: mov r1,#150
start1: mov dptr,#word1
mov r5,#8
mov r2,#01111111b
again1: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again1
djnz r1,start1
mov r1,#150
start2: mov dptr,#word2
mov r5,#8
mov r2,#01111111b
again2: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again2
djnz r1,start2
mov r1,#150
start3: mov dptr,#word3
mov r5,#8
mov r2,#01111111b
again3: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again3
djnz r1,start3
mov r1,#150
start4: mov dptr,#word4
mov r5,#8
mov r2,#01111111b
again4: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again4
djnz r1,start4
mov r1,#150
start5: mov dptr,#word5
mov r5,#8
mov r2,#01111111b
again5: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again5
djnz r1,start5
mov r1,#150
start6: mov dptr,#word6
mov r5,#8
mov r2,#01111111b
again6: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again6
djnz r1,start6
mov r1,#150
start7: mov dptr,#word7
mov r5,#8
mov r2,#01111111b
again7: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again7
djnz r1,start7
mov r1,#150
start8: mov dptr,#word8
mov r5,#8
mov r2,#01111111b
again8: clr A
movc A,@A+dptr
inc dptr
mov p2,A
mov A,r2
mov p3,A
rr A
mov r2,A
acall delay
mov p2,#11111111b
djnz r5,again8
djnz r1,start8
ljmp begin
;
delay: mov r3,#10
delay1: mov r4,#10
djnz r4,$
djnz r3,delay1
ret
;
word1: db 10001010b,11000000b,11001000b,10001100b
db 11000001b,10000111b,10000110b,11001110b
word2: db 11000000b,11001000b,10001100b,11000001b
db 10000111b,10000110b,11001110b,10001010b
word3: db 11001000b,10001100b,11000001b,10000111b
db 10000110b,11001110b,10001010b,11000000b
word4: db 10001100b,11000001b,10000111b,10000110b
db 11001110b,10001010b,11000000b,11001000b
word5: db 11000001b,10000111b,10000110b,11001110b
db 10001010b,11000000b,11001000b,10001100b
word6: db 10000111b,10000110b,11001110b,10001010b
db 11000000b,11001000b,10001100b,11000001b
word7: db 10000110b,11001110b,10001010b,11000000b
db 11001000b,10001100b,11000001b,10000111b
word8: db 11001110b,10001010b,11000000b,11001000b
db 10001100b,11000001b,10000111b,10000110b
end
end

Step 3rd
Safe your assembly program above, and name it with *.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 ( *.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 the 7 segmen( of course if your cable connection and your program are corrected ).

8 x 7 Segmen Multiplexing



Writing multi character on 8 x 7 segmen

In this lesson, we are going to drive more 7 segmen, in this way you can write eight character or number on multi 7 segmen. We used a multiplexing methode to transfer data for driver transistor consequtively.

Step 1st
Build the circuit as shown in figure 2.3.5. As you seen on figure 2.3.5. P2.0 trough P2.7 is connected to driver transistor, and all eight 7 segment is connected to P0.0 trough P0.6 parallelly. Remember, that all we want to do with this lesson is write multi number ( 1-2-3-4-5-6-7-8 ) to 1st, 2nd, 3rd, 4th, 5th, 6th, 7th and 8th 7 segmen each.

Step 2nd
In this step, you must tipe the assembly program to make your 7 segmen shown some number on 7 segmen, we assume that you have already known the editor, we used RIDE-51 to edit the program.Below the schematic of 8 seven segmen multiplexing.

       org 0h
start: mov P0,#11111001b;write a number '1'
clr P2.7 ;turn on 1st 7 segment
call delay ;call delay time
setb P2.7 ;turn off 1st 7 segment
;
mov P0,#11011011b;write a number '2'
clr P2.6 ;turn on 2nd 7 segment
call delay ;call delay time
setb P2.6 ;turn off 2nd 7 segment
;
mov P0,#10110000b;write a number '3'
clr P2.5 ;turn on 3rd 7 segment
call delay ;call delay time
setb P2.5 ;turn off 3rd 7 segment
;
mov P0,#10011001b;write a number '4'
clr P2.4 ;turn on 4th 7 segment
call delay ;call delay time
setb P2.4 ;turn off 4th 7 segment
;
mov P0,#10010010b;write a number '5'
clr P2.3 ;turn on 5th 7 segment
call delay ;call delay time
setb P2.3 ;turn off 5th 7 segment
;
mov P0,#10000010b;write a number '6'
clr P2.2 ;turn on 2nd 7 segment
call delay ;call delay time
setb P2.2 ;turn off 2nd 7 segment
;
mov P0,#11111000b;write a number '7'
clr P2.1 ;turn on 7th 7 segment
call delay ;call delay time
setb P2.1 ;turn off 7th 7 segment
;
mov P0,#10000000b;write a number '8'
clr P2.0 ;turn on 8th 7 segment
call delay ;call delay time
setb P2.0 ;turn off 8th 7 segment
sjmp start ;jump forever
;=============================================
;subroutine delay created to rise delay time
;=============================================
delay: mov R1,#255
del1: mov R2,#255
del2: djnz R2,del2
djnz R1,del1
ret
end

Step 3rd
Safe your assembly program above, and name it with 7seg3.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 ( 7seg3.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 the 7 segmen( of course if your cable connection and your program are corrected ).

Programming Microcontroller H Bridge Motor

Assembly programming
CODE:
L293D_A equ P2.0 ;L293D A - Positive of Motor
L293D_B equ P2.1 ;L293D B - Negative of Motor
L293D_E equ P2.2 ;L293D E - Enable pin of IC

org 0H
Main:
acall rotate_f ;Rotate motor forward
acall delay ;Let the motor rotate
acall break ;Stop the motor
acall delay ;Wait for some time
acall rotate_b ;Rotate motor backward
acall delay ;Let the motor rotate
acall break ;Stop the motor
acall delay ;Wait for some time
sjmp Main ;Do this in loop

rotate_f:
setb L293D_A ;Make Positive of motor 1
clr L293D_B ;Make negative of motor 0
setb L293D_E ;Enable to run the motor
ret ;Return from routine

rotate_b:
clr L293D_A ;Make positive of motor 0
setb L293D_B ;Make negative of motor 1
setb L293D_E ;Enable to run the motor
ret ;Return from routine

break:
clr L293D_A ;Make Positive of motor 0
clr L293D_B ;Make negative of motor 0
clr L293D_E ;Disable the o/p
ret ;Return from routine

delay: ;Some Delay
mov r7,#20H
back: mov r6,#FFH
back1: mov r5,#FFH
here: djnz r5, here
djnz r6, back1
djnz r7, back
ret

C programming
CODE:
#include #define L293D_A P2_0 //Positive of motor
#define L293D_B P2_1 //Negative of motor
#define L293D_E P2_2 //Enable of L293D

// Function Prototypes
void rotate_f(void); //Forward run funtion
void rotate_b(void); //Backward run function
void breaks(void); //Motor stop function
void delay(void); //Some delay

void main(){ //Our main function
while(1){ //Infinite loop
rotate_f(); //Run forward
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
rotate_b(); //Run Backwards
delay(); //Some delay
breaks(); //Stop
delay(); //Some delay
} //Do this infinitely
}

void rotate_f(){
L293D_A = 1; //Make positive of motor 1
L293D_B = 0; //Make negative of motor 0
L293D_E = 1; //Enable L293D
}

void rotate_b(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 1; //Make negative of motor 1
L293D_E = 1; //Enable L293D
}

void breaks(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 0; //Make negative of motor 0
L293D_E = 0; //Disable L293D
}

void delay(){ //Some delay...
unsigned char i,j,k;
for(i=0;i<0x20;i++)
for(j=0;j<255;j++)
for(k=0;k<255;k++);
}