Monday, 6 February 2017

SOLAR CHARGE CONTROLLER









Study this cod below and redraw or create your own circuit.


 
*********************************
// solar charge controller


#include
#include
#include "lcd.h"
#include "delay.h"
#include "serial.h"

// Prototypes
float ReadAdc(unsigned char channel);
void lcd_intro (void);

void giris_olc(void);

// Useful defines
#define LSB(x) (unsigned char)(*(((unsigned char *)&x)+0))
#define MSB(x) (unsigned char)(*(((unsigned char *)&x)+1))
#define LWORD(x)       (unsigned int)(*(((unsigned int *)&x)+0))
#define HWORD(x)       (unsigned int)(*(((unsigned int *)&x)+1))
#define clrwdt() asm("clrwdt")
#define PORTBIT(adr, bit)      ((unsigned)(&adr)*8+(bit))
#defined DelayUs(x)    { unsigned char _dcnt; _dcnt = x; while(--_dcnt != 0){asm("NOP");asm("NOP");} }
#define DelayMS(x)  { unsigned char _dcnt; _dcnt = x; while(--_dcnt !=0) {DelayUs(250);DelayUs(250);DelayUs(250);DelayUs(250);}}

#define SampNum 40
@ CO-bit static PORTBIT(DOOR, 0);
CI @ static bit PORTBIT(DOOR, 1);

float giris0, Input1, input2, Input3;
float LRV, HVD, RCV, LVD;
unsigned char buff[15];

main (){
// Interrupt settings
GIE = 0;                       // Disable all interrupts

// ADC settings
ADCON1=0b10000010;     // right justified, DOOR for A / D , PORTE digital
;              // Fosc/32, CH0, ADON

// PORT settings
PORTA=255;
PORTB = 0;
PORTC = 0;
PORTD = 0;
GATE = 3;
TRISA=0b11111111;
TRISB = 0b00000000;
TRISC=0b00000000;
Thirty = 0b00000000;;
TRISE = 0b00000000;
LRV = 13;Load Reconnect Voltage(cargo lashing)
HVD = 143/10;High Voltage Disconnect(PV separation)
RCV=135/10;PV Reconnect(Connecting PV)
LVD=115/10;Low Voltage Disconnect(load allocation)
;The above values ​​are based on the battery type setting points deyişen.

lcd_init();
lcd_intro();
lcd_dispmode(4+0+0); // 4:Display on  2:cursor off  1:blink off
DelayUs(220);

while(1)
{
giris0 =(ReadAdc(0)*20/1024);
ftoa(giris0,buff);
lcd_clear();
lcd_goto(0);  //1.line
(4+0+0); // 4:Display  2:cursor  1:blink
lcd_puts("E =");
lcd_goto(0x02);
lcd_puts(buff);
lcd_goto(0x06);
lcd_puts("In");
if (giris0<=RCV) {CO=1;}
if (giris0>HVD =) {CO=0;}
if (giris0<=LVD) {CI=0;}
if (giris0>LRV =) {CI = 1;}

Input1 =(ReadAdc(1)*75/10240);
ftoa(giris1,buff);
lcd_goto(0x08);
lcd_puts("I=");
lcd_goto(0x0A);
lcd_puts(buff);
if (Input1> = 30) {CI = 0;}
lcd_goto(0x0E);
lcd_puts("A");
lcd_goto(0x40);
lcd_puts("P=");
lcd_goto(0x42);
input1 input2 = * giris0;
ftoa(giris2,buff);
lcd_puts(buff);
lcd_goto(0x47);
lcd_puts("The");
lcd_goto(0x49);
lcd_puts("SOC=%");
lcd_goto(0x4E);
Input3 = 100 *(giris0-LVD)/(HVD-LVD);
ftoa(giris3,buff);
lcd_puts(buff);
DelayMs(250);
DelayMs(250);
DelayMs(250);
DelayMs(250);
lcd_clear();
}
}

float ReadAdc(unsigned char channel){
        unsigned int adcvalue;
        ADCON0 = (channel << 3) + 0x81;       // select channel
        DelayUs(20);                                  // wait for acquasition time
        ADGO = 1;
        while(ADGO);                                  // wait for conversion complete
        MSB(adcvalue)=ADRESH;
        LSB(adcvalue)=ADRESL;
        return(adcvalue);
//******************************************
}

void lcd_intro (void)
{
        lcd_clear();
        lcd_goto(0);
        lcd_dispmode(4+0+0); // 4:Display  2:cursor  1:blink
        lcd_putsd("      SOLAR");
        lcd_goto(0x40);
        lcd_putsd(" SARJ REGULATORU");
        DelayMs(250);
        DelayMs(250);
        DelayMs(250);
        DelayMs(250);
        lcd_clear();
}
*********************************

No comments: