| ??? 05/26/02 06:11 Read: times |
#23441 - RE: compile a simple sample program part 2 |
Jeff,
ASM is ok give it a little time. Your program works fine alternating LEDs. Now depending on how fast your micro is executing how fast the blink rate will be. If your program executes at 11.0592MHz the the blink rate can be determined by refering to Andy Neil's User Page where he has a spread sheet of opcodes and std 8051 machine cycle clock timing. a "djnz" takes 24 clock cycles so (1/11.0592Mhz)*24 =~2.2us. Your loop uses "djnz" with an inner and outer loop scheme. You first delay 255 (not 256) times djnz (2.2us)=~563us. You then execute a djnz (2.2us+563us=565.2us) looping until the outer loop count is exhausted (255 times) so 255*565us=~144ms. Usually you want to blink a led at a slower rate. Why not try the following version of your program. (i assume a "low bit illuminates the led).
$mod51
org 00h
jmp start ;It's good practice to jump
; over the interrupt vectors
org 40H
start:
clr a ;Preset zero for reg loading
mov r0,a ;Init .. the minor loop count
mov r1,a ; .. the major loop count
setb p2.0 ; .. LEDs into alternate states
clr p2.3
; *** LED State Delay Loop ***
loop:
mul ab ;this instr. used just for delay
mul ab ; MUL AB = 48 cycles or 4.3us
mul ab
mul ab
djnz r1,loop ;Down count the minor loop
; *** inner loop count exhausted ***
djnz r0,loop ;Down count the major loop
; *** alternate the illumination state of both LEDs ***
cpl p2.0
cpl p2.3
jmp loop ;Restart the state delay
end
|



