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
[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;
msdelay(1);
break;
case 's':
ADCON0=0x98;
msdelay(1);
break;
}
ADCON0bits.ADON = 1;
msdelay(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.
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;
ANSEL = 0x60;
// 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= 0x10;
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]
[syntax = c]
if (ssvalue <= lon_value)
{
load = 1; //light on
}
else
load = 0; //light off
olvalue = adc('o');
if (olvalue >= olvoltage)
{
load = 0; //light off
}
[/syntax]
if (ssvalue <= lon_value)
{
load = 1; //light on
}
else
load = 0; //light off
olvalue = adc('o');
if (olvalue >= olvoltage)
{
load = 0; //light off
}
[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 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;
msdelay(1);
break;
case 's':
ADCON0=0x98;
msdelay(1);
break;
}
ADCON0bits.ADON = 1;
msdelay(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.
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;
ANSEL = 0x60;
// 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= 0x10;
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
//}
if (ssvalue <= lon_value && olvalue < olvoltage)
{
load = 1;
}
else if (olvalue >= olvoltage)
{
load = 0;
}
}
}
[/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?