钻石会员
主题
帖子
积分14868
阅读权限50
注册时间2010-10-1
最后登录1970-1-1
在线时间 小时
|
///////////////////////////////////////////////////////////
//// CVCC Control Program
//// Constant Current Constant Voltage Controller
//// Analog Input Data
//// CH0 : 晧壸揹棳(Curr_Now)
//// CH1 : 嵟戝晧壸揹棳愝掕抣(Curr_Set)
//// CH2 : 揹棳惂屼揹埑抣(Volt_Cont)
//// CH3 : 弌椡揹埑抣(Volt_Now)
///////////////////////////////////////////////////////////
#include <16f876.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#device ADC=10 //A/D曄姺侾侽價僢僩儌乕僪
#use delay(CLOCK = 20000000) //僋儘僢僋20MHz
#use fast_io(B) //擖弌椡儌乕僪屌掕
#use fast_io(C)
////// 塼徎昞帵婍儔僀僽儔儕梡愝掕
#define mode 0 //嬻偒僺儞偺擖弌椡儌乕僪
#define input_x input_B //愙懕億乕僩巜掕
#define output_x output_B
#define set_tris_x set_tris_B
#define stb PIN_B3 //惂屼怣崋愝掕
#define rs PIN_B2
#include <lcd_lib.c> //儔僀僽儔儕僀儞僋儖乕僪
///// 儊僀儞娭悢
void main()
{
float Curr_Now, Curr_Set; //寁應僨乕僞丂float巜掕
float Volt_Cont, Volt_Now;
float Max_Pwr, Temp; //嵟戝揹椡愝掕抣
int Set_Pwr, flag;
setup_adc_ports(A_ANALOG); //RA0-RA5僺儞偑傾僫儘僌擖椡
setup_adc(ADC_CLOCK_DIV_32); //Fosc/32 嵟崅懍搙
set_tris_b(0); //慡僺儞弌椡儌乕僪
output_B(0); //0僋儕傾
set_tris_c(0);
output_C(0);
//// 塼徎昞帵弶婜昞帵
lcd_init(); //塼徎昞帵婍弶婜壔
lcd_clear(); //慡徚嫀
printf(lcd_data,"Start!!"); //僗僞乕僩儊僢僙乕僕弌椡
delay_ms(1000); //侾昩懸偪
lcd_clear();
//丂寁應昞帵孞傝曉偟儖乕僾
while(1)
{
/// 弌椡揹埑寁應
set_adc_channel(3); //僠儍僱儖3慖戰
delay_us(50); //傾僋僀僕僔儑儞懸偪
Volt_Now = read_adc(); //A/D曄姺僨乕僞侾侽價僢僩撉傒崬傒
Volt_Now = (Volt_Now * 15.0) / 1024; //揹埑15VMax傊僗働乕儖曄姺
/// 晧壸揹棳抣
set_adc_channel(1); //僠儍僱儖1慖戰
delay_us(50); //傾僋僀僕僔儑儞僞僀儉懸偪
Curr_Now = read_adc(); //10價僢僩偱撉傒崬傒
Curr_Now = (5.3 * Curr_Now)/1024 - 0.12; //5.0A僼儖僗働乕儖偱曄姺
/// 嵟戝揹棳抣
set_adc_channel(2); //僠儍僱儖2慖戰
delay_us(50); //傾僋僀僕僔儑儞僞僀儉懸偪
Curr_Set = read_adc(); //10價僢僩偱撉傒崬傒
Curr_Set = (4.6 * Curr_Set)/1024 - 1.26; //僼儖僗働乕儖曄姺
/// 揹棳惂屼揹埑抣
set_adc_channel(0); //僠儍僱儖0慖戰
delay_us(50); //傾僋僀僕僔儑儞懸偪
Volt_Cont = read_adc(); //A/D曄姺僨乕僞侾侽價僢僩撉傒崬傒
Volt_Cont = (Volt_Cont * 5.0) / 1024; //揹埑乮13VMax)傊僗働乕儖曄姺
/// 壏搙寁應
set_adc_channel(4); //僠儍僱儖係慖戰
delay_us(50);
Temp = read_adc();
Temp = Temp * 100;
//// 奺抣昞帵
lcd_clear(); //1峴栚偺愭摢傊堏摦
printf(lcd_data, "V=%2.2f LMT%1.2f", Volt_Now, Volt_Cont);
lcd_cmd(0xC0); //2峴栚偺摢偵堏摦
printf(lcd_data, "A=%1.2f Max%1.2f", Curr_Now, Curr_Set);
/////丂嵟戝晧壸揹棳惂尷愝掕弌椡
///// 嵟戝侾侽倂傑偱偲偡傞
Max_Pwr = 10.0/(15.0 - Volt_Now); //擖椡侾俆倁
if (Max_Pwr > 2.0) //嵟戝俀俙
Set_Pwr = 0x0F;
else
Set_Pwr = (Max_Pwr * 0x0F) / 2;
//// 俢乛俙弌椡
output_c(Set_Pwr); //壓埵係價僢僩弌椡
//// LED Controle
if (flag)
{
output_bit(PIN_C7, 1); //俴俤俢徚摂
flag = 0;
}
else
{
output_bit(PIN_C7, 0); //俴俤俢揰摂
flag = 1;
}
delay_ms(500); //0.5昩懸偪
}
} |
|