Sie sind auf Seite 1von 1

1. #include <16F883.

h>
2. #device adc=10
3. #use delay(int=4000000)
4. #define LCD_ENABLE_PIN PIN_B2
5. #define LCD_RS_PIN PIN_B0
6. #define LCD_RW_PIN PIN_B1
7. #define LCD_DATA4 PIN_B4
8. #define LCD_DATA5 PIN_B5
9. #define LCD_DATA6 PIN_B6
10. #define LCD_DATA7 PIN_B7
11. #include <LCD.C>
12. #include <math.h>
13. #define CONST_CORRIENTE 5
14. #define CONST_TENSION 310
15. void main(){
16. setup_adc_ports(sAN0|sAN1|VSS_VDD);
17. setup_adc(ADC_CLOCK_DIV_2);
18. int16 i, adcZ=0;
19. float adc1=0, valorMax1=0, adc2=0, valorMax2=0;
20. float tension, corriente, potencia;
21. lcd_init();
22. while(true){
23. do{
24. set_adc_channel(0);
25. adcZ=read_adc()-512;
26. delay_us(20);
27. }while(adcZ<10);
28. for(i=0;i<300;i++){
29. set_adc_channel(0);
30. adc1=(read_adc()*5.0/1023.0)-2.5;
31. delay_us(33);
32. valorMax1=adc1*adc1+valorMax1;
33. set_adc_channel(1);
34. adc2=(read_adc()*5.0/1023.0)-2.5;
35. delay_us(33);
36. valorMax2=adc2*adc2+valorMax2;
37. }
38. tension=sqrt(valorMax1/300)*CONST_TENSION;
39. corriente=sqrt(valorMax2/300)*CONST_CORRIENTE;
40. potencia=tension*corriente;
41. if(tension<50.0||corriente<0.03){
42. lcd_gotoxy(1,1);
43. printf(lcd_putc," W:000.0 ");
44. lcd_gotoxy(1,2);
45. printf(lcd_putc,"V:000.0 A:0.00");
46. }else{
47. lcd_gotoxy(1,1);
48. printf(lcd_putc," W:%3.1f ",potencia);
49. lcd_gotoxy(1,2);
50. printf(lcd_putc,"V:%3.1f A:%1.2f",tension, corriente);
51. }
52. valorMax1=0;
53. valorMax2=0;
54. }
55. }

Das könnte Ihnen auch gefallen