C51单片机学习(实验)
DA(数模)转换——(DAC0832)
DAC硬件测试 仿真图——逻辑电平控制
用直通的方式产生方波、三角波和锯齿波
C程序
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P1^0;
void Delay1ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
void sanjiaobo()
{
uchar i;
for(i=0;i<255;i++){
P2=i;
}
for(i=255;i>0;i--){
P2=i;
}
}
void jiaobo()
{
uchar i;
for(i=0;i<255;i++){
P2=i;
}
}
void fangbo()
{
P2=0;
Delay1ms();
P2=255;
Delay1ms();
}
void main()
{
uchar count=1;
while(1){
if(key==0)
{
while (key==0){};
count++;
}
if(count==1){sanjiaobo();}
if(count==2){fangbo();}
if(count==3){jiaobo();}
if(count>=4) count=0;
}
}