产生波形实验(DA转换)
2017-01-20 来源:eefocus
要求:产生某种特定在波形
1 /*DA转换实验 例如产生锯齿波*/ 2 3 #include4 5 unsigned char xdata ad_cs0 _at_ 0xc000; 6 unsigned char xdata ad_cs1 _at_ 0xc001 ; 7 unsigned char xdata key_seg _at_ 0xd004; 8 unsigned char xdata key_bit _at_ 0xd002; 9 10 sbit EOC=P3^2; 11 unsigned char disp_ram[6]; 12 unsigned char seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 13 0x77,0x7c,0x39,0x5e,0x79,0x71,0,0x80}; 14 unsigned char scan[]={0x01,0x02,0x04,0x08,0x10,0x20}; 15 16 void delay() 17 { 18 unsigned char i,j; 19 for (i=0;i<200;i++) 20 for (j=0;j<2;j++); 21 } 22 23 void main() 24 { 25 unsigned char i=0; 26 unsigned char ad_value; 27 unsigned char tmp,a; 28 29 30 31 disp_ram[0]=17; 32 disp_ram[1]=16; 33 disp_ram[2]=16; 34 disp_ram[3]=16; 35 disp_ram[4]=16; 36 disp_ram[5]=16; 37 38 ad_cs0=0; 39 40 while(1) 41 { 42 key_bit=scan[i]; 43 a=seg7[disp_ram[i]]; 44 if (i==5) 45 a=a|0x80; 46 key_seg=a; 47 delay(); 48 i++; 49 i=i%6 ; 50 51 if (EOC) 52 { 53 ad_value=ad_cs0; 54 disp_ram[5]=ad_value*5/256; 55 tmp=(ad_value*5)%256; 56 disp_ram[4]=tmp/100; 57 disp_ram[3]=(tmp%100)/10; 58 } 59 ad_cs0=0; 60 } ; 61 62 63 }
上一篇:按键盘数码管流动显示实验
下一篇:电压表实验(AD转换)
相关文章