/******************************************************/ /** DDS Subtone Generator (c)2003 by SV6GMP **/ /** Stavros S. Fotoglou **/ /******************************************************/ #include #include #include #include #define TEST_TIM (1<<5) #define SUBTONE_EN (1<<0) #define PTT_PRESSD (1<<1) typedef unsigned char u08; typedef unsigned short u16; void delay(u16); // Sinus table u08 __attribute__ ((progmem)) sinvals[] = {0, //t0 0, //t1 0, //t2 1, //t3 1, //t4 2, //t5 3, //t6 4, //t7 5, //t8 6, //t9 7, //t10 8, //t11 10, //t12 11, //t13 13, //t14 14, //t15 16, //t16 18, //t17 19, //t18 21, //t19 22, //t20 24, //t21 25, //t22 26, //t23 27, //t24 28, //t25 29, //t26 30, //t27 30, //t28 31, //t29 31, //t30 31}; //t31 u08 __attribute__ ((progmem)) divider[8][2] = {{0xfc, 0xf2}, //C-77 {0xfd, 0x29}, //D-82,5 {0xfd, 0x5c}, //E-88,5 {0xfd, 0x73}, //--91,5 {0xfd, 0x8b}, //F-94,8 {0xfd, 0xc2}, //G-103,5 {0xfd, 0xeb}, //H-110,9 {0xfe, 0x10}}; //J-118,8 u08 s, tcnth, tcntl, flag; SIGNAL(SIG_OVERFLOW1) { static u08 ti; u08 ampl, idx; //outp(0xfd, TCNT1H); //outp(0xc4, TCNT1L); outp(tcnth, TCNT1H); //Reload timer, Hi byte first outp(tcntl, TCNT1L); s = inp(PORTB); s = s & 0xe0; if (s & TEST_TIM) s = s & (~TEST_TIM); else s = s | TEST_TIM; if (ti & 32) { idx = 31 - ti; } else idx=ti; idx = idx & 0x1f; ampl = PRG_RDB(&sinvals[idx]); ti=ti+1; ampl = ampl & 0x1f; if ((flag & SUBTONE_EN) && (flag & PTT_PRESSD)) s = s | ampl; outp(s, PORTB); } int main(void) { u08 dip; outp(0xff, DDRB); //Port B is output outp(0xff, PORTB); //All outs hi outp(0, DDRD); //Port D is input outp(0x1f, PORTD); //Pull up 5 lower bits outp((1<