/*DA转换实验 例如产生锯齿波*/
#include <reg52.h>
unsigned char xdata ad_cs0 _at_ 0xc000;
unsigned char xdata ad_cs1 _at_ 0xc001 ;
unsigned char xdata key_seg _at_ 0xd004;
unsigned char xdata key_bit _at_ 0xd002;
sbit EOC=P3^2;
unsigned char disp_ram[6];
unsigned char seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71,0,0x80};
unsigned char scan[]={0x01,0x02,0x04,0x08,0x10,0x20};
void delay()
{
unsigned char i,j;
for (i=0;i<200;i++)
for (j=0;j<2;j++);
}
void main()
{
unsigned char i=0;
unsigned char ad_value;
unsigned char tmp,a;
disp_ram[0]=17;
disp_ram[1]=16;
disp_ram[2]=16;
disp_ram[3]=16;
disp_ram[4]=16;
disp_ram[5]=16;
ad_cs0=0;
while(1)
{
key_bit=scan[i];
a=seg7[disp_ram[i]];
if (i==5)
a=a|0x80;
key_seg=a;
delay();
i++;
i=i%6 ;
if (EOC)
{
ad_value=ad_cs0;
disp_ram[5]=ad_value*5/256;
tmp=(ad_value*5)%256;
disp_ram[4]=tmp/100;
disp_ram[3]=(tmp%100)/10;
}
ad_cs0=0;
} ;
}
DA转换 Code
#include <reg52.h>
unsigned char xdata ad_cs0 _at_ 0xc000;
unsigned char xdata ad_cs1 _at_ 0xc001 ;
unsigned char xdata key_seg _at_ 0xd004;
unsigned char xdata key_bit _at_ 0xd002;
sbit EOC=P3^2;
unsigned char disp_ram[6];
unsigned char seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71,0,0x80};
unsigned char scan[]={0x01,0x02,0x04,0x08,0x10,0x20};
void delay()
{
unsigned char i,j;
for (i=0;i<200;i++)
for (j=0;j<2;j++);
}
void main()
{
unsigned char i=0;
unsigned char ad_value;
unsigned char tmp,a;
disp_ram[0]=17;
disp_ram[1]=16;
disp_ram[2]=16;
disp_ram[3]=16;
disp_ram[4]=16;
disp_ram[5]=16;
ad_cs0=0;
while(1)
{
key_bit=scan[i];
a=seg7[disp_ram[i]];
if (i==5)
a=a|0x80;
key_seg=a;
delay();
i++;
i=i%6 ;
if (EOC)
{
ad_value=ad_cs0;
disp_ram[5]=ad_value*5/256;
tmp=(ad_value*5)%256;
disp_ram[4]=tmp/100;
disp_ram[3]=(tmp%100)/10;
}
ad_cs0=0;
} ;
}
DA转换 Code