📄 digitaldcpower.c
字号:
putstring(s1);
putstring("mV ");
lcd_write_string(3,0,s1); // LCD显示
//uart输出ADC1的电压值
uiadc1_value=cal_VD(uitime2_adc1_value_sum); // 输出ADC1的电压值VD1=Vref*uitime2_adc1_value_sum/16/1024
uint_to_ascii(uiadc1_value,s1);
putstring("D1="); // uart输出ADC1
putstring(s1);
putstring("mV ");
lcd_write_string(14,0,s1); // LCD显示
//uart输出ADC2的电压值
uiadc2_value=cal_VD(uitime2_adc2_value_sum); // 输出ADC2的电压值VD2=Vref*uitime2_adc2_value_sum/16/1024
uint_to_ascii(uiadc2_value,s1);
putstring("D2="); // uart输出ADC2
putstring(s1);
putstring("mV ");
lcd_write_string(3,1,s1); // LCD显示
//uart输出ADC3的电压值
uiadc3_value=cal_VD(uitime2_adc3_value_sum); // 输出ADC3的电压值VD3=Vref*uitime2_adc3_value_sum/16/1024
uint_to_ascii(uiadc3_value,s1);
putstring("D3="); // uart输出ADC3
putstring(s1);
putstring("mV ");
lcd_write_string(14,1,s1); // LCD显示
uint_to_ascii(OCR1A,s1); // uart输出TIME1 比较寄存器A 的值
putstring(" 1A="); // uart输出
putstring(s1);
uint_to_ascii(OCR1B,s1); // uart输出TIME1 比较寄存器B 的值
putstring(" 1B="); // uart输出
putstring(s1);
ulong_to_ascii(time2_count/10,s1); // uart输出TIME2秒计数值
putstring(" tn="); // uart输出
putstring(s1);
putchar('s');
putchar_ENTER(); // uart输出回车换行
} // *********ADC显示 end*********
/************** 数控电源相关子程序 *********************/
void DCpower(void) // 数控电源功能模块
{
//3*4键盘扫描
/*扫描1*/
DDRD &=~((1<<PD3)|(1<<PD4)|(1<<PD5)); // SET1、2、3(PD3、4、5)(S12,S11,S10)三键输入
PORTD |= ((1<<PD3)|(1<<PD4)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD2); // 使SET0(PD2)脚输出0,扫描SET1、2、3(PD3、4、5)脚
DDRD |= (1<<PD2);
while((PIND & 0x38) != 0x38)
{
delay_ms(1);
if((PIND & 0x38) == 0x30) // SET1(PD3=0) S12键按下 PWMA电压快速递增
{
if(uiVout_set<2451) // 限定电压不超过25.00V
{
uiVout_set +=50;
OCR1A = PWM_Vout_to_count(uiVout_set); // 电压值转换成PWMA值
}
}
if((PIND & 0x38) == 0x28) //SET2(PD4=0) S11键按下 PWMA电压快速递减
{
if(uiVout_set>49)
{
uiVout_set -=50;
OCR1A = PWM_Vout_to_count(uiVout_set); // 电压值转换成PWMA值
}
}
if((PIND & 0x38) == 0x18) //SET3(PD5=0) S10键按下 ATX电源打开
{
power_ON();
}
delay_ms(1);
DCpower_display();
for(num1=0;num1<30;num1++)
{
if((PIND & 0x38) == 0x38) return;
delay_ms(10);
}
}
/*扫描2*/
DDRD &=~((1<<PD2)|(1<<PD4)|(1<<PD5)); // SET0、2、3(PD2、4、5)(S22,S21,S20)三键输入
PORTD |= ((1<<PD2)|(1<<PD4)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD3); // 使SET1(PD3)脚输出0,扫描SET0、2、3(PD2、4、5)脚
DDRD |= (1<<PD3);
while((PIND & 0x34) != 0x34)
{
delay_ms(1);
if((PIND & 0x34) == 0x30) // SET0(PD2=0) S22键按下 PWMA电压慢速递增
{
if(uiVout_set<2500) // 限定电压不超过25.00V
{
uiVout_set +=1;
OCR1A = PWM_Vout_to_count(uiVout_set); // 电压值转换成PWMA值
}
}
if((PIND & 0x34) == 0x24) //SET2(PD4=0) S21键按下 PWMA电压慢速递减
{
if(uiVout_set>0)
{
uiVout_set -=1;
OCR1A = PWM_Vout_to_count(uiVout_set); // 电压值转换成PWM值
}
}
if((PIND & 0x34) == 0x14) //SET3(PD5=0) S20键按下 ATX电源关闭
{
power_OFF();
}
delay_ms(1);
DCpower_display();
for(num1=0;num1<30;num1++)
{
if((PIND & 0x34) == 0x34) return;
delay_ms(10);
}
}
/*扫描3*/
DDRD &=~((1<<PD2)|(1<<PD3)|(1<<PD5)); // SET0、1、3(PD2、3、5)(S32,S31,S30)三键输入
PORTD |= ((1<<PD2)|(1<<PD3)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD4); // 使SET2(PD4)脚输出0,扫描SET0、1、3(PD2、3、5)脚
DDRD |= (1<<PD4);
while((PIND & 0x2c) != 0x2c)
{
delay_ms(1);
if((PIND & 0x2c) == 0x28) //SET0(PD2=0) S32键按下 PWMB电压快速递增
{
if(uiIout_set<3901) // 限定电流不超过4.000A
{
uiIout_set +=100;
OCR1B = PWM_Iout_to_count(uiIout_set); // 电流值转换成PWMB值
}
}
if((PIND & 0x2c) == 0x24) //SET1(PD3=0) S31键按下 PWMB电压快速递减
{
if(uiIout_set>99)
{
uiIout_set -=100;
OCR1B = PWM_Iout_to_count(uiIout_set); // 电流值转换成PWMB值
}
}
if((PIND & 0x2c) == 0x0c) // SET3(PD5=0) S30键按下 "CANCEL"键 当前功能退出
{
config_temp++; // 改变config_temp值,令config_temp!=config
}
delay_ms(1);
DCpower_display();
for(num1=0;num1<30;num1++)
{
if((PIND & 0x2c) == 0x2c) return;
delay_ms(10);
}
}
/*扫描4*/
DDRD &=~((1<<PD2)|(1<<PD3)|(1<<PD4)); // SET0、1、2(PD2、3、4)(S42,S41,S40)三键输入
PORTD |= ((1<<PD2)|(1<<PD3)|(1<<PD4)); // 置上拉电阻
PORTD &=~(1<<PD5); // 使SET3(PD5)脚输出0,扫描SET0、1、2(PD2、3、4)脚
DDRD |= (1<<PD5);
while((PIND & 0x1c) != 0x1c)
{
delay_ms(1);
if((PIND & 0x1c) == 0x18) // SET0(PD2=0) S42键按下 PWMB电压慢速递增
{
if(uiIout_set<4000) // 限定电流不超过4.000A
{
uiIout_set +=1;
OCR1B = PWM_Iout_to_count(uiIout_set); // 电流值转换成PWMB值
}
}
if((PIND & 0x1c) == 0x14) // SET1(PD3=0) S41键按下 PWMB电压慢速递减
{
if(uiIout_set>0)
{
uiIout_set -=1;
OCR1B = PWM_Iout_to_count(uiIout_set); // 电流值转换成PWMB值
}
}
if((PIND & 0x1c) == 0x0c) // SET2(PD4=0) S40键按下
{
}
delay_ms(1);
DCpower_display();
for(num1=0;num1<30;num1++)
{
if((PIND & 0x1c) == 0x1c) return;
delay_ms(10);
}
}
}
void power_ON(void) // 开关电源打开
{
ATX_CTL_DDR |= (1<<ATX_CTL); //
ATX_CTL_PORT |= (1<<ATX_CTL); // 置1
}
void power_OFF(void) // 开关电源关闭
{
ATX_CTL_DDR |= (1<<ATX_CTL); //
ATX_CTL_PORT &=~ (1<<ATX_CTL); // 置0
}
/************** 数控电源相关子程序 *************** END */
void program_set(void) // 功能模块选择设定
{
//循环3*4键盘扫描
while(1)
{
/*扫描1*/
DDRD &=~((1<<PD3)|(1<<PD4)|(1<<PD5)); // SET1、2、3(PD3、4、5)(S12,S11,S10)三键输入
PORTD |= ((1<<PD3)|(1<<PD4)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD2); // 使SET0(PD2)脚输出0,扫描SET1、2、3(PD3、4、5)脚
DDRD |= (1<<PD2);
while((PIND & 0x38) != 0x38)
{
delay_ms(1);
if((PIND & 0x38) == 0x30) //SET1(PD3=0) S12 "1"键按下 选择数控电源
{
config_temp = 0x10;
}
if((PIND & 0x38) == 0x28) //SET2(PD4=0) S11 "5"键按下
{
}
if((PIND & 0x38) == 0x18) //SET3(PD5=0) S10键按下
{
}
delay_ms(50);
}
/*扫描2*/
DDRD &=~((1<<PD2)|(1<<PD4)|(1<<PD5)); // SET0、2、3(PD2、4、5)(S22,S21,S20)三键输入
PORTD |= ((1<<PD2)|(1<<PD4)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD3); // 使SET1(PD3)脚输出0,扫描SET0、2、3(PD2、4、5)脚
DDRD |= (1<<PD3);
while((PIND & 0x34) != 0x34)
{
delay_ms(1);
if((PIND & 0x34) == 0x30) //SET0(PD2=0) S22键按下
{
}
if((PIND & 0x34) == 0x24) //SET2(PD4=0) S21键按下
{
}
if((PIND & 0x34) == 0x14) //SET3(PD5=0) S20键按下
{
}
delay_ms(50);
}
/*扫描3*/
DDRD &=~((1<<PD2)|(1<<PD3)|(1<<PD5)); // SET0、1、3(PD2、3、5)(S32,S31,S30)三键输入
PORTD |= ((1<<PD2)|(1<<PD3)|(1<<PD5)); // 置上拉电阻
PORTD &=~(1<<PD4); // 使SET2(PD4)脚输出0,扫描SET0、1、3(PD2、3、5)脚
DDRD |= (1<<PD4);
while((PIND & 0x2c) != 0x2c)
{
delay_ms(1);
if((PIND & 0x2c) == 0x28) //SET0(PD2=0) S32键按下
{
}
if((PIND & 0x2c) == 0x24) //SET1(PD3=0) S31键按下
{
}
if((PIND & 0x2c) == 0x0c) // SET3(PD5=0) S30键按下 "CANCEL"键 当前功能退出
{
config_temp = config; // 取消config_temp值,令config_temp=config
return; // 退出功能选择
}
delay_ms(50);
}
/*扫描4*/
DDRD &=~((1<<PD2)|(1<<PD3)|(1<<PD4)); // SET0、1、2(PD2、3、4)(S42,S41,S40)三键输入
PORTD |= ((1<<PD2)|(1<<PD3)|(1<<PD4)); // 置上拉电阻
PORTD &=~(1<<PD5); // 使SET3(PD5)脚输出0,扫描SET0、1、2(PD2、3、4)脚
DDRD |= (1<<PD5);
while((PIND & 0x1c) != 0x1c)
{
delay_ms(1);
if((PIND & 0x1c) == 0x18) //SET0(PD2=0) S42键按下
{
}
if((PIND & 0x1c) == 0x14) //SET1(PD3=0) S41键按下
{
}
if((PIND & 0x1c) == 0x0c) // SET2(PD4=0) S40键按下 "ENTER"键按下 确认功能选择
{
config = config_temp;
return; // 退出功能选择
}
delay_ms(50);
}
switch(config_temp)
{
case 0x10:
{
lcd_write_string(0,0,"PROGRAM SELECT = 0 ");
lcd_write_string(0,1,"DCpower OK?");
break;
}
/*case 0x11:
{
break;
}*/
//可添加其它功能
default:
{
lcd_write_string(0,0,"PROGRAM SELECT = NO ");
lcd_write_string(0,1,"Please Select Other!");
break;
}
}
}
} //program_set(void) end
void program_select(void) // 功能模块选择
{
switch(config)
{
case 0x10 : // 数控电源
{
DCpower();
break;
}
/*case 0x11 : //
{
break;
}*/
//可添加其它功能
default :
{
lcd_write_string(0,0,"NO PROGRAM SELECT ");
lcd_write_string(0,1,"PLEASE SELECT! ");
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -