#include "E:\MPLAB\p16c711.INC" __CONFIG 0x3FF2 ;Registers for the NCO DAC DAC equ 0x0C ;Holding reg. for DAC value PACC equ 0x0D ;Phase Accumulator ;Registers for the sinewave generation LUPCNT equ 0x0E ;Loop cntr for sin updates INDEX equ 0x0F ;Index into the lookup table ;Reset Vector: org 0 goto START ;SINE Lookup Table, one cycle, 16 values org 0x10 SINTBL addwf PCL,f retlw d'128' retlw d'177' retlw d'219' retlw d'246' retlw d'255' retlw d'246' retlw d'219' retlw d'177' retlw d'128' retlw d'79' retlw d'37' retlw d'10' retlw d'1' retlw d'10' retlw d'37' retlw d'79' ;Initialize ports and registers ;Initialize WDT, DDRs, Regs START bsf STATUS,RP0 ;Page 1 movlw 0x08 ;Presc-WDT, 1:1 movwf 0x81 ;Setup WDT & TMR0 ;Setup Ports A&B movlw 3 ;RA0,1 are Ins movwf TRISA ;RA2,3,4 are Outs ;Setup ADCON1 movlw 3 ;Make PORTA movwf ADCON1 ; Dig I/O bcf STATUS,RP0 ;Page 0 clrf PACC ;Clear phase accumulator clrf LUPCNT ;Clear the loop counter movlw 0x80 ;Start the output movwf DAC ; at midscale ;Main loop MAIN incf LUPCNT,f ;1 more pass thru btfsc LUPCNT,5 ;When 32 cnts have elapsed, call GETSIN ; get the next value call NCO ;Update the output goto MAIN ;Subroutine that gets the sine value from lookup. Loop counter ; gets reset. INDEX increments to point to the next DAC value. ;Restart counter, update INDEX GETSIN clrf LUPCNT incf INDEX,f btfsc INDEX,4 clrf INDEX ;Get the Sine value from lookup table. movf INDEX,w ;Pass INDEX in 'w' to call SINTBL ; the lookup table movwf DAC ;Save returned value in DAC return ;Subroutine that updates the phase accumulator and sends the ; carry bit to PORTA bit 2. NCO movf DAC,w ;Get DAC value addwf PACC,f ;Add it to the phase accum. movlw b'00000' ;Reset bit 2 btfsc STATUS,C ;If C = 1, movlw b'00100' ; Set bit 2 movwf PORTA ;Send it to PORTA return END ______________________________________________________________________