函数信号发生器的设计与实现 (1)资料 下载本文

内容发布更新时间 : 2024/11/19 1:48:47星期一 下面是文章的全部内容请认真阅读。

{ while(!key3); if(f>1) f--; } } if(key4==0) { delay1(10); if(key4==0) { while(!key4); A2++; if(A2>5) A2=5; } } if(key5==0) { delay1(10); if(key5==0) { while(!key5); if(A2>1) A2--; } } } void main() { unsigned char i,temp,Atemp,Ftemp; LcdInit();

P1=table[0]; while (1) { temp=wave; keys(); if(temp!=wave) ClrGDRAM(); if(wave==1) { Atemp=A1;Ftemp=f;

keys1(); if(Atemp!=A1) ClrGDRAM(); if(Ftemp!=f) ClrGDRAM(); for(i=0;i<65;i++) WriteDAC(1.0*sanjiao[i]*A1/20,21-f); drawTri(A1,f); //绘制三角波图像. delayms(10); } else if(wave==2) { Atemp=A1;Ftemp=f; keys1(); if(Atemp!=A1) ClrGDRAM(); if(Ftemp!=f) ClrGDRAM(); for(i=0;i<64;i++) WriteDAC(1.0*sin[i]*A1/40,21-f); drawSin(A1,f); //绘制正弦波图像. delayms(10); } else if(wave==3) { Atemp=A2;Ftemp=f; keys2(); if(Atemp!=A2) ClrGDRAM(); if(Ftemp!=f) ClrGDRAM(); for(i=0;i<64;i++) WriteDAC(1.0*fangbo[i]*A2/40,21-f); drawSquare(A2,f); //绘制方波图像. delayms(10); } else if(wave==3) { for(i=0;i<64;i++) if(i%2==0)

}

}

}

WriteDAC(1.0*0xff*A2/40,21-f); else

WriteDAC(0,21-f);

LCD12864.c文件中部分代码:

画点函数:

void drawPoint(unsigned char x,unsigned char y,unsigned char color) {

unsigned char row,collum,cbite; unsigned char tempH,tempL; writeCommand(0x34); writeCommand(0x36); collum=x>>4; cbite=x&0x0f; if(y<32) row=y; else {

row=y-32; collum+=8; }

writeCommand(0x80+row); writeCommand(0x80+collum); readData();

tempH=readData(); tempL=readData();

writeCommand(0x80+row); writeCommand(0x80+collum); if (color) { if(cbite<8) { tempH|=(0x01<<(7-cbite)); } else { tempL|=(0x01<<(15-cbite)); } }

else {

if(cbite<8) { tempH&=~(0x01<<(7-cbite)); } else { tempL&=~(0x01<<(15-cbite)); } }

writeData(tempH); writeData(tempL); writeCommand(0x30); }

绘制三角波函数:

void drawTri(unsigned int A1,f) //绘制三角波图像。参数A幅度,格式为几点几伏, 参数f频率,格式为几十几点几赫兹 { unsigned char x; unsigned int t; char Am[]=\ char Fr[]=\

if(f==1) { for(x=0;x<32;x++) //在液晶屏左半屏绘出 三角波图像(不会随频率f改 变) { drawPoint(x,47-x/4*(A1-9),1); drawPoint(63-x,47-x/4*(A1-9),1); } }

else { for(x=0;x<64/(pow(2,f));x++) //在液晶屏左半屏绘出

三角波图像 (不会随频率f改变) { drawPoint(x,47-x*(pow(2,(f-3)))*(A1-9),1); drawPoint(((128/pow(2,f))-1-x),47-x*(pow(2,(f-3)))*(A1-9),1); } for(x=128/pow(2,f);x<192/(pow(2,f));x++)