Você está na página 1de 3

/*

Project Name: Unintrupted Power Supply


MicroController:16HV616
Clock Frq: 4 Mhz Internal

*/

#include <16hv616.h>
#DEVICE adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal Clock Enabled
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=4000000) // High speed Osc (> 4mhz)

#define bat_sense PIN_A0 // BATTERY SENSING AS INPUT


#define main_sense PIN_A1 // MAINS SENSING AS INPUT
#define Ovr_crt PIN_A2 // OVER CURRENT SENSING AS INPUT
#define RST_CHG PIN_A3 // RESTART CHRGER SENSING AS OUTPUT
#define Chg_Rly PIN_A4 // BATTERY CHARGER RELAY AS OUTPUT
#define LED PIN_A5 // INVERTER AND BATTERY CHARGING
INDICATION AS OUTPUT

#define op_sense PIN_C0 // OUTPUT SENSING AS INPUT


#define Buzzer PIN_C1 // AS INPUT
#define PWM2 PIN_C2 // AS OUTPUT
#define by_rly PIN_C3 // AS OUTPUT
#define PWM1 PIN_C4 // AS OUTPUT
#define Chcrl PIN_C5 // AS OUTPUT

#define GREEN_led_on output_high(LED);


#define GREEN_led_off output_low(LED);
#define RED_led_on output_LOW(LED);

int bat_voltage,ct_sense,mains;

void InitHW()
{ //INTAULIZE HARDWARE SETTINGS

output_A(0b00000111);//0x07 0x31
output_C(0b00000001);//0x01

}
adc_setup()
{ setup_adc_ports(0x0C); //RA0,RA1,RA2 ADC INPUTS
setup_adc( ADC_CLOCK_INTERNAL );return(0);
}
void buzzer_on()
{ output_high(Buzzer);delay_ms(10);output_low(pin_C1);}

void Init_PWM() //INTAULIZE PWM SETTINGS


{ output_low(PWM1); //output_low(PIN_C4);
output_low(PWM2);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,24,1);//255
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
set_pwm1_duty(50);
}
void main()
{
InitHW();
Init_PWM();
adc_setup();
buzzer_on();
while(1) // continues loop
{
set_adc_channel(1); // read all adc inputs
mains=read_adc();

set_adc_channel(0);
bat_voltage=read_adc();

set_adc_channel(2);
ct_sense=read_adc();

if(main_sense==1) //MAINS OK CONDITION


{
buzzer_on();
output_high(by_rly);
set_adc_channel(0);
bat_voltage=read_adc();
if(bat_voltage>=3 && bat_voltage<=5) //BATTERY
CHARGING
{
output_high(chg_Rly);
buzzer_on();
buzzer_on();
buzzer_on();
GREEN_led_on;// system is in Power Mode
delay_ms(20);
GREEN_led_off;
}
else if(bat_voltage>5) // BATTERY FULL
{
GREEN_led_on;

}
else if(bat_voltage<3) // battery
Low
{
output_low(chg_Rly);
}
}
else if(main_sense==0)
{
if(bat_voltage>3){
output_low(by_rly);
buzzer_on();
buzzer_on();
RED_led_on; // inverter mode Bat is in
Use
set_adc_channel(0); // read bat voltage
bat_voltage=read_adc();
set_adc_channel(2); // read current sense for over load
ct_sense=read_adc();
}
else if(ct_sense==1) // over load
{
output_low(chg_Rly);
}

}
}

Você também pode gostar