设计一个能产生三种波形(方波,正弦波,三角波)且频率步进可调的信号发生器。
技术指标 1,按键可以选择方波,正弦波,三角波三种波的波形输出
2,正弦波输出信号频率0~100hz频率步进值10hz
3,方波输出信号频率0~1khz频率步进值10hz
4,三角波输出信号频率0~200hz频率步进值10hz
给出各个部分的电路原理图和总电路图,还有流程图
呵呵 要求比较多 请高手耐心回答 展开
#include<iom16v.h>
#include<macros.h>
void Delayus(unsigned int t);
void INT0_isr(void);
void Init_PORT(void);
void INT0_init(void);
unsigned int select_num,num;
unsigned int pl,zkb;
const unsigned char sin_tab[]=
{
128,130,132,135,137,139,141,143,146,148,
150,152,154,157,159,161,163,165,167,169,
171,174,176,178,180,182,184,186,188,190,
191,193,195,197,199,201,203,204,206,208,
210,211,213,215,216,218,219,221,222,224,
225,227,228,229,231,232,233,235,236,237,
238,239,240,241,242,243,244,245,246,247,
247,248,249,249,250,251,251,252,252,253,
253,253,254,254,254,255,255,255,255,255,
255,255,255,255,255,255,254,254,254,253,
253,253,252,252,251,251,250,249,249,248,
247,247,246,245,244,243,242,241,240,239,
238,237,236,235,233,232,231,229,228,227,
225,224,222,221,219,218,216,215,213,211,
210,208,206,204,203,201,199,197,195,193,
192,190,188,186,184,182,180,178,176,174,
171,169,167,165,163,161,159,157,154,152,
150,148,146,143,141,139,137,135,132,130,
128,126,124,121,119,117,115,113,110,108,
106,104,102, 99, 97, 95, 93, 91, 89, 87,
85,82,80,78,76,74,72,70,68,66,
65,63,61,59,57,55,53,52,50,48,
46,45,43,41,40,38,37,35,34,32,
31,29,28,27,25,24,23,21,20,19,
18,17,16,15,14,13,12,11,10,9,
9,8,7,7,6,5,5,4,4,3,
3,3,2,2,2,1,1,1,1,1,
1,1,1,1,1,1,2,2,2,3,
3,3,4,4,5,5,6,7,7,8,
9,9,10,11,12,13,14,15,16,17,
18,19,20,21,23,24,25,27,28,29,
31,32,34,35,37,38,40,41,43,45,
46,48,50,52,53,55,57,59,61,63,
64,66,68,70,72,74,76,78,80,82,
85,87,89,91,93,95,97,99,102,104,
106,108,110,113,115,117,119,121,124,126
};
const unsigned char table[]={0x3F,/*0*/
0x06,/*1*/
0x5B,/*2*/
0x4F,/*3*/
0x66,/*4*/
0x6D,/*5*/
0x7D,/*6*/
0x07,/*7*/
0x7F,/*8*/
0x6F/*9*/};
void Delayus(unsigned int t)
{
WDR();
do
t--;
while(t>1);
WDR();
}
void Init_PORT(void)
{
PORTA = 0XFF;
DDRA = 0X00;
PORTB = 0X00;
DDRB = 0XFF;
PORTC = 0X00;
DDRC = 0XFF;
PORTD = 0XF4;//0000 0100
DDRD = 0XFB;
}
void INT0_init(void)
{
SREG|=BIT(7);
MCUCR|=0x02;
GICR|=BIT(6);
GIFR|=BIT(6);
}
#pragma interrupt_handler INT0_isr:2
void INT0_isr(void)
{
PORTB|=BIT(0);
Delayus(100);
num=PINA&0X1F;
if(num==0x1E)
{
select_num++;//0001 1110
if(select_num>=4)
select_num=0;
}
if(num==0x1C)pl++;
if(num==0x1B)pl--;
if(num==0x17)zkb++;
if(num==0x0F)zkb--;
}
void main(void)
{
unsigned int ii,jj,nn,mm,kk=100;
Init_PORT();
INT0_init();
while(1)
{
if(select_num==0)
{
for(ii=0;ii<360;ii++)
{
PORTD&=~BIT(0);
PORTC=sin_tab[ii];
Delayus(kk);
PORTD|=BIT(0);
}
}
if(select_num==1)
{
jj=180;//方波宽度可修改
PORTD&=~BIT(0);
PORTC=0XFF;
PORTD|=BIT(0);
do
Delayus(kk);
while(--jj);
jj=180;
PORTD&=~BIT(0);
PORTC=0X00;
PORTD|=BIT(0);
do
Delayus(kk);
while(--jj);
}
if(select_num==2)
{
for(nn=0;nn<255;nn++)//产生上升波
{
PORTD&=~BIT(0);
PORTC=nn;//A口输出上升波
PORTD|=BIT(0);
Delayus(kk);
}
for(nn=255;nn>0;nn--)//产生下降波
{
PORTD&=~BIT(0);
PORTC=nn;//A口输出下降波
PORTD|=BIT(0);
Delayus(kk);//延时
}
}
if(select_num==3)
{
if(mm==0)mm=256;
PORTD&=~BIT(0);
PORTC=mm--;
PORTD|=BIT(0);
Delayus(kk);
}
}
}