vinay bs
Member level 3
- Joined
- May 22, 2012
- Messages
- 65
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,751
View attachment 74691
hi,
i attached simple hardware schematic here, p.f.a
using ldr for input(solar sense) and variable dc for olsense..
using leds to check the output(load,spulse, solarled)
[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 PORTBbits.RB3
#define spulse PORTBbits.RB2
#define solarled PORTBbits.RB6
#define solarsense PORTAbits.RA0
#define olsense PORTAbits.RA1
unsigned long int analogchannel(unsigned int i)
{
unsigned short int hbyte,lbyte,adcout;
ADON = 1;
GODONE = 1;
switch(i)
{
case'0':
ADCON0=0x81;
while(GODONE);
ADON = 0
return ADRES;
break;
case'1':
ADCON0=0x85;
while(GODONE);
ADON = 0
return ADRES;
break;
}
}
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)
TRISBbits. TRISB2=0;//spulse
TRISBbits. TRISB6=0;//solarled
TRISBbits. TRISB3=0;//load
TRISAbits. TRISA1=1;//ol sense
TRISAbits. TRISA0=1;//solar sense
ANSEL = 0x03;
ADCON1=0x00;
while(1)
{
solarled=1;//led ON to show uc working
ssvalue=analogchannel(0);
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=analogchannel(1);
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]
ssvalue=analogchannel('0');
olvalue=analogchannel('1');
[/syntax]
[syntax = c]
ssvalue=analogchannel(0);
olvalue=analogchannel(1);
[/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 PORTBbits.RB3
#define spulse PORTBbits.RB2
#define solarled PORTBbits.RB6
#define solarsense PORTAbits.RA0
#define olsense PORTAbits.RA1
unsigned long int analogchannel(unsigned int i)
{
unsigned short int hbyte,lbyte,adcout;
ADON = 1;
GODONE = 1;
switch(i)
{
case'0':
ADCON0=0x81;
break;
case'1':
ADCON0=0x85;
break;
}
while(GODONE);
ADON = 0
return ADRES;
}
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)
TRISBbits. TRISB2=0;//spulse
TRISBbits. TRISB6=0;//solarled
TRISBbits. TRISB3=0;//load
TRISAbits. TRISA1=1;//ol sense
TRISAbits. TRISA0=1;//solar sense
ANSEL = 0x03;
ADCON1=0x00;
while(1)
{
solarled=1;//led ON to show uc working
ssvalue=analogchannel(0);
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=analogchannel(1);
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]
olvalue=oadc('o');
ssvalue=sadc('s');
unsigned int analogchannel(unsigned int i)
{
unsigned short int hbyte,lbyte,adcout;
switch(i)
{
case'0':
ADCON0=0x41;
ADCON1=0x00;
break;
case'1':
ADCON0=0x49;
ADCON1=0x00;
break;
}
}
[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 PORTBbits.RB3
#define spulse PORTBbits.RB2
#define solarled PORTBbits.RB6
#define solarsense PORTAbits.RA0
#define olsense PORTAbits.RA1
unsigned long int analogchannel(unsigned int i)
{
unsigned short int hbyte,lbyte,adcout;
ADON = 1;
GODONE = 1;
switch(i)
{
case'0':
ADCON0=0x80;
break;
case'1':
ADCON0=0x84;
break;
}
while(GODONE);
ADON = 0
return ADRES;
}
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;
TRISBbits. TRISB2=0;//spulse
TRISBbits. TRISB6=0;//solarled
TRISBbits. TRISB3=0;//load
TRISAbits. TRISA1=1;//ol sense
TRISAbits. TRISA0=1;//solar sense
ANSEL = 0x03;
ADCON1=0x00;
while(1)
{
solarled=1;//led ON to show uc working
ssvalue=analogchannel(0);
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=analogchannel(1);
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]
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?