internetuser2k11
Banned
What about batsense, batlow, bathigh, temp sense, templed?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
//Overload, Dusk and Dawn Control
#define solarsense PORTC.RC2
#define spulse PORTA.RA5
#define olsense PORTC.RC3
#define load PORTA.RA2
#define solarled PORTC.RC4
#define charging PORTA.RA1
unsigned long int adc(unsigned char source);
// Subroutine
unsigned long int adc(unsigned char source)
{
unsigned long int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
ADCON0.ADON = 1;
Delay_ms(5);
break;
case 's':
ADCON0=0x98;
ADCON0.ADON = 1;
Delay_ms(5);
break;
}
ADCON0.GO = 1;
while(ADCON0.GO);
ADCON0.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//main
void main(void)
{
unsigned long int ssvalue,olvalue;
unsigned long int lon_value = 409; //(for 2V)
unsigned long int htvalue = 665; //(for 3.25V)
unsigned long int ltvalue = 563; //(for 2.75)
unsigned long int olvoltage = 819; //(for 4V)
TRISC.TRISC2 = 1; //solar sense
TRISA.TRISA5 = 0; //spulse
TRISC.TRISC3 = 1; //ol sense
TRISA.TRISA2 = 0; //load
TRISC.TRISC4 = 0; //solarled
TRISA.TRISA1 = 0; //charging
ANSEL = 0xF0;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1= 0x50;
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
if (ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse = 1;
charging = 1;
}
else
spulse = 0;
Delay_ms(5);
olvalue = adc('o');
if (ssvalue <= lon_value && olvalue < olvoltage)
{
load = 1;
}
else if (ssvalue >= lon_value || olvalue >= olvoltage)
{
load = 0;
}
}
}
//Overload, Dusk and Dawn Control
#define solarsense PORTC.RC2
#define spulse PORTA.RA5
#define olsense PORTC.RC3
#define load PORTA.RA2
#define solarled PORTC.RC4
#define charging PORTA.RA1
unsigned long int adc(unsigned char source);
// Subroutine
unsigned long int adc(unsigned char source)
{
unsigned long int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
ADCON0.ADON = 1;
Delay_ms(5);
break;
case 's':
ADCON0=0x98;
ADCON0.ADON = 1;
Delay_ms(5);
break;
}
ADCON0.GO = 1;
while(ADCON0.GO);
ADCON0.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//main
void main(void)
{
unsigned long int ssvalue,olvalue;
unsigned long int lon_value = 409; //(for 2V)
unsigned long int htvalue = 665; //(for 3.25V)
unsigned long int ltvalue = 563; //(for 2.75)
unsigned long int olvoltage = 819; //(for 4V)
TRISC.TRISC2 = 1; //solar sense
TRISA.TRISA5 = 0; //spulse
TRISC.TRISC3 = 1; //ol sense
TRISA.TRISA2 = 0; //load
TRISC.TRISC4 = 0; //solarled
TRISA.TRISA1 = 0; //charging
ANSEL = 0xF0;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50;
CMCON = 0x07;
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
if (ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse = 1;
charging = 1;
}
else
spulse = 0;
charging = 0;
Delay_ms(5);
olvalue = adc('o');
if (ssvalue <= lon_value && olvalue < olvoltage)
{
load = 1;
}
else if (ssvalue >= lon_value || olvalue >= olvoltage)
{
load = 0;
}
}
}
//Solar Charge Controller
#define batfullled PORTC.RC5
#define batlowled PORTA.RA4
#define solarsense PORTC.RC2
#define spulse PORTA.RA5
#define olsense PORTC.RC3
#define load PORTA.RA2
#define solarled PORTC.RC4
#define charging PORTA.RA1
#define batsense PORTC.RC1
#define tempsense PORTC.RC0
unsigned short int adc(unsigned char source);
// Subroutine
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
ADCON0.ADON = 1;
Delay_ms(5);
break;
case 's':
ADCON0=0x98;
ADCON0.ADON = 1;
Delay_ms(5);
break;
case 'b':
ADCON0=0x94;
ADCON0.ADON = 1;
Delay_ms(5);
break;
case 't':
ADCON0=0xD0;
ADCON0.ADON = 1;
Delay_ms(5);
break;
}
ADCON0.GO = 1;
while(ADCON0.GO);
ADCON0.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//main
void main(void)
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 196; //(for 49 C)
TRISA.TRISA4 = 0; // bat low led
TRISC.TRISC5 = 0; // bat full led
TRISC.TRISC2 = 1; //solar sense
TRISA.TRISA5 = 0; //spulse
TRISC.TRISC3 = 1; //ol sense
TRISA.TRISA2 = 0; //load
TRISC.TRISC4 = 0; //solarled
TRISA.TRISA4 = 0; //charging
TRISC.TRISC0 = 1; //temp sense
TRISC.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
if (ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse = 1;
charging = 1;
}
else
spulse = 0;
charging = 0;
Delay_ms(5);
olvalue = adc('o');
if (ssvalue <= lon_value && olvalue < olvoltage)
{
load = 1;
}
else if (ssvalue >= lon_value || olvalue >= olvoltage)
{
load = 0;
}
Delay_ms(5);
bsvalue = adc('b');
if (bsvalue >= hbat)
{
spulse = 0;
batfullled = 1;
//batlowled = 0;
}
else if(bsvalue <= lbat)
{
load = 0;
batlowled = 1;
//batfullled = 0;
}
else
batfullled = 0;
batlowled = 0;
Delay_ms(5);
tsvalue = adc('t');
if(tsvalue >= htemp)
{
load = 0;
spulse = 0;
}
}
}
[syntax]
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF);
//Solar Charge Controller
#define batfullled PORTCbits.RC5
#define batlowled PORTAbits.RA4
#define solarsense PORTCbits.RC2
#define spulse PORTAbits.RA5
#define olsense PORTCbits.RC3
#define load PORTAbits.RA2
#define solarled PORTCbits.RC4
#define charging PORTAbits.RA1
#define batsense PORTCbits.RC1
#define tempsense PORTCbits.RC0
// Prototypes
void Delay_ms(unsigned int);
unsigned short int adc(unsigned char source);
// Subroutines
void Delay_ms(unsigned int time)
{
unsigned int i,j;
for(i = 0;i < time;i++);
for(j = 0;j < 165;j++);
}
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
break;
case 's':
ADCON0=0x98;
break;
case 'b':
ADCON0=0x94;
break;
case 't':
ADCON0=0xD0;
break;
}
ADCON0bits.ADON = 1;
Delay_ms(5);
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
ADCON0bits.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//#pragma psect code main=0x100
void main(void)
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 196; //(for 49 C)
TRISAbits.TRISA4 = 0; // bat low led
TRISCbits.TRISC5 = 0; // bat full led
TRISCbits.TRISC2 = 1; //solar sense
TRISAbits.TRISA5 = 0; //spulse
TRISCbits.TRISC3 = 1; //ol sense
TRISAbits.TRISA2 = 0; //load
TRISCbits.TRISC4 = 0; //solarled
TRISAbits.TRISA4 = 0; //charging
TRISCbits.TRISC0 = 1; //temp sense
TRISCbits.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
if (ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse = 1;
charging = 1;
}
else
spulse = 0;
charging = 0;
Delay_ms(5);
olvalue = adc('o');
if (ssvalue <= lon_value && olvalue < olvoltage)
{
load = 1;
}
else if (ssvalue >= lon_value || olvalue >= olvoltage)
{
load = 0;
}
Delay_ms(5);
bsvalue = adc('b');
if (bsvalue >= hbat)
{
spulse = 0;
batfullled = 1;
//batlowled = 0;
}
else if(bsvalue <= lbat)
{
load = 0;
batlowled = 1;
//batfullled = 0;
}
else
batfullled = 0;
batlowled = 0;
Delay_ms(5);
tsvalue = adc('t');
if(tsvalue >= htemp)
{
load = 0;
spulse = 0;
}
}
}
[/syntax]
[syntax = mikroC]
//Solar Charge Controller
#define batfullled PORTC.RC5
#define batlowled PORTA.RA4
#define solarsense PORTC.RC2
#define spulse PORTA.RA5
#define olsense PORTC.RC3
#define load PORTA.RA2
#define solarled PORTC.RC4
#define charging PORTA.RA1
#define batsense PORTC.RC1
#define tempsense PORTC.RC0
// Prototype
unsigned short int adc(unsigned char source);
// Subroutine
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
break;
case 'b':
ADCON0=0x98;
break;
case 's':
ADCON0=0x94;
break;
case 't':
ADCON0=0xD0;
break;
}
ADCON0.ADON = 1;
Delay_ms(2);
ADCON0.GO = 1;
while(ADCON0.GO);
ADCON0.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
return result; // return the value in result
}
//main
void main()
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 196; //(for 49 C)
TRISA.TRISA4 = 0; // bat low led
TRISC.TRISC5 = 0; // bat full led
TRISC.TRISC2 = 1; //solar sense
TRISA.TRISA5 = 0; //spulse
TRISC.TRISC3 = 1; //ol sense
TRISA.TRISA2 = 0; //load
TRISC.TRISC4 = 0; //solarled
TRISA.TRISA4 = 0; //charging
TRISC.TRISC0 = 1; //temp sense
TRISC.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x10; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
Delay_ms(2);
olvalue = adc('o');
Delay_ms(2);
bsvalue = adc('b');
Delay_ms(2);
tsvalue = adc('t');
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat))
{
spulse = 1;
charging = 1;
}
else if (tsvalue >= htemp)
{ spulse = 0;
}
else
{ spulse = 0;
charging = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
//spulse = 0;
batfullled = 1;
//batlowled = 0;
}
else if(bsvalue <= lbat)
{
//load = 0;
batlowled = 1;
//batfullled = 0;
}
else
batfullled = 0;
batlowled = 0;
if(tsvalue >= htemp)
{
//load = 0;
//spulse = 0;
}
}
}
[/syntax]
[syntax = Hi Tech C]
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF);
//Solar Charge Controller
#define batfullled PORTCbits.RC5
#define batlowled PORTAbits.RA4
#define solarsense PORTCbits.RC2
#define spulse PORTAbits.RA5
#define olsense PORTCbits.RC3
#define load PORTAbits.RA2
#define solarled PORTCbits.RC4
#define charging PORTAbits.RA1
#define batsense PORTCbits.RC1
#define tempsense PORTCbits.RC0
// Prototypes
void Delay_ms(unsigned int);
unsigned short int adc(unsigned char source);
// Subroutines
void Delay_ms(unsigned int time)
{
unsigned int i,j;
for(i = 0;i < time;i++);
for(j = 0;j < 165;j++);
}
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
break;
case 's':
ADCON0=0x98;
break;
case 'b':
ADCON0=0x94;
break;
case 't':
ADCON0=0xD0;
break;
}
Delay_ms(5);
ADCON0bits.ADON = 1;
Delay_ms(5);
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
ADCON0bits.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//#pragma psect code main=0x100
void main(void)
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 200; //196; //(for 49 C)
TRISAbits.TRISA1 = 1; // Vref 2.5V
TRISAbits.TRISA4 = 0; // bat low led
TRISCbits.TRISC5 = 0; // bat full led
TRISCbits.TRISC2 = 1; //solar sense
TRISAbits.TRISA5 = 0; //spulse
TRISCbits.TRISC3 = 1; //ol sense
TRISAbits.TRISA2 = 0; //load
TRISCbits.TRISC4 = 0; //solarled
TRISAbits.TRISA4 = 0; //charging
TRISCbits.TRISC0 = 1; //temp sense
TRISCbits.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
Delay_ms(5);
olvalue = adc('o');
Delay_ms(5);
bsvalue = adc('b');
Delay_ms(5);
tsvalue = adc('t');
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat) && (tsvalue < htemp))
{
spulse = 1;
charging = 1;
}
else if (tsvalue >= htemp || bsvalue >= hbat)
{
spulse = 0;
}
else
{ spulse = 0;
charging = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
batfullled = 1;
}
else if(bsvalue <= lbat)
{
batlowled = 1;
}
else
batfullled = 0;
batlowled = 0;
}
}
[/syntax]
#define batlowled PORTAbits.RA4
#define charging PORTAbits.RA1
charging = 1;
charging = 0;
batlowled = 1;
batlowled = 0;
[syntax = Hi Tech C]
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF);
//Solar Charge Controller
#define batfullled PORTCbits.RC5
//#define batlowled PORTAbits.RA4
#define batlowled PORTAbits.RA4
#define solarsense PORTCbits.RC2
#define spulse PORTAbits.RA5
#define olsense PORTCbits.RC3
#define load PORTAbits.RA2
#define solarled PORTCbits.RC4
//#define charging PORTAbits.RA1
#define charging PORTAbits.RA1
#define batsense PORTCbits.RC1
#define tempsense PORTCbits.RC0
// Prototypes
void Delay_ms(unsigned int);
unsigned short int adc(unsigned char source);
// Subroutines
void Delay_ms(unsigned int time)
{
unsigned int i,j;
for(i = 0;i < time;i++);
for(j = 0;j < 165;j++);
}
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
break;
case 's':
ADCON0=0x98;
break;
case 'b':
ADCON0=0x94;
break;
case 't':
ADCON0=0xD0;
break;
}
Delay_ms(5);
ADCON0bits.ADON = 1;
Delay_ms(5);
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
ADCON0bits.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(5);
return result; // return the value in result
}
//#pragma psect code main=0x100
void main(void)
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 200; //196; //(for 49 C)
TRISAbits.TRISA1 = 1;
TRISAbits.TRISA4 = 0; // bat low led
TRISCbits.TRISC5 = 0; // bat full led
TRISCbits.TRISC2 = 1; //solar sense
TRISAbits.TRISA5 = 0; //spulse
TRISCbits.TRISC3 = 1; //ol sense
TRISAbits.TRISA2 = 0; //load
TRISCbits.TRISC4 = 0; //solarled
//TRISAbits.TRISA4 = 0; //charging
TRISCbits.TRISC0 = 1; //temp sense
TRISCbits.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
Delay_ms(5);
olvalue = adc('o');
Delay_ms(5);
bsvalue = adc('b');
Delay_ms(5);
tsvalue = adc('t');
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat) && (tsvalue < htemp))
{
spulse = 1;
//charging = 1;
//batlowled = 1;
}
else if (tsvalue >= htemp || bsvalue >= hbat)
{
spulse = 0;
}
else
{ spulse = 0;
//charging = 0;
//batlowled = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
batfullled = 1;
}
else if (bsvalue <= lbat)
{
batlowled = 1;
}
else
batfullled = 0;
batlowled = 0;
}
}
[/syntax]
[syntax = mikroC]
//Solar Charge Controller
#define batfullled PORTC.F5
#define batlowled PORTA.F4
#define solarsense PORTC.F2
#define spulse PORTA.F5
#define olsense PORTC.F3
#define load PORTA.F2
#define solarled PORTC.F4
#define charging PORTA.F1
#define batsense PORTC.F1
#define tempsense PORTC.F0
//main
void main()
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 200; //(for 49 C)
TRISA = 0b001011;
TRISC = 0b001111;
ANSEL = 0xF0; // analog channel i/p o/p config
ADCON1 = 0x20; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = ADC_Read(6);
Delay_ms(2);
olvalue = ADC_Read(7);
Delay_ms(2);
bsvalue = ADC_Read(5);
Delay_ms(2);
tsvalue = ADC_Read(4);
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat) && (tsvalue < htemp))
{
spulse = 1;
}
else if (tsvalue >= htemp || bsvalue >= hbat)
{
spulse = 0;
}
else
{ spulse = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
batfullled = 1;
}
else if(bsvalue <= lbat)
{
batlowled = 1;
}
else
batfullled = 0;
batlowled = 0;
}
}
[/syntax]
[syntax = mikroC]
//Solar Charge Controller
#define batfullled PORTC.F5
#define batlowled PORTA.F4
#define solarsense PORTC.F2
#define spulse PORTA.F5
#define olsense PORTC.F3
#define load PORTA.F2
#define solarled PORTC.F4
#define charging PORTA.F1
#define batsense PORTC.F1
#define tempsense PORTC.F0
//main
void main()
{
unsigned long int ssvalue,olvalue;
unsigned long int bsvalue,tsvalue;
unsigned long int lon_value = 409; //(for 2V)
unsigned long int htvalue = 665; //(for 3.25V)
unsigned long int ltvalue = 563; //(for 2.75)
unsigned long int olvoltage = 819; //(for 4V)
unsigned long int hbat = 778; //(for 3.8V)
unsigned long int lbat = 594; //(for 2.9V)
unsigned long int htemp = 196; //(for 49 C)
TRISA = 0b001011; // 0x0B;
TRISC = 0b001111; // 0x0F;
ANSEL = 0xF0; // analog channel i/p o/p config
ADCON1 = 0x20; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = ADC_Read(6);
olvalue = ADC_Read(7);
bsvalue = ADC_Read(5);
ADCON0.VCFG = 1;
tsvalue = ADC_Read(4);
ADCON0.VCFG = 0;
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat) && (tsvalue < htemp))
{
spulse = 1;
}
else if (tsvalue >= htemp || bsvalue >= hbat)
{
spulse = 0;
}
else
{ spulse = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
batfullled = 1;
}
else if(bsvalue <= lbat)
{
batlowled = 1;
}
else
{
batfullled = 0;
batlowled = 0;
}
}
}
[/syntax]
[syntax = hi tech c]
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF);
//Solar Charge Controller
#define batfullled PORTCbits.RC5
#define batlowled PORTAbits.RA4
#define solarsense PORTCbits.RC2
#define spulse PORTAbits.RA5
#define olsense PORTCbits.RC3
#define load PORTAbits.RA2
#define solarled PORTCbits.RC4
//#define charging PORTAbits.RA1
//#define charging PORTAbits.RA1
#define batsense PORTCbits.RC1
#define tempsense PORTCbits.RC0
// Prototypes
void Delay_ms(unsigned int);
unsigned short int adc(unsigned char source);
// Subroutines
void Delay_ms(unsigned int time)
{
unsigned int i,j;
for(i = 0;i < time;i++);
for(j = 0;j < 165;j++);
}
unsigned short int adc(unsigned char source)
{
unsigned short int result = 0;// 16/32 bit variable to hold the 10 bit A/D result
ADRESL = 0x00;
ADRESH = 0x00;
switch(source)
{
case 'o':
ADCON0=0x9C;
break;
case 's':
ADCON0=0x98;
break;
case 'b':
ADCON0=0x94;
break;
case 't':
ADCON0=0xD0;
break;
}
Delay_ms(5);
ADCON0bits.ADON = 1;
Delay_ms(5);
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
ADCON0bits.ADON = 0;
result = ADRESH; // copy high byte to result
result <<= 8; // shift low byte to 2nd byte
result |= ADRESL; // OR result with ADRESL to get both the bytes into one var.
Delay_ms(1);
return result; // return the value in result
}
//#pragma psect code main=0x100
void main(void)
{
unsigned short int ssvalue,olvalue;
unsigned short int bsvalue,tsvalue;
unsigned short int lon_value = 409; //(for 2V)
unsigned short int htvalue = 665; //(for 3.25V)
unsigned short int ltvalue = 563; //(for 2.75)
unsigned short int olvoltage = 819; //(for 4V)
unsigned short int hbat = 778; //(for 3.8V)
unsigned short int lbat = 594; //(for 2.9V)
unsigned short int htemp = 200; //196; //(for 49 C)
//TRISAbits.TRISA0 = 0;
TRISAbits.TRISA1 = 1;
TRISAbits.TRISA4 = 0; // bat low led
TRISCbits.TRISC5 = 0; // bat full led
TRISCbits.TRISC2 = 1; //solar sense
TRISAbits.TRISA5 = 0; //spulse
TRISCbits.TRISC3 = 1; //ol sense
TRISAbits.TRISA2 = 0; //load
TRISCbits.TRISC4 = 0; //solarled
//TRISAbits.TRISA4 = 0; //charging
TRISCbits.TRISC0 = 1; //temp sense
TRISCbits.TRISC1 = 1; //bat sense
ANSEL = 0xF0; // analog channel i/p o/p config
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 16 * Tosc = 4us
// min Tad = 1.6us
// ADCS2-ADCS0 = 101
// ADCON1 = 01010000 or 0x50
ADCON1 = 0x50; // select conversion clock
CMCON = 0x07; //comparator off
solarled = 1; //led ON to show uc working
while(1)
{
Delay_ms(1);
ssvalue = adc('s');
Delay_ms(1);
olvalue = adc('o');
Delay_ms(1);
bsvalue = adc('b');
Delay_ms(1);
tsvalue = adc('t');
ADCON0bits.VCFG = 0;
if ((ssvalue >= ltvalue) && (ssvalue <= htvalue) && (bsvalue < hbat) && (tsvalue < htemp))
{
spulse = 1;
//charging = 1;
//batlowled = 1;
}
else if ((bsvalue >= hbat) || (tsvalue >= htemp))
{
spulse = 0;
}
else
{ spulse = 0;
//charging = 0;
//batlowled = 0;
}
if ((ssvalue <= lon_value) && (olvalue < olvoltage) && (bsvalue > lbat) && (tsvalue < htemp))
{
load = 1;
}
else if ((ssvalue >= lon_value) || (olvalue >= olvoltage) || (bsvalue <= lbat) || (tsvalue >= htemp))
{
load = 0;
}
if (bsvalue >= hbat)
{
batfullled = 1;
}
else if (bsvalue <= lbat)
{
batlowled = 1;
}
else
{
batfullled = 0;
batlowled = 0;
}
}
}
[/syntax]