Current Sensor 20A
/*
* Project name:
Current Sensor 20A
* Copyright
(c) Researchdesignlab.com
* Test configuration:
MCU: PIC16F877A
Dev.Board: PIC
Oscillator: 20.0 MHz
Software: mikroC PRO for PIC v 4.6
*/
// Define LCD connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void Display(unsigned int num){
char temp[] = "I = 0.00 Amp";
temp[4] = num/1000 + 48;
temp[6] = (num/100)%10 + 48;
temp[7] = (num/10)%10 + 48;
LCD_Out(2, 3, temp);
}
char message[] = "ACS712-20 ";
unsigned int ADC_Value, Factor;
unsigned long temp;
main(){
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message);
Factor = 488; // To conver Count into current
do{
// Read multiple samples for better accuracy
ADC_Value = ADC_Read(0);
ADC_Value = ADC_Value + ADC_Read(0);
ADC_Value = ADC_Value + ADC_Read(0);
ADC_Value = ADC_Value/3;
temp = (ADC_Value-512)*Factor ;
ADC_Value = temp/10;
Display(ADC_Value);
Delay_ms(1000);
} while(1);
}