hello
i'm using pic16f877a to mesure ac voltage this is my circuit: but it can read only values between 80v to 240 v..however im doing the same circuit with arduio and it works ! i guess the problem is in adc gonfiguration of pic16f877a, but i can't solve it cauz this pic don't hav ANSEL and ANSELH ..i already try to modifie ADCON1 but no result..please can someone help me! thnx in advance.
cofig I/O pic16f877a:
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0x00;
PORTB = 0x00;
TRISC = 0x80;
PORTC = 0x00;
ADCON1 = 0x80;
// LCD module connections
sbit LCD_RS at RC1_bit;
sbit LCD_EN at RC2_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D3 at RB4_bit;
sbit LCD_D2 at RB5_bit;
sbit LCD_D1 at RB6_bit;
sbit LCD_D0 at RB7_bit;
sbit LCD_RS_Direction at TRISC1_bit;
sbit LCD_EN_Direction at TRISC2_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;
sbit LCD_D3_Direction at TRISB4_bit;
sbit LCD_D2_Direction at TRISB5_bit;
sbit LCD_D1_Direction at TRISB6_bit;
sbit LCD_D0_Direction at TRISB7_bit;// End LCD module connectionschar display[16]="";float U;unsignedint vs;unsignedchar text0[4];char uart_rd;int U0 =0;//Programme principal :
Adc_Init();void main(){
Uart1_Init (9600);{char UART1_Read(U);{
Delay_ms(100);
TRISA =0xFF;
PORTA =0x00;
TRISB =0x00;
PORTB =0x00;
TRISC =0x80;
PORTC =0x00;
ADCON1 =0x80;// Configure all other AN pins as digital I/O // Pins RC7 and RC6 are configured as outputs// PORTB is configured as an output
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_LCD_CURSOR_OFF);}{while(1){
U0 = Adc_Read(0);
vs=U0*0.0048;// Lu canal AN0 et enregistrez la valeur dans la variable temp0
U =vs*80.0519;
ByteToStr(U, text0);
floattostr(U,display);
lcd_out_cp(display);
lcd_chr(1,14,223);//print at pos(row=1,col=13) "°" =223 =0xdf
lcd_out_cp("Volt");
UART1_Write_Text("La tension Mch1 est : ");
UART1_Write_Text(text0);// Envoyé à l'uart
UART1_Write_Text(" Volt");
Uart1_Write('\r');//
delay_ms(500);}}}}