pass pic basic pro pic from pic 16f877a to pic 16f887


Closed Thread
Results 1 to 9 of 9
  1. #1

    Default pass pic basic pro pic from pic 16f877a to pic 16f887

    amigos del foro, saludos cordiales


    He diseñado el siguiente código con el pic basic pro usando el pic 16f877a, el código es para una fuente simétrica, quiero que este mismo código funcione con el pic 16f887.

    '* Nombre: FUENTE SIMETRICA.BAS *
    '* Autor: [JOSE LUIS COMAS LLINAS] *
    '* *
    '* Aviso: Copyright (c) 2020 [seleccione VER ... OPCIONES DEL EDITOR] *
    '* : Todos los derechos reservados *
    '* Fecha: 10/02/2020 *
    '* Versión: 1.0 *
    '* Notas: *
    '*: *
    '************************************************* ***************
    include "fp2032.bas" ' Include file for 14-bit core with RAM at $20 (32-bit)


    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2


    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_ SAMPLEUS 50


    '************************************************* *******************
    ' Definición de puertos y variables
    '************************************************* *******************
    LED VAR PORTB.6 'Define el led en el pin 6 del puerto B
    TXD VAR PORTC.6 'Define el pin de transmision serial en el pin 6 del puerto C
    B1 VAR WORD
    B2 VAR WORD
    VALOR1 VAR BYTE
    VALOR2 VAR BYTE
    fpplaces var byte ' Used to define number of decimal places in fpdisplay,fpdisplayr
    ahold var word ' Required by fpdisplay
    bhold var word ' Required by fpdisplay


    '************************************************* *******************
    ' Inicio del programa principal
    '************************************************* *******************
    INICIO:
    TRISC.6 = 0 'Configura puerto RC6 como salida
    TRISC.7 = 1 'Configura puerto RC7 como entrada
    TRISA = 255 'Configura puerto A como entrada
    ADCON1 = %11000010 'Justifica el resultado hacia la izquierda
    TRISB.6 = 0 'Configura puerto RB6 como salida


    LCDOUT $FE,2," FUENTE SIMETRICA "
    LCDOUT $FE,$C0,"JOSELUISCOMASLLINAS "
    LCDOUT $FE,$94,"VOLT.NEGATIVO:-"
    LCDOUT $FE,$D4,"VOLT.POSITIVO:+"
    COMENZAR:
    ADCIN 1, B1 'Lee el voltaje negativo en el canal 1 del ADC
    ADCIN 2, B2 'Lee el voltaje positivo en el canal 2 del ADC

    'Envia los valores del ADC a la terminal
    SEROUT2 TXD,188,["$", "$", DEC4 B1,"$", "$",DEC4 B2,10,13]

    aint = B1 'Transfiere el valor del ADC del voltaje negativo
    gosub itofa 'Conviertelo a punto flotante
    bint = 2000 'Carga el valor 2000 (5*400)
    gosub itofb 'Conviertelo en punto flotante
    gosub fpmul 'ADCres * 2000
    bint = 52224 'Carga el valor de la cuenta maxima del ADC * 51
    gosub itofb 'Conviertelo en punto flotante
    GOSUB fpdiv '(ADCres * 2000)/52224
    LCDOUT $FE,$A3," " 'Limpia el espacio donde se coloca el voltaje negativo
    LCDOUT $FE,$A3
    fpplaces = 2 : Gosub fpdisplayr ' Call display routine

    aint = B2 'Transfiere el valor del ADC del voltaje positivo
    gosub itofa 'Conviertelo a punto flotante
    bint = 35 'Carga el valor 35 (5*7)
    gosub itofb 'Conviertelo en punto flotante
    gosub fpmul 'ADCres * 35
    bint = 1024 'Carga el valor de la cuenta maxima del ADC
    gosub itofb 'Conviertelo en punto flotante
    GOSUB fpdiv '(ADCres * 35)/1024
    LCDOUT $FE,$E3," " 'Limpia el espacio donde se coloca el voltaje positivo
    LCDOUT $FE,$E3
    fpplaces = 2 : Gosub fpdisplayr ' Call display routine
    HIGH LED
    GOTO COMENZAR

    ' The fpdisplayr routine checks for number of places, then adds the appropriate
    ' value to achieve rounding. To save RAM space, the values are hard coded
    ' in floating point format.


    fpdisplayr: If fpplaces=0 Then ' Set floating point barg to 0.5
    bexp = $7E
    bargb0 = $00
    bargb1 = $00
    bargb2 = $01
    Endif
    If fpplaces=1 Then ' Set floating point barg to 0.05
    bexp = $7A
    bargb0 = $4C
    bargb1 = $CC
    bargb2 = $CD
    Endif
    If fpplaces=2 Then ' Set floating point barg to 0.005
    bexp = $77
    bargb0 = $23
    bargb1 = $D7
    bargb2 = $0B
    Endif
    If fpplaces=3 Then ' Set floating point barg to 0.0005
    bexp = $74
    bargb0 = $03
    bargb1 = $12
    bargb2 = $6F
    Endif
    If fpplaces=4 Then ' Set floating point barg to 0.00005
    bexp = $70
    bargb0 = $51
    bargb1 = $B7
    bargb2 = $17
    Endif


    Gosub fpadd ' add barg to aarg






    ' The fpdisplay routine outputs the signed value of aarg in decimal floating point format. It
    ' can display a positive value of 65535, and decimals to 4 places. The number of decimal
    ' places should be stored in fpplaces before calling the routine. The routine reads the
    ' floating point value of aarg. This value should NOT be converted to an integer before
    ' calling fpdisplay. The integer conversion will be perfomed as part of this routine, and
    ' aint will be returned to the calling program just as from the itofa routine.


    fpdisplay: bexp = aexp ' Store the FP value of aarg to the barg variables
    bargb0 = aargb0
    bargb1 = aargb1
    bargb2 = aargb2


    Gosub ftoia ' Convert aarg to integer
    ahold = aint ' Save this value for the final display

    Gosub itofa ' Convert integer back to float


    Swap aexp,bexp ' Swap the FP values of aarg and barg before subtraction
    Swap aargb0,bargb0
    Swap aargb1,bargb1
    Swap aargb2,bargb2


    Gosub fpsub ' Subtract the integer portion from the full number




    bint = 10 ' Make bint = 10 E fpplaces
    If fpplaces=2 Then
    bint = 100
    Endif
    If fpplaces=3 Then
    bint = 1000
    Endif
    If fpplaces=4 Then
    bint = 10000
    Endif


    bhold = bint ' Save the integer value of bint for zeros loop


    Gosub itofb ' Convert bint to integer prior to FP multiply
    Gosub fpmul ' Multiply the decimal portion x 10 E fpplaces


    Gosub ftoia ' Convert result to aint integer




    Lcdout dec ahold ' Display integer portion


    If fpplaces > 0 Then
    Lcdout "." 'Mostrar punto decimal


    ceros: bhold = bhold / 10 'Establecer bhold para que sea el próximo lugar a la derecha
    If (aint <bhold) AND (bhold> 1) Entonces 'Verifique el cero inicial en decimal
    Lcdout "0" 'Pantalla cero inicial
    Vaya a bucle de ceros para buscar otro cero
    Terminara si

    LCDOUT diciembre aint 'mostrar el resto de la parte decimal


    Terminara si


    aint = ahold 'Restaura el valor original de aint


    Regreso





    amigos espero y me puedan ayudar gracias

    jose

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    an adc result is only accurate to 2 places anyway so why not just use

    B1**25097


    result is (b1 *2000/52224 )*100

    eg
    b1 = 1023
    B1**25097=391

    b1 = 255
    B1**25097=97
    Last edited by richard; - 11th February 2020 at 08:04.
    Warning I'm not a teacher

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    hello thanks for answering, the code that I have done works perfectly with pic 16f877a, but what I want is for this same code to work with pic 16f887, in the simulation in proteus on the 20x4 display in the positive and negative voltage blink a lot and they are not fixed, and I have not been able to correct this fault, I hope you can help me thanks

    José

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    you have been asking this question since 2018.
    what have you tried ?
    what are you measuring ?
    where is your schematic ?
    your code is incomplete what is in your config section ?
    why do think fp math is necessary to get the display you want?
    Warning I'm not a teacher

  5. #5


    Did you find this post helpful? Yes | No

    Thumbs up Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    hello I sent you the following link of the video of the simulation in proteus of the symmetric source with pic 16f877a, and you will see that the values of the voltages and negative flash a lot and do not remain fixed.
    I know that the replacement of pic 16f877a is pic 16f887, and I want this same code to work with pic 16f887.
    In addition, this was a work that I presented at the university in my digital electronic subject and obtained a 4.0 as final work.
    Here I leave the link
    https://drive.google.com/file/d/1jlS...ew?usp=sharing


    And thanks again


    José

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    in the simulation in proteus on the 20x4 display in the positive and negative voltage blink a lot and they are not fixed, and I have not been able to correct this fault
    thats not even a close description of what i see in the vid


    i see an
    incompletely described pgm with no config settings
    performing an undescribed task
    in an unspecified circuit
    that when simulated in an unspecified environment
    performs not as hoped for(what ever that expectation is)


    who would have thought it ?
    Warning I'm not a teacher

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    Name:  symmetric power supply.jpg
Views: 998
Size:  458.0 KB

    I attached the image of the symmetrical power supply circuit, at the output of the positive voltage it has a voltage divider and at the output of the negative voltage it has a voltage comparator in inverter mode, so the code works perfectly with the pic 16f877a, in the 20x4 display the result of the negative and positive voltages flicker a lot, the objective is to correct this fault, and pass the code to work with the pic 16f887.

    thanks
    José

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    so
    a xtal osc freq unknown
    no OSC statement in pbp code
    and still not a clue about the config settings used
    no idea of how osc is treated in proteus
    and a cropped schematic thats barely readable
    no idea of how the 877a was setup in comparison
    Warning I'm not a teacher

  9. #9
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: pass pic basic pro pic from pic 16f877a to pic 16f887

    I assume you have a data sheet for your LCD. First, only update the screen when a value changes. This means tracking "OldVolts" through a separate variable. Next, when you DO update, only update the new values; in other words, don't update the whole screen, don't update the whole line, in fact, only update the actual characters that have changed. Another common issue is sending the Erase Screen command every time you want to change something. DON'T! Just update the changes. (Again, it is explained in common LCD data sheets how to change only 1 DDRAM address without having to reload the entire screen.)

Similar Threads

  1. Trying to integrate Visual Basic with PIC 16f877a
    By vtolentino in forum General
    Replies: 3
    Last Post: - 9th March 2011, 10:22
  2. serial interface pic 18f452 using pic basic pro
    By syed ahmed in forum Serial
    Replies: 0
    Last Post: - 16th May 2010, 06:46
  3. PIC BASIC or PIC BASIC PRO
    By kirkmans in forum USB
    Replies: 3
    Last Post: - 20th April 2007, 01:52
  4. Replies: 5
    Last Post: - 17th January 2006, 20:26
  5. help pic basic pro
    By f6ggy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2003, 01:55

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts