Jump to content

  • Log In with Google      Sign In   
  • Create Account

Photo

voltampermetru cu pic 16f876


  • Please log in to reply
453 replies to this topic

#451 ONLINE   dancostea2002

dancostea2002

    Membru

  • Membri
  • PipPip
  • 359 posts
  • Locatie:galati

Posted 04 June 2016 - 07:46 PM

Va multumesc!pacat ca nu este un buton Thanks aici!



Cu_reclama

Cu_reclama
  • Membri

#452 OFFLINE   Liviu M

Liviu M

    -

  • Membri
  • PipPipPipPipPip
  • 3,093 posts
  • Locatie:In sat cu Doru

Posted 04 June 2016 - 08:17 PM

Cu mine vorbesti? Sunt singur aici, nu-i nevoie de plural. :)

Sa-nteleg ca vrei sa folosesti codul din postul anterior? Am sa te rog sa postezi aici daca merge sau nu. Daca nu merge sa postezi si ce anume nu merge.



#453 OFFLINE   Eolos

Eolos

    Nou venit

  • Membri
  • Pip
  • 3 posts

Posted 01 January 2017 - 12:37 PM

Hi there ! The code works fine with pic16f877A..  I created the hex file for pic18f4520 and pic18f4550 but i couldnt get any readings from the Lcd Display.

 

Can u re write it for pic 18f4520 or 50 ?



Cu_reclama

Cu_reclama
  • Membri

#454 OFFLINE   Eolos

Eolos

    Nou venit

  • Membri
  • Pip
  • 3 posts

Posted 01 January 2017 - 02:25 PM

The Code is Belown..

 

I use Port A and E for ADC reading by Opamp..   Port B is for LCD, Port C and D are for output that controls some leds, relays etc..  

Crystal is 4 Mhz.

 

//LCD

sbit LCD_RS at RB7_bit;

sbit LCD_EN at RB6_bit;

sbit LCD_D4 at RB5_bit;

sbit LCD_D5 at RB4_bit;

sbit LCD_D6 at RB3_bit;

sbit LCD_D7 at RB2_bit;

 

sbit LCD_RS_Direction at TRISB7_bit;

sbit LCD_EN_Direction at TRISB6_bit;

sbit LCD_D4_Direction at TRISB5_bit;

sbit LCD_D5_Direction at TRISB4_bit;

sbit LCD_D6_Direction at TRISB3_bit;

sbit LCD_D7_Direction at TRISB2_bit;

 

//Declarare variabile

unsigned char ch, ADCx;

unsigned int Tens, Curent, PVV, P24, P48, OFV, PV, DV, PI, P2, P4, OF, DW;

unsigned long V, I, Pw, Av;

 

char text[10];

 

const char *mesg1="%100";

const char *mesg2="%90";

const char *mesg3="%80";

const char *mesg4="%70";

const char *mesg5="%60";

const char *mesg6="%50";

const char *mesg7="%40";

const char *mesg8="%30";

const char *mesg9="%20";

const char *mesg10="%10";

const char *mesg11="AKU BOS";

 

void strConstCpy(char *dest, const char *source) {

    while(*source)

    *dest++ = *source++ ;

 

    *dest = 0 ;

    }

 

//Functie principala

void main() {

     INTCON = 0;                             // Dezactivare intreruperi

     TRISA = 0xFF;

     TRISE = 0xFF;                           // RA0, RA1 setate ca intrari

     TRISC = 0x00;                    // RC3 si RC4 setati pe iesire

     PORTC = 0;                       // Resetare port c

     TRISD = 0x00;                    // RC3 si RC4 setati pe iesire

     PORTD = 0;

 

     Lcd_Init();                             // Initializare LCD

     Lcd_Cmd(_LCD_CURSOR_OFF);               // Dezactivare cursor

     Lcd_Cmd(_LCD_CLEAR);                    // Stergere Ecran

     Delay_ms(600);                         // Delay 1 secunda

     Lcd_Out(1,5,"HYPERNOVA");          // Mesaj initial 1, prima linie

     Lcd_Out(2,2,"ELECTRIC");                // Mesaj initial 1 linia 2

     Delay_ms(800);

     Lcd_Cmd(_LCD_CLEAR);                    // Stergere ecran

     Lcd_Out(1,4,"ALTERNATIVE");        // Mesaj initial 2, prima linie

     Lcd_Out(2,4,"POWER SYSTEMS");                 // Mesaj initial 2, linia 2

     Delay_ms(1000);

     Lcd_Cmd(_LCD_CLEAR);

 

      while (1) {

            //ADC

            Tens = 0;

            Curent = 0;

PVV = 0;

P24= 0;

P48 = 0;

OFV = 0;

            for (ADCx=0; ADCx<10; ADCx++) {

            Tens += ADC_Read(0);         // Achizitie ADC pentru Tens

            Curent += ADC_Read(1);           // Achizitie ADC pentru curent

            PVV += ADC_Read(7);

            P24 += ADC_Read(2);

            P48 += ADC_Read(5);

           OFV += ADC_Read(6);

            Delay_ms(30);

            }

 

            //Voltage

            Tens = Tens/ADCx;        // Alocare valoare Tens

            V = (long)Tens*1000;         // Converteste rezultat in milivolti

            V = V/1023;                      // 0...1023 => 0...1000mV

            ch = V/1000;                     // Extrage sute 100.00

            Lcd_Chr(1,1,48+ch);              // Afisare rezultat in format ASCII linia 1, coloana 1

            ch = (V/100) % 10;               // Extrage zeci 010.00

            Lcd_Chr_CP(48+ch);               // Afiseaza rezultat in format ASCII

            ch = (V/10) % 10;                // Extrage unitati 001.00

            Lcd_Chr_CP(48+ch);               // Afiseaza rezultat in format ASCII

            Lcd_Chr_CP('.');                 // Afiseaza caracter '.'

            ch = (V/1) % 10;                 // Extrage sutimi  000.10

            Lcd_Chr_CP(48+ch);

            ch = V % 10;                     // Extrage zecimi  000.01

            Lcd_Chr_CP(48+ch);

            LCD_Chr_CP('V');                 // Afiseaza caracter 'V'

            Delay_ms(30);

 

            //Current

            Curent = Curent/ADCx;            // Alocare valoare curent

            I = (long)Curent*5000;            // Convertire rezultat in milivolti

            I = I/1023;                      // 0..1023 => 0-5000mV

            ch = I/1000;                     // Extragere zeci 10.00

            Lcd_Chr(1,9,48+ch);              // Scrie rezultatul in format ASCII linia 1, coloana 9

            ch = (I/100) % 10;               // Extragere unitati 01.00

            Lcd_Chr_CP(48+ch);               // Scrie rezultatul in format ASCII

            Lcd_Chr_CP('.');

            ch = (I/10) %10;                 // Extragere sutimi 00.10

            Lcd_Chr_CP(48+ch);               // Scrie rezultatul in format ASCII

            ch = I % 10;                     // Extragere zecimi 00.01

            Lcd_Chr_CP(48+ch);

            Lcd_Chr_CP('A');                 // Afisare caracter 'A' la final

            Delay_ms(30);

 

            //Power

            Pw = V*I/1000;                   // Seteaza valoare Putere

            ch = Pw/1000;                    // Extrage mii 1000

            Lcd_Chr(2,1,48+ch);              // Scrie rezultatul in format ASCII linia 2, coloana 1

            ch = (Pw/100) % 10;              // Extrage sute 0100

            Lcd_Chr_CP(48+ch);

            ch = (Pw/10) %10;                // Extrage zeci 0010

            Lcd_Chr_CP(48+ch);

            ch = Pw % 10;                    // Extrage unitati 0001

            Lcd_Chr_CP(48+ch);

            Lcd_Chr_CP('W');                 // Afiseaza "W" la sfarsit

            Delay_ms(30);

 

    //Protective Read

        PV = ADC_Read(7);

        DV = ADC_Read(0);

        PI = ADC_Read(1);

        P2 = ADC_Read(2);

        P4 = ADC_Read(5);

        OF = ADC_Read(6);

        DW= DV*PI /100;

 

//Protective 24V

if (P2>= 388 && P4< 388 && PV >=286  || P2>= 388 && P4< 388 && PV <286 && PI >=818 || P2>= 388 && P4< 388 && DW > 234) {

        PORTC.F3 = 1;

        PORTC.F4 = 0;

              }

//Protective 48V

else if (P4>= 388 && P2< 388 && PV >=572  || P4>= 388 && P2< 388 && PV <572 && PI >=818 || P4>= 388 && P2< 388 && DW > 468) {

        PORTC.F0 = 1;

        PORTC.F6 = 0;

              }

//Button Protective - Onn Off

else if (P2>= 388 && P4>= 388 || OF >= 388) {

      PortC.F4 = 0;

      PortC.F6 = 0;

      PortC.F3 = 1;

      }

      else {

      PortC.F4 = 1;

      }

// Aku Seviye 24V Sistem

      if (OF >= 388 && PV > 256 && PV <= 275) {

      strConstCpy(text,mesg1);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 254 && PV <= 256) {

      strConstCpy(text,mesg2);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 252 && PV <= 254) {

      strConstCpy(text,mesg3);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 249 && PV <= 252) {

      strConstCpy(text,mesg4);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 246 && PV <= 249) {

      strConstCpy(text,mesg5);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 243 && PV <= 246) {

      strConstCpy(text,mesg6);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 240 && PV <= 243) {

      strConstCpy(text,mesg7);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 237 && PV <= 240) {

      strConstCpy(text,mesg8);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 231 && PV <= 237) {

      strConstCpy(text,mesg9);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 215 && PV <= 231) {

      strConstCpy(text,mesg10);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV <= 215) {

      strConstCpy(text,mesg11);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

// Aku Seviye 48V Sistem

      else if (OF >= 388 && PV > 511 && PV <= 530) {

      strConstCpy(text,mesg1);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 508 && PV <= 511) {

      strConstCpy(text,mesg2);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 504 && PV <= 508) {

      strConstCpy(text,mesg3);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 499 && PV <= 504) {

      strConstCpy(text,mesg4);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 493 && PV <= 499) {

      strConstCpy(text,mesg5);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 487 && PV <= 493) {

      strConstCpy(text,mesg6);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 480 && PV <= 487) {

      strConstCpy(text,mesg7);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 473 && PV <= 480) {

      strConstCpy(text,mesg8);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 462 && PV <= 473) {

      strConstCpy(text,mesg9);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 429 && PV <= 462) {

      strConstCpy(text,mesg10);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

      }

      else if (OF >= 388 && PV > 401 && PV <= 429) {

      strConstCpy(text,mesg11);

      Lcd_Out(2, 9, text);

      Delay_ms(5000);

      Lcd_Cmd(_LCD_CLEAR);

}

}

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users