unsigned int ADCRead(unsigned char channel)
{
unsigned char l_byte, h_byte;
unsigned int ADR;
ADCON0 = 0x81 | (channel << 3); //Change channel
delay_us(50); //Acquisition Delay
GO_DONE_bit = 1; //Set GO_DONE bit to start conversion
while (GO_DONE_bit == 1); //Wait for bit to be cleared
//If bit is cleared, this means conversion is over
l_byte = ADRESL;
h_byte = ADRESH;
ADR = (h_byte<<8)|l_byte;
ADON_bit =0; //switch off adc
return ADR;
}
// LCD Module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// End LCD module connections
// LCD Pin direction
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
// End of LCD Pin direction
void main(void)
{
unsigned int Ch0, Ch1;
float Form1,Form2;
unsigned short duty1=255;
float tempo=15.6;
char str_temp[60];
CMCON = 7; //Disable ADC
PORTA=0;
TRISA=0xff;
PORTB = 0;
TRISB = 0;
PORTC=0;
TRISC = 0;
PORTD = 0;
TRISD = 0;
PORTE = 0;
TRISE = 0;
ADCON0 = 0x81;
ADCON1 = 0x80;//CCP1CON = 0x3C;
PWM1_Init(25000); // Initialize PWM1 for 25Khz
PWM1_Start(); // start PWM1
PWM1_Set_Duty(duty1); // Set current duty for PWM1
Lcd_Init(); // Initialize LCD
Delay_ms(30);
Lcd_Cmd(_LCD_CLEAR); // Clear DisplayDelay_ms(30);
Lcd_Out(1, 1, "MPPT Controller");
//FloatToStr(tempo, str_temp);
//Lcd_Out(2, 1, str_temp);
}
}