// 正弦波(値:0〜255, データ数:400) PROGMEM prog_uint8_t W[]={0,0,0,0,0,0,1,1,1,1,2,2,2,3,3,4,4,5,5,6,6,7,8,8,9,10,11,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,33,35,36,37,39,40,42,43,45,46,48,50,51,53,54,56,58,59,61,63,65,66,68,70,72,74,75,77,79,81,83,85,87,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,168,170,172,174,176,178,180,181,183,185,187,189,190,192,194,196,197,199,201,202,204,205,207,209,210,212,213,215,216,218,219,220,222,223,224,226,227,228,229,231,232,233,234,235,236,237,238,239,240,241,242,243,244,244,245,246,247,247,248,249,249,250,250,251,251,252,252,253,253,253,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255,254,254,254,254,253,253,253,252,252,251,251,250,250,249,249,248,247,247,246,245,244,244,243,242,241,240,239,238,237,236,235,234,233,232,231,229,228,227,226,224,223,222,220,219,218,216,215,213,212,210,209,207,205,204,202,201,199,197,196,194,192,190,189,187,185,183,181,180,178,176,174,172,170,168,167,165,163,161,159,157,155,153,151,149,147,145,143,141,139,137,135,133,131,129,128,126,124,122,120,118,116,114,112,110,108,106,104,102,100,98,96,94,92,90,88,87,85,83,81,79,77,75,74,72,70,68,66,65,63,61,59,58,56,54,53,51,50,48,46,45,43,42,40,39,37,36,35,33,32,31,29,28,27,26,24,23,22,21,20,19,18,17,16,15,14,13,12,11,11,10,9,8,8,7,6,6,5,5,4,4,3,3,2,2,2,1,1,1,1,0,0,0,0,0}; #define lcdadr(addr) lcdctrl(0x80|addr) void delayus(uint16_t c){ for(TCNT0=0;TCNT0>4); lcdput1(c); } void lcdputs(const prog_char *s){ char c; while((c=pgm_read_byte(s++))!=0) lcdput(c); } void lcdctrl(char c){ lcdput0(c>>4); lcdput0(c); } void lcdclear(){lcdput0(0x00); lcdput0(0x01); delayms(2);} #define lcdstr(a,s) {lcdadr(a);lcdputs(PSTR(s));} void lcdfbk(){ uint16_t num; uint8_t m; if(MODE==DAF){lcdstr(0x00,"DAF・DVF "); lcdstr(0x43,"ms"); num=Pmax/10;} else if(MODE==RAF){ lcdstr(0x00,"RAF・RVF ");lcdstr(0x43,"% "); num=R;} else if(MODE==FAF){ lcdstr(0x00,"FAF ");lcdstr(0x43,"Hz"); num=Fa;} else if(MODE==DTF1){lcdstr(0x00,"DTF 50Hz");lcdstr(0x43,"ms"); num=Pmax*20;} else if(MODE==DTF2){lcdstr(0x00,"DTF 100Hz");lcdstr(0x43,"ms"); num=Pmax*20;} else if(MODE==DTF3){lcdstr(0x00,"DTF 200Hz");lcdstr(0x43,"ms"); num=Pmax*20;} lcdadr(0x40); lcdput((num>=100)?(0x30|(num/100)):' '); lcdput((num>=100||(num%100)/10>0)?(0x30|(num%100)/10):' '); lcdput(0x30|(num%10)); } void lcddb(uint8_t num){ // num: 0..13 lcdstr(0x0c,"ATT"); if(num==13){ lcdstr(0x4a," 0dB"); } else{ num=pgm_read_byte(&dB[num]); if(num==255){ lcdstr(0x4a," ---"); } else{ lcdadr(0x4a); lcdput('-'); lcdput((num/10>0)?(0x30|num/10):' '); lcdput(0x30|(num%10)); lcdput('d');lcdput('B'); } } } void lcdinit(){ delayms(15); lcdput0(0x03); delayms(5); lcdput0(0x03); delayms(1); lcdput0(0x03); lcdput0(0x02); lcdctrl(0x2c); // N=1, F=1 lcdctrl(0x0c); // D=1, C=0, B=0 lcdctrl(0x06); // I/D=1, S=0 lcdclear(); } void daout(int16_t c){ if(mute>0) mute--; else{ if(c<0) c=0; else if(c>=256) c=255; PORTB=0x06; // SS=0 SPDR=(c>>4)|0x30; while((SPSR&0x80)==0); SPDR=(c<<4); while((SPSR&0x80)==0); PORTB=0x07; // SS=1 } } void daout10(int16_t c){ // 000000dd dddddddd uint16_t u; if(mute>0) mute--; else{ if(c<0) c=0; else if(c>=1024) c=1023; OCR5B=c; if(c>=(512-NG)&&c<=(512+NG)) OCR5A=1023; else if(c>=512) OCR5A=((1023-c)<<1); else OCR5A=(c<<1); PORTB=0x06; // SS=0 SPDR=(c>>6)|0x0030; while((SPSR&0x80)==0); SPDR=(c<<2)&0x00ff; while((SPSR&0x80)==0); PORTB=0x07; // SS=1 } } void daout12(int16_t c){ // 0000dddd dddddddd if(mute>0) mute--; else{ if(c<0) c=0; else if(c>=4096) c=4095; PORTB=0x06; // SS=0 SPDR=(c>>8)|0x30; while((SPSR&0x80)==0); SPDR=c; while((SPSR&0x80)==0); PORTB=0x07; // SS=1 } } void dbout(uint16_t c){ PORTB=0x06; // SS=0 SPDR=(c>>8)|0xb0; while((SPSR&0x80)==0); SPDR=(c&0x00ff); while((SPSR&0x80)==0); PORTB=0x07; // SS=1 }