Intento programar un microcontrolador con Mikro c para encontrar la posición del sol
Puse una función CalculateSunPosition para calcular la posición del sol pero el problema wenn cambio el tiempo en que se soluciona el resultado no sé por qué tal vez el problema en la llamada de la función o la declaración
por favor necesito ayuda este es mi programa
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
double posa;
double posh;
double Deg2Rad = (3.141592653589793/ 90);
double Rad2Deg = (90 / 3.141592653589793);
char value1 [15] ;
char value2 [15] ;
char value3 [15] ;
char value4 [15] ;
double abc;
double CorrectAngle(double angleInRadians)
{
double a;
if (angleInRadians < 0) {
// 2 * Math.PI - (Math.Abs(angleInRadians) % (2 * Math.PI));
a= (2* 3.141592653589793) -( Abs(angleInRadians) - ((2* 3.141592653589793) *((Abs(angleInRadians) / (2* 3.141592653589793)))));
return a;
} else if (angleInRadians > (2 * 3.141592653589793)) {
//angleInRadians % (2 * Math.PI);
a= angleInRadians-((2 * 3.141592653589793)*(angleInRadians/(2 * 3.141592653589793)));
return a;
} else {
a= (angleInRadians);
return a;
}
}
void CalculateSunPosition( int year, int month, int day, int hour, int minute, int second,double latitude, double longitude)
{
//OSCCON= 0X66;
double altitude ;
double aziDenom ;
double azimuth;
double aziNom;
double meanLongitude ;
double meanAnomaly ;
double equationOfCenter ;
double elipticalLongitude ;
double obliquity ;
double rightAscension ;
double declination ;
double hourAngle;
double siderealTimeHours ;
double siderealTimeUT ;
double siderealTime;
double julianDate;
double julianCenturies ;
double result;
double ticks;
// Number of days from J2000.0.
julianDate = 367 * year - (int)((7.0 / 4.0) * (year +(int)((month + 9.0) / 12.0))) + (int)((275.0 * month) / 9.0) + day - 730531.5;
julianCenturies = julianDate / 36525.0;
ticks = (second + (minute * 60) + (hour * 3600)) * 10000000;
result = ticks * 2.7777777777777777E-11;
// julianCenturies = julianDate / 36525.0;
// Sidereal Time
siderealTimeHours = 6.6974 + 2400.0513 * julianCenturies;
siderealTimeUT = siderealTimeHours + (366.2422 / 365.2422) * result;
siderealTime = siderealTimeUT * 15 + longitude;
julianDate =julianDate + (result/ 24.0);
julianCenturies = julianDate / 36525.0;
// Solar Coordinates
meanLongitude = CorrectAngle(Deg2Rad *(280.466 + 36000.77 * julianCenturies));
meanAnomaly = CorrectAngle(Deg2Rad *
(357.529 + 35999.05 * julianCenturies));
equationOfCenter = Deg2Rad * ((1.915 - 0.005 * julianCenturies) *
sin(meanAnomaly) + 0.02 * sin(2 * meanAnomaly));
elipticalLongitude =
CorrectAngle(meanLongitude + equationOfCenter);
obliquity = (23.439 - 0.013 * julianCenturies) * Deg2Rad;
// Right Ascension
rightAscension = atan2(
cos(obliquity) * sin(elipticalLongitude),
cos(elipticalLongitude));
declination = asin( sin(rightAscension) * sin(obliquity));
hourAngle = CorrectAngle(siderealTime * Deg2Rad) - rightAscension;
if (hourAngle > 3.141592653589793) {
hourAngle = hourAngle -( 2 * 3.141592653589793);
}
altitude = asin(sin(latitude * Deg2Rad) *
sin(declination) + cos(latitude * Deg2Rad) *
cos(declination) * cos(hourAngle));
// Nominator and denominator for calculating Azimuth
// angle. Needed to test which quadrant the angle is in.
aziNom = -sin(hourAngle);
aziDenom =
tan(declination) * cos(latitude * Deg2Rad) -
sin(latitude * Deg2Rad) * cos(hourAngle);
azimuth = atan(aziNom / aziDenom);
if (aziDenom < 0) // In 2nd or 3rd quadrant {
azimuth =azimuth + (2 * 3.141592653589793);
}
posa=altitude * Rad2Deg;
posh= azimuth * Rad2Deg;
//julianDate
floattostr(posa,value1);
floattostr(posh,value2);
// Cursor off
Lcd_out(1,1,"alt:");
Lcd_out(1,6,value1);
Lcd_out(2,1,"azim:");
Lcd_out(2,6,value2);
}
void main() {
//OSCCON= 0X66;
I2C1_Init(100000);
Lcd_Init ();
Lcd_Cmd(_LCD_CURSOR_OFF);
CalculateSunPosition (2016,9,3,4,30,50,1222223,322323) ;//time and position
}