; ******************************************* ; * 10Hz - 100KHz D.D.S. FUNCTION GENERATOR * ; * Microcontroller Source Code * ; * Version : 1.0 * ; * © 1998 George Vastianos * ; ******************************************* ; Note : ; This version does not support the frequency ; limits checking, so the LED is always on. .include "1200def.inc" rjmp RESET ;reset handle ;***************************************************** ;* "BCD2BIN" - BCD to 16-Bit Binary Conversion * ;* * ;* This subroutine converts a 6-digit packed BCD * ;* number represented by 3 bytes (fBCD2:fBCD1:fBCD0) * ;* to a 16-bit number divided by 2 (tbinH:tbinL). * ;***************************************************** .def fBCD0 =r16 ;BCD value digits 1 and 0 .def fBCD1 =r17 ;BCD value digits 3 and 2 .def fBCD2 =r18 ;BCD value digits 5 and 4 .def tbinL =r19 ;Low byte of binary result (same as mp10L) .def tbinH =r20 ;High byte of binary result (same as mp10M) .def mp10L =r19 :Low byte of number to be multiplied by 10 .def mp10M =r20 :Mid byte of number to be multiplied by 10 .def mp10H =r21 ;High byte of number to be multiplied by 10 .def copyL =r22 ;temporary register .def copyM =r23 ;temporary register .def copyH =r24 ;temporary register .def adder =r25 ;value to add after multiplication mul10a: swap adder mul10b: mov copyL,mp10L ;make copy mov copyM,mp10M mov copyH,mp10H lsl mp10L ;multiply original by 2 rol mp10M rol mp10H lsl copyL ;multiply copy by 2 rol copyM rol copyH lsl copyL ;multiply copy by 2 (4) rol copyM rol copyH lsl copyL ;multiply copy by 2 (8) rol copyM rol copyH add mp10L,copyL ;add copy to original adc mp10M,copyM adc mp10H,copyH andi adder,0x0f ;mask away upper nibble of adder add mp10L,adder ;add lower nibble of adder clr adder adc mp10M,adder adc mp10H,adder ret BCD2BIN: clr mp10H clr mp10M mov adder,fBCD2 swap adder andi adder,0x0f ;mask away upper nibble of adder mov mp10L,adder ;mp10H:mp10M:mp10L = a mov adder,fBCD2 rcall mul10b ;mp10H:mp10M:mp10L = 10a+b mov adder,fBCD1 rcall mul10a ;mp10H:mp10M:mp10L = 10(10a+b)+c mov adder,fBCD1 rcall mul10b ;mp10H:mp10M:mp10L = 10(10(10a+b)+c)+d mov adder,fBCD0 rcall mul10a ;mp10H:mp10M:mp10L = 10(10(10(10a+b)+c)+d)+e mov adder,fBCD0 rcall mul10b ;mp10H:mp10M:mp10L = 10(10(10(10(10a+b)+c)+d)+e)+f clc ror mp10H ;Divide result by 2 ror mp10M ror mp10L ret ;********************************************* ;* "READTWS" - Read Thunpweel Switches * ;* * ;* This subroutine converts a 6-digit packed * ;* BCD number represented by 3 bytes * ;* (fBCD2:fBCD1:fBCD0) to a 16-bit number * ;* divided by 2 (tbinH:tbinL) * ;********************************************* .def fBCD0 =r16 ;BCD value digits 1 and 0 .def fBCD1 =r17 ;BCD value digits 3 and 2 .def fBCD2 =r18 ;BCD value digits 5 and 4 .def thsl =r19 .def thrd =r20 READTWS: clr fBCD0 ;Clear fBCD0 clr fBCD1 ;Clear fBCD1 clr fBCD2 ;Clear fBCD2 in thsl,PIND ;Read TW1 & TW2 andi thsl,0x40 ori thsl,0x01 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 swap thrd or fBCD0,thrd rcall delay in thsl,PIND andi thsl,0x40 ori thsl,0x02 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 or fBCD0,thrd rcall delay in thsl,PIND ;Read TW3 & TW4 andi thsl,0x40 ori thsl,0x04 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 swap thrd or fBCD1,thrd rcall delay in thsl,PIND andi thsl,0x40 ori thsl,0x08 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 or fBCD1,thrd rcall delay in thsl,PIND ;Read TW5 & TW6 andi thsl,0x40 ori thsl,0x10 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 swap thrd or fBCD2,thrd rcall delay in thsl,PIND andi thsl,0x40 ori thsl,0x20 out PORTD,thsl rcall delay in thrd,PINB andi thrd,0xf0 or fBCD2,thrd rcall delay ret ;********************************* ;* "delay" - Small Delay Routine * ;********************************* .def temp =r26 .def temp2 =r27 delay: ldi temp,$ff ldi temp2,$00 lp1: dec temp cpse temp,temp2 rjmp lp1 lp2: ret ;****************************************** ;* "SEND2DDS" - Send Data To DDS * ;* * ;* This subroutine sends the contents of * ;* the tbinH:tbinL (DDSH:DDSL) to the DDS * ;****************************************** .def DDSL =r21 .def DDSH =r22 .def count =r23 SEND2DDS: in temp,PINB andi temp,0x00 ori temp,0x04 out PORTB,temp rcall delay rcall delay rcall delay ldi count,0x10 lp3: in temp,PINB andi temp,0x04 ori temp,0x02 out PORTB,temp rcall delay rcall delay rcall delay ror DDSH ror DDSL brcs lp4 rjmp lp5 lp4: in temp,PINB andi temp,0x06 ori temp,0x01 out PORTB,temp rcall delay rcall delay rcall delay rjmp lp6 lp5: in temp,PINB andi temp,0x06 out PORTB,temp rcall delay rcall delay rcall delay rjmp lp6 lp6: in temp,PINB andi temp,0x05 out PORTB,temp rcall delay rcall delay rcall delay dec count ldi temp,0x00 cpse count,temp rjmp lp3 rjmp lp7 lp7: in temp,PINB andi temp,0x00 out PORTB,temp rcall delay rcall delay rcall delay ret ;**************** ;* Main Program * ;**************** RESET: ldi temp,0x0f out DDRB,temp ldi temp,0x00 out PORTB,temp ldi temp,0xff out DDRD,temp ldi temp,0x00 out PORTD,temp loop: rcall READTWS rcall BCD2BIN mov DDSH,tbinH mov DDSL,tbinL rcall SEND2DDS rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rcall delay rjmp loop ;****************** ;* End Of Program * ;******************