產(chǎn)生波形實(shí)驗(yàn)(DA轉(zhuǎn)換)
要求:產(chǎn)生某種特定在波形
1/*DA轉(zhuǎn)換實(shí)驗(yàn)例如產(chǎn)生鋸齒波*/23#include45unsignedcharxdataad_cs0_at_0xc000;6unsignedcharxdataad_cs1_at_0xc001;7unsignedcharxdatakey_seg_at_0xd004;8unsignedcharxdatakey_bit_at_0xd002;910sbitEOC=P3^2;11unsignedchardisp_ram[6];12unsignedcharseg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,130x77,0x7c,0x39,0x5e,0x79,0x71,0,0x80};14unsignedcharscan[]={0x01,0x02,0x04,0x08,0x10,0x20};1516voiddelay()17{18unsignedchari,j;19for(i=0;i<200;i++)20for(j=0;j<2;j++);21}2223voidmain()24{25unsignedchari=0;26unsignedcharad_value;27unsignedchartmp,a;28293031disp_ram[0]=17;32disp_ram[1]=16;33disp_ram[2]=16;34disp_ram[3]=16;35disp_ram[4]=16;36disp_ram[5]=16;3738ad_cs0=0;3940while(1)41{42key_bit=scan[i];43a=seg7[disp_ram[i]];44if(i==5)45a=a|0x80;46key_seg=a;47delay();48i++;49i=i%6;5051if(EOC)52{53ad_value=ad_cs0;54disp_ram[5]=ad_value*5/256;55tmp=(ad_value*5)%256;56disp_ram[4]=tmp/100;57disp_ram[3]=(tmp%100)/10;58}59ad_cs0=0;60};616263}