Design a power measurement and display system for a solar power panel using PIC-
ID: 3783175 • Letter: D
Question
Design a power measurement and display system for a solar power panel using PIC-18. Write a C program to perform the following tasks: To convert analog input voltage (0-5 Volts), AN0, and current(0-10 Amperes), AN1, To calculate power = voltage*current To display power (Watts) on the two segment-displays, which are connected to PORT B and PORT D as shown below. PORT D outputs 7 segments, from Segment a (PD6) to Segment g (PDO). PORT B Bit 1 is connected to the common cathode of the ten's digit, and Bit 0 is connected to the common cathode of one's digit display. To enable a display, output a low to the common cathode of the display, and output highs to the common cathodes of the other displays.Explanation / Answer
#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 8000000
void ADC_Init()
{
ADCON0 = 0x41; //ADC Module Turned ON and Clock is selected
ADCON1 = 0xC0; //All pins as Analog Input
//With reference voltages VDD and VSS
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //If Invalid channel selected
return 0; //Return 0
ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D Conversion
while(GO_nDONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
unsigned int a;
TRISB = 0x00; //PORTB as output
TRISC = 0x00; //PORTC as output
TRISA = 0xFF; //PORTA as input
ADC_Init(); //Initializes ADC Module
do
{
a = ADC_Read(0); //Reading Analog Channel 0
PORTB = a; //Lower 8 bits to PORTB
PORTC = a>>8; //Higher 2 bits to PORTC
__delay_ms(100); //Delay
}while(1); //Infinite Loop
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.