;********************************************************************
;
; Author        : ADI - Apps            www.analog.com/MicroConverter
;
; Date          : October 2003
;
; File          : DACsine.asm
;
; Hardware      : ADuC842
;
; Description   : Outputs a sine waves on DAC0 at 1.03kHz.
;                 Rate calculations assume a 2.09 Mclk, pllcon=3
;
;********************************************************************

$MOD842                         ; Use 8052&ADuC842 predefined symbols

LED     EQU     P3.4            ; P3.4 drives red LED on eval board

;____________________________________________________________________
                                                  ; BEGINNING OF CODE
CSEG

ORG 0000h
	MOV	ADCCON1,#80H
	MOV	PLLCON,#03h
        MOV     DACCON,#00Dh    ; DAC0 on, 12bit, asynchronous
        MOV     DAC0H,#008h
        MOV     DAC0L,#000h     ; DAC0 to mid-scale

        MOV     DPTR,#TABLE

STEP:   CLR     A               ;                                   
        MOVC    A,@A+DPTR       ; get high data byte from table..   
        MOV     DAC0H,A         ; ..and move it into DAC register   
        INC     DPTR            ; move on to get low byte           

        CLR     A               ;                                   
        MOVC    A,@A+DPTR       ; get low data byte from table..    
        MOV     DAC0L,A         ; ..and update DAC output           
        INC     DPTR            ; move on for next data point       

        ANL     DPL,#07Fh       ; wrap around at end of table       

        MOV     A,DAC0H         ;                                   
        MOV     C,ACC.3         ; MSB of DAC0 value                 
        MOV     LED,C           ; LED = MSB of DAC0                 

        JMP     STEP            ;                                   

;____________________________________________________________________
                                                  ; SINE LOOKUP TABLE
ORG 01000h

TABLE:

DB  007h, 0FFh
DB  008h, 0C8h
DB  009h, 08Eh
DB  00Ah, 051h
DB  00Bh, 00Fh
DB  00Bh, 0C4h
DB  00Ch, 071h
DB  00Dh, 012h
DB  00Dh, 0A7h
DB  00Eh, 02Eh
DB  00Eh, 0A5h
DB  00Fh, 00Dh
DB  00Fh, 063h
DB  00Fh, 0A6h
DB  00Fh, 0D7h
DB  00Fh, 0F5h
DB  00Fh, 0FFh
DB  00Fh, 0F5h
DB  00Fh, 0D7h
DB  00Fh, 0A6h
DB  00Fh, 063h
DB  00Fh, 00Dh
DB  00Eh, 0A5h
DB  00Eh, 02Eh
DB  00Dh, 0A7h
DB  00Dh, 012h
DB  00Ch, 071h
DB  00Bh, 0C4h
DB  00Bh, 00Fh
DB  00Ah, 051h
DB  009h, 08Eh
DB  008h, 0C8h
DB  007h, 0FFh
DB  007h, 036h
DB  006h, 070h
DB  005h, 0ADh
DB  004h, 0EFh
DB  004h, 03Ah
DB  003h, 08Dh
DB  002h, 0ECh
DB  002h, 057h
DB  001h, 0D0h
DB  001h, 059h
DB  000h, 0F1h
DB  000h, 09Bh
DB  000h, 058h
DB  000h, 027h
DB  000h, 009h
DB  000h, 000h
DB  000h, 009h
DB  000h, 027h
DB  000h, 058h
DB  000h, 09Bh
DB  000h, 0F1h
DB  001h, 059h
DB  001h, 0D0h
DB  002h, 057h
DB  002h, 0ECh
DB  003h, 08Dh
DB  004h, 03Ah
DB  004h, 0EFh
DB  005h, 0ADh
DB  006h, 070h
DB  007h, 036h          ; end of table

;____________________________________________________________________

END
