logo

Select Sidearea

Populate the sidearea with useful widgets. Itโ€™s simple to add images, categories, latest post, social media icon links, tag clouds, and more.
[email protected]
+1234567890
 

Searching to Find Data Max in RAM 8051 Microcontroller

Probably, this subroutine is my best routine that I ever design, in this routine you can find maximum data or biggest data that save in RAM, in this routine w’ll be save 30 data 16 bit in RAM, by compare 1st data and 2nd data, 2nd data and 3rd data and etc, we can find biggest data in RAM.

;==========================================================; Subrutine SearchingMax ( Oleh: Triwiyanto ) 
; Email: [email protected];==========================================================;This subroutine is to search data 16 bit betwen 30 data
;with metode, to compare data betwen now and next data
;RAM have capacity only 1 byte so low byte will be saved to 30h .. 40h;and high byte will be saved on 50h..61h;by using the algorith from high programmming language then :;===========================================================;DataMax:=DataNext[0] ;for i:=1 to 30 do;  begin ;   if DataNext[i] > DataMax then DataMax := DataNext[i];  end;=======================================================;How to detect if a data is bigger then others, is
; by using instruction SUBB A,Data and JNC Label ; for example A=19, Data=20 then  C = 1;             A=21, Data=20 then  C = 0;=======================================================SearchingMax:          mov R7,#30    ;number address ram is 2 x 30 address Low and High         mov R0,#30h   ;RAM location to save Low Byte         mov R1,#50h   ;RAM location to save High Byte          mov DataCounter_MaxL,@R0;saving data @R0 to RAM DataCounter_MaxL         mov DataCounter_MaxH,@R1;saving data @R1 to RAM DataCounter_MaxHNextData:         inc R0        ;Increment Address Location=30h+i           inc R1        ;Increment Address Location=50h+i         mov DataCounter_NextL,@R0         mov DataCounter_NextH,@R1;         mov A,DataCounter_NextL         clr C         subb A,DataCounter_MaxL         mov A,DataCounter_NextH         subb A,DataCounter_MaxH;          jnc SaveDataCounterMax         djnz R7,NextData         Sjmp QuitSSaveDataCounterMax:         mov DataCounter_MaxL,DataCounter_NextL         mov DataCounter_MaxH,DataCounter_NextH          djnz R7,NextDataQuitS:   ret;