Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Phillip M Gallo
05/26/02 00:11
Read: 573 times
Torrance
USA


 
#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 



List of 19 messages in thread
TopicAuthorDate
compile a simple sample program part 2      Jeff Corr      05/24/02 17:06      
RE: compile a simple sample program part 2      Erik Malund      05/24/02 17:48      
RE: compile a simple sample program part 2      Phillip M Gallo      05/24/02 18:04      
RE: compile a simple sample program part 2      Jeff Corr      05/24/02 22:35      
RE: compile a simple sample program part 2      Jeff Corr      05/24/02 22:36      
RE: compile a simple sample program part      Steve M. Taylor      05/25/02 00:53      
RE: compile a simple sample program part      Jeff Corr      05/25/02 01:18      
RE: compile a simple sample program part 2      Peter Dannegger      05/25/02 04:22      
RE: compile a simple sample program part 2      Jeff Corr      05/25/02 20:25      
RE: compile a simple sample program part 2      Jeff Corr      05/25/02 20:30      
RE: compile a simple sample program part 2      Phillip M Gallo      05/26/02 00:11      
RE: compile a simple sample program part 2      Phillip M Gallo      05/26/02 00:19      
RE: compile a simple sample program part      Steve M. Taylor      05/26/02 12:56      
RE: compile a simple sample program part      Peter Dannegger      05/27/02 00:25      
RE: compile a simple sample program part      Jeff Corr      05/27/02 01:32      
RE: compile a simple sample program part      Chris Brooks      05/27/02 02:43      
RE: compile a simple sample program part 2      Andy Neil      05/27/02 13:38      
RE: compile a simple sample program part 2      Alexz Haages      05/28/02 13:28      
RE: compile a simple sample program part      Raghavendra Raghav      09/20/02 23:56      

Back to Subject List