[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
#define olsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define solarsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int adcout;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
adcout = ADRES;
return adcout;
}
//#pragma psect code main=0x100
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)
unsigned long int ssvalue, olvalue;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
TRISCbits. TRISA0=1; //solar sense
TRISAbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0;//light off //light off
}
}
void msdelay(unsigned int time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<165;j++)
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
#define olsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define solarsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresh, _adresl;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adresl = _adresl >> 1;
_adresh = ADRESH;
_adresh = _adresh << 7;
_adres = _adresl | _adresh;
return _adres;
}
//#pragma psect code main=0x100
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)
unsigned long int ssvalue, olvalue;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
TRISCbits. TRISA0=1; //solar sense
TRISAbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0;//light off //light off
}
}
void msdelay(unsigned int time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<165;j++)
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
//#define olsense PORTAbits.RA0
#define solarsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define olsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresh, _adresl;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adres = ADRESH; // copy high byte to __adres
_adres = _adres << 8; // shift low byte to 2nd byte
_adresl = _adresl; // copy low byte to _adresl
_adres = _adres | _adresl; // OR _adres with _adresl to get both the bytes into one var.
return _adres;
}
//#pragma psect code main=0x100
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)
unsigned long int ssvalue, olvalue;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
TRISCbits. TRISA0=1; //solar sense
TRISAbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
// ADCS2-ADCS0 = 001
// ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0;//light off //light off
}
}
void msdelay(unsigned int time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<165;j++)
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
//#define olsense PORTAbits.RA0
#define solarsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define olsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresl;
//char c_adres[2];
//unsigned long int i_adres;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adres = ADRESH; // copy high byte to __adres
_adres = _adres << 8; // shift low byte to 2nd byte
_adres = _adres | _adresl; // OR _adres with _adresl to get both the bytes into one var.
return _adres;
}
//#pragma psect code main=0x100
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)
unsigned int time;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
//TRISCbits. TRISA0=1; //solar sense
//TRISAbits. TRISC2=1; //ol sense
TRISAbits. TRISA0=1; //solar sense
TRISCbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
//ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0; //light off
}
}
void msdelay(unsigned int time)
{
unsigned char i,j;
for(i=0;i<time;i++);
for(j=0;j<165;j++);
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
//#define olsense PORTAbits.RA0
#define solarsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define olsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresl;
//char c_adres[2];
//unsigned long int i_adres;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adres = ADRESH; // copy high byte to __adres
_adres = _adres << 8; // shift low byte to 2nd byte
_adres = _adres | _adresl; // OR _adres with _adresl to get both the bytes into one var.
return _adres;
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++);
for(j=0;j<165;j++);
}
//#pragma psect code main=0x100
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)
unsigned int time;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
//TRISCbits. TRISA0=1; //solar sense
//TRISAbits. TRISC2=1; //ol sense
TRISAbits. TRISA0=1; //solar sense
TRISCbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
//ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0; //light off
}
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
//#define olsense PORTAbits.RA0
#define solarsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define olsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresl;
//char c_adres[2];
//unsigned long int i_adres;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adres = ADRESH; // copy high byte to __adres
_adres = _adres << 8; // shift low byte to 2nd byte
_adres = _adres | _adresl; // OR _adres with _adresl to get both the bytes into one var.
return _adres;
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++);
for(j=0;j<165;j++);
}
//#pragma psect code main=0x100
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)
unsigned int time;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
//TRISCbits. TRISA0=1; //solar sense
//TRISAbits. TRISC2=1; //ol sense
TRISAbits. TRISA0=1; //solar sense
TRISCbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
//ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0; //light off
}
}
}
}
[/syntax]
[syntax]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF );
#define load PORTCbits.RC3
//#define olsense PORTAbits.RA0
#define solarsense PORTAbits.RA0
#define spulse PORTAbits.RA5
#define solarled PORTCbits.RC4
#define olsense PORTCbits.RC2
// Prototypes
void msdelay(unsigned int);
// Subroutines
unsigned long int adc(unsigned char source)
{
unsigned long int _adres;
unsigned char _adresl;
//char c_adres[2];
//unsigned long int i_adres;
ADCON0bits.ADON=1;
ADCON0bits.GO=1;
switch(source)
{
case'o':
ADCON0=0x80;
while(ADCON0bits.GO);
break;
case's':
ADCON0=0x98;
while(ADCON0bits.GO);
break;
}
_adresl = ADRESL;
_adres = ADRESH; // copy high byte to __adres
_adres = _adres << 8; // shift low byte to 2nd byte
_adres = _adres | _adresl; // OR _adres with _adresl to get both the bytes into one var.
return _adres;
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++);
for(j=0;j<165;j++);
}
//#pragma psect code main=0x100
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)
unsigned int time;
TRISAbits. TRISA5=0; //spulse
TRISCbits. TRISC4=0; //solarled
TRISCbits. TRISC3=0; //load
//TRISCbits. TRISA0=1; //solar sense
//TRISAbits. TRISC2=1; //ol sense
TRISAbits. TRISA0=1; //solar sense
TRISCbits. TRISC2=1; //ol sense
ANSEL = 0x03;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// 32 * Tosc = 8us
// 8 * Tosc = 2us
// min Tad = 1.6us
//ADCS2-ADCS0 = 001
//ADCON1 = 00010000 or 0x10
ADCON1= 0x10;
while(1)
{
solarled=1; //led ON to show uc working
ssvalue = adc('s');
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
msdelay(5);
if(ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse=1;
}
}
else
spulse=0;
if(ssvalue <= lon_value)
{
msdelay(5);
if(ssvalue <= lon_value)
{
load=1; //light on
}
}
else
load=0; //light off
olvalue = adc('o');
if(olvalue >= olvoltage)
{
msdelay(5);
if(olvalue >= olvoltage)
{
load=0; //light off
}
}
}
}
[/syntax]
[syntax = c]
//Overload, Dusk and Dawn Control
#include<htc.h>
#include<stdlib.h>
#include<stdio.h>
__CONFIG(FOSC_INTRCCLK&PWRTE_ON&BOREN_OFF&WDTE_OFF);
#define solarsense PORTAbits.RC1
#define spulse PORTAbits.RA5
#define olsense PORTCbits.RC2
#define load PORTCbits.RC3
#define solarled PORTCbits.RC4
// Prototypes
void msdelay(unsigned int);
unsigned long int adc(unsigned char source);
// Subroutines
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=0x94;
break;
case 's':
ADCON0=0x98;
break;
}
ADCON0bits.ADON = 1;
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
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
}
void msdelay(unsigned int time)
{
unsigned int i,j;
for(i = 0;i < time;i++);
for(j = 0;j < 165;j++);
}
//#pragma psect code main=0x100
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)
TRISCbits.TRISC1 = 1; //solar sense
TRISAbits.TRISA5 = 0; //spulse
TRISCbits.TRISC2 = 1; //ol sense
TRISCbits.TRISC3 = 0; //load
TRISCbits.TRISC4 = 0; //solarled
ANSEL = 0x41;
// Fosc = 4 Mhz, Tosc = 1/Fosc = 0.25us = 250ns
// Tad = 32 * Tosc = 8us
// Tad = 8 * Tosc = 2us
// min Tad = 1.6us
// ADCS2-ADCS0 = 001
// ADCON1 = 00010000 or 0x10
// ADCON1= 0x10;
ADCON1= 0x20;
solarled = 1; //led ON to show uc working
while(1)
{
ssvalue = adc('s');
if (ssvalue >= ltvalue && ssvalue <= htvalue)
{
spulse = 1;
}
else
spulse=0;
if (ssvalue <= lon_value)
{
load = 1; //light on
}
else
load = 0; //light off
olvalue = adc('o');
if (olvalue >= olvoltage)
{
load = 0; //light off
}
}
}
[/syntax]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?