📄 main.c
字号:
//******************************************************
//Chinese Academy of Sciences, Institute of Automation
//File Name: main.c
//Description: DAC Test
//Author: JuGuang,Lee
//Date:
//******************************************************
#define DAC (*(volatile unsigned char *)0x03F00070) //DAC
#define LED1 (*(volatile unsigned char*)0x03F00000) //DS4
#define LED2 (*(volatile unsigned char*)0x03F00010) //DS3
#define LED3 (*(volatile unsigned char*)0x03F00020) //DS2
#define LED4 (*(volatile unsigned char*)0x03F00030) //DS1
unsigned char led[11]={0xb7,0x06,0x73,0x57,0xc6,0xd5,0xf5,0x07,0xf7,0xd7,0x0};
void Delay(unsigned int);
void Disp(unsigned char adc);
int C_Entry()
{
unsigned char dac_value;
dac_value=0;
while(1){
DAC=dac_value; // 将数字量送到DAC端口
Disp(dac_value); // 同时在LED上显示当前数字量
Delay(5); // 延时,等待DA转换结束
dac_value=dac_value+1; // 数字量增加
if(dac_value>255) // 如果数字量大于255,重新从0开始
dac_value=0;
}
return 0;
}
void Disp(unsigned char adc)
{
unsigned char temp;
temp=adc;
adc=adc/1000;
LED1=led[adc];
temp=temp-1000*adc;
adc=temp;
adc=adc/100;
LED2=led[adc];
temp=temp-100*adc;
adc=temp;
adc=adc/10;
LED3=led[adc];
temp=temp-10*adc;
LED4=led[temp];
}
void Delay(unsigned int x)
{
unsigned int i,j,k;
for(i=0;i<=x;i++)
for(j=0;j<255;j++)
for(k=0;k<255;k++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -