|
Microcontroller Kits
Programmer
and Target 89s51
Simple
Mikrokontroller 89s51 Trainer

Standart
Mikrokontroller 89s51 Trainer

Super Mikrokontroller
Trainer 89s51
+
All Item Include
Programmer
Via USB
|
|
BACK
NEXT
2.2.2. Running LED Right
or Left when you' re push the button
In this lesson, we will command the LED to run
right or left by swichting the button, for example run the LED to the
right when pushing swicht on P2.0 and run the LED to the left when pushing
swicht on P2.1.

Figure 2.2.2. Diagram Skematik Input Data
Step 1st
Build the circuit as shown in figure 2.2.2. As you seen on figure 2.2.2.
P2.0 trough P2.7 is connected to swicht push button each and LED's Katode
is connected to P0.0 trough P0.7. Remember, that all we want to do with
this lesson is make a LED start running to the left or right, by pushing
the button P2.0 or P2.1.
Step 2nd
In this step, you must tipe the assembly program to make your LED on
when you push the swicht, we assume that you have already known the
editor, we used MIDE-51 to edit the program. ( Download
File : exp222.zip )
org 0h CekP20: JB P2.0,CekP21 ; checking P2.0 while get push call RLeft ; if so, call Rotate Left subrutine sjmp CekP20 ; jump forever to CekP20 CekP21: JB P2.1,CekP20 ; checking P2.1 while get push call RRight ; if so, call Rotate Right sjmp CekP20 ; jump forever to CekP2.0 ;=============================================== ;this subroutine is used to move LED to the left. ;================================================ RLeft: mov A,#11111110b;send data to Acc RLeft1: mov P0,A ;send data to P0 call delay ;call delay time JB P2.0,RLeft2 ;checking P2.0 while get push sjmp EndRLeft ;if so, finish Rotate Left RLeft2: RL A sjmp RLeft1 EndRLeft: ret ; ;================================================= ;this subroutine is used to move LED to the right. ;================================================= RRight: mov A,#01111111b RRight1:mov P0,A call delay JB P2.0,RRight2 sjmp EndRRight RRight2:RL A sjmp RRight1 EndRRight: ret ;============================================= ;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 SW2.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 ( SW2.hex ) into the microcontroller
by using Microcontroller ATMEL ISP software, see the instruction.After
download this hex file you'll see the action of the LED ( of course
if your cable connection and your program are corrected ).
Comments,
questions and discussion about this topic
BACK
NEXT
|
|
|
|