18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Calling Assembly-language Routines<br />

Listing 13-5. Assembly-language sine-wave routine for Figure 13-2’s circuit..<br />

;Reads and copies values in sequence from locations 3000h<br />

;to 30FFh to E400h. A DAC0832 generates a sine wave from<br />

;the values.<br />

;A keypress terminates the routine and returns to BASIC-52.<br />

org 3100h ;load routine above the<br />

;stored values<br />

OutputPort equ 0e400h ;address of port to write<br />

;sine values to<br />

;Begin generating the sine wave:<br />

nextcycle mov 20h,#0ffh ;store initial count at 20h<br />

;in internal<br />

;data memory<br />

nextvalue mov dph,#30h ;put high byte of sine wave<br />

;address (30h)<br />

;in dptr<br />

mov dpl,20h ;copy low byte of sine wave<br />

;address from 20h to dptr<br />

movx a,@dptr ;place sine wave value in<br />

;acc.<br />

mov dptr,#OutputPort ;copy port address<br />

;to dptr<br />

movx @dptr,a ;copy sine wave value to<br />

;output port<br />

djnz 20h,nextvalue ;do another if count > 0<br />

jb ri,return ;after writing one complete<br />

;cycle, check serial receive<br />

;flag and quit if set<br />

sjmp nextcycle ;if serial flag not set,<br />

;begin another cycle<br />

;Return to BASIC-52:<br />

return clr ri ;clear serial receive flag<br />

ret<br />

;return to BASIC<br />

end<br />

<strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong> 229

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!