D/A转换实验报告

2019-04-15 14:11发布

/************************************************** 实验名称:DA实验一 实验目的:利用单片机控制ADC0832芯片输出电流,让发光  二极管D12由灭均匀边到最亮,再由最亮变到熄  灭。在最亮和熄灭的时候用蜂鸣器警报一声。  如此循环。 实验备注: **************************************************/ #include
#define uchar unsigned char #define uint unsigned int
sbit DUAN = P2^6; sbit WEI = P2^7; sbit SPK = P2^3; sbit DACS = P3^2; sbit DAWR = P3^6;
void delay1ms(uchar);
void main() { uchar flag,var; flag = 0; var = 0; DUAN = 0; WEI = 0; DACS = 0; DAWR = 0; while(1) { if(flag == 0) { var = var+5; P0 = var; if(var == 255) { flag = 1; SPK = 0; delay1ms(100); SPK = 1; } delay1ms(50); } else { var = var - 5; P0 = var; if(var == 0) { flag = 0; SPK = 0; delay1ms(100); SPK = 1; } delay1ms(50); } } }
void delay1ms(uchar x) { uchar i, j; for(i = 0;i < x;i++) for(j = 0;j < 110;j++); }