after all ... PBP is not so bad ...


Results 1 to 24 of 24

Threaded View

  1. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Just for you Dave ...

    As requested ...


    want proof ??? Ok ... let's go !

    1St attempt : Mikrobasic 7.2 ...


    Code:
    program Gouvernail                                                                                                        ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim result  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
     '******************************************************************************
     sub Procedure Init ' Initialisation
     
     'CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    Delay_ms(500)
    Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
     Lcd_Cmd(lcd_Clear)
     Lcd_Cmd(lcd_cursor_off)
     
     end sub
     
    '*******************************************************************************
     main: ' ********* Principal *********
    '*******************************************************************************
     Init ' config. et init. du PIC
     
     while true ' début de la boucle
     
         result = adc_read(0)
         tension = result *  Vref /1024  ' en mv !!!
     
         '**************************************************************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            text = " Tribord "
         else
            Text = "  Babord "
     
         end if
     '*****************************************************************************
     ' Calcul de l'angle
     
            angle = 3133 * Fabs(tension - 4020) / 120000
     '*****************************************************************************
     ' Affichage
     
            LongintTostr(angle,valeur)
     
            Lcd_out(1, 1, text)
     
            Lcd_out(2,1,valeur)
     
             delay_ms(100)
     
     wend
    end.
    1:1 E-0 Linker error: NOT ENOUGH ROM

    NOTA: 2504 Words compiled for a 16F877A

    2nd Attempt : MikroBasic 7.2 ... NOT USING Fabs () ... = PbP ABS()

    Code:
    program Gouvernail                                                                                                        ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F877A sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim result  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
     '******************************************************************************
     sub Procedure Init ' Initialisation
     
    ' CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    Delay_ms(500)
    Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
     Lcd_Cmd(lcd_Clear)
     Lcd_Cmd(lcd_cursor_off)
     
     end sub
     
    '*******************************************************************************
     main: ' ********* Principal *********
    '*******************************************************************************
     Init ' config. et init. du PIC
     
     while true ' début de la boucle
     
         result = adc_read(0)
         tension = result *  Vref /1024  ' en mv !!!
     
         '**************************************************************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            text = " Tribord "
            angle = 3133 * (4020 - tension ) / 120000
         else
            Text = "  Babord "
            angle = 3133 * (tension - 4020) / 120000
     
         end if
     '*****************************************************************************
     ' Calcul de l'angle
     
    '        angle = 3133 * Fabs(tension - 4020) / 120000
     '*****************************************************************************
     ' Affichage
     
            LongintTostr(angle,valeur)
     
            Lcd_out(1, 1, text)
     
            Lcd_out(2,1,valeur)
     
             delay_ms(100)
     
     wend
    end.
    0:0 S-100 Success (Release build) - Timestamp: 10:15:57
    0:0 W-101 Used ROM: 1774 (86%) Used RAM: 80 (31%)
    0:0 W-102 Free ROM: 273 (14%) Free RAM: 176 (69%)

    a small bit better ...

    3rd attempt : MikroBasic PRO 3.2

    Code:
    program Gouvernail
    ' program PiloteAT50
    '************************************************* ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '************************************************* ****************************
     'program PiloteAT50
     
     ' Lcd module connections
     
    dim LCD_RS as sbit  at RB4_bit
        LCD_EN as sbit  at RB5_bit
        LCD_D4 as sbit  at RB0_bit
        LCD_D5 as sbit  at RB1_bit
        LCD_D6 as sbit  at RB2_bit
        LCD_D7 as sbit  at RB3_bit
        LCD_RS_Direction as sbit at TRISB4_bit
        LCD_EN_Direction as sbit at TRISB5_bit
        LCD_D4_Direction as sbit at TRISB0_bit
        LCD_D5_Direction as sbit at TRISB1_bit
        LCD_D6_Direction as sbit at TRISB2_bit
        LCD_D7_Direction as sbit at TRISB3_bit
    ' End Lcd module connections
     
    ' Symbol Up3 = PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
     dim resulta  as word
     
     dim tension as longint
     dim angle   as longint
     
     dim text    as string[9]
     dim valeur  as string[11]
     
     const Vref = 5000
     
    '*******************************************************************************
    main:
    '*******************************************************************************
    ' Init ' config. et init. du PIC
    ' CMCON = 7
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
    Delay_ms(500)
    'Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     LCD_init() ' initialisation Lcd sur PortB
     Lcd_Cmd(_LCD_CLEAR)
     Lcd_Cmd(_Lcd_Cursor_Off)
     
    while true    ' début de la boucle
           resulta = adc_read(0)
           tension = resulta *  Vref /1024  ' en mv !!!
           '************************************************************************
           ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
           if tension < 4020 then
              text = " Tribord "
              '*********************************************************************
               ' Calcul de l'angle
               angle = 3133 * ( 4020 - tension ) / 120000
           else
              Text = "  Babord "
              angle = 3133 * (tension - 4020) / 120000
           end if
       '*****************************************************************************
       ' Affichage
              LongintTostr(angle,valeur)
              Lcd_out(1, 1, text)
              Lcd_out(2,1,valeur)
               delay_ms(100)
    wend
    end.
    0 133 Compiled Successfully C:\Program Files\Mikroelektronika\ProjetsBPro\Gouvernail\Gouv ernail.mbas
    0 1143 Used ROM (program words): 1722 (84%) Free ROM (program words): 326 (16%)
    0 1143 Used RAM (bytes): 44 (18%) Free RAM (bytes): 196 (82%)

    a tiny little bit better ...

    4Th attempt : Our favourite PicBasicPro v 2.60 / MPASM/ MCS ( left MkB lines commented besides PbP lines ...)

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 30/04/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'program Gouvernail                                                                                                        ' program PiloteAT50
    '*************************************************   ****************************
     ' microcontroleur : 16F819 sur EasyPic 5
     '
    ' Projet : PPE 2010
     '
    ' En entree : A0 Up3 = entree analogique
     '
     ' En sortie : portB Affichage des consignes "Babord et Tribord" sur lcd
     '
     '*************************************************   ****************************
     'program PiloteAT50
     
    @ ERRORLEVEL -306
    @ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_OFF
     
     entree var PORTA.0 ' tension analogique (<5V)
    ' déclaration des variables
    ' dim result  as word
     
    ' dim tension as longint
    ' dim angle   as longint
     
    ' dim text    as string[9]
    ' dim valeur  as string[10]
     
    ' const Vref = 5000
    result var word
    tension var word
    angle var word
    dummy var word
    vref con 5000
     
     '*************************************************  *****************************
     'sub Procedure Init ' Initialisation
     
     
    DEFINE  OSC 8
     
    CLEAR
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTB          ' LCD Data port
    DEFINE LCD_DBIT  0              ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB          ' LCD Enable port
    DEFINE LCD_EBIT  5              ' Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB          ' LCD Register Select port
    DEFINE LCD_RSBIT 4              ' Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4              ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2              ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ' Command delay time in us 
    DEFINE LCD_DATAUS 50            ' Data delay time in us 
    ;----[LCD definitions]------------------------------------------------------
    DEFINE ADC_BITS 10 ' set number of bits in result
    DEFINE ADC_CLOCK 3 ' set clock source
    ADCON1 = %10000000  ' right formatted
     
    ' CMCON = 7
     
     trisb = %00000000 ' portB en sortie
     trisa = %11111111 ' portA en entrée
     
    'Delay_ms(500)
    PAUSE 500
    'Lcd_Config(PORTB, 3, 2, 1, 0, PORTB, 4, 6, 5) ' Initialize LCD connected to PORTB
     'LCD_init(PORTB) ' initialisation Lcd sur PortB
     
    ' Lcd_Cmd(lcd_Clear)
    ' Lcd_Cmd(lcd_cursor_off)
    LCDOUT $FE,1
     
    ' end sub
     
    '*************************************************  ******************************
     main: ' ********* Principal *********
    '*************************************************  ******************************
    ' Init ' config. et init. du PIC
     
     'while true ' début de la boucle
     while 1=1
     
    '     result = adc_read(0)
        adcin 0, result
         dummy = result * Vref 
         tension = DIV32 1024  ' en mv !!!
     
         '*************************************************  *************************
         ' < ou > 4.02 v ???    ( 1024 * 4.02/5 = 823 !!! )
     
         if tension < 4020 then
     
            LCDOUT $FE,2, " Tribord "
         else
            LCDOUT $FE,2, "  Babord "
         endif
     '*************************************************  ****************************
     ' Calcul de l'angle
     
    '        angle = 3133 * abs(tension - 4020) / 120 / 1000
            dummy = 3133 * abs(tension - 4020)
            angle = DIV32 12000
            angle = angle /10
     '*************************************************  ****************************
     ' Affichage
     
    '        LongintTostr(angle,valeur)
     
    '        Lcd_out(1, 1, text)
     
    '        Lcd_out(2,1,valeur)
            LCDOUT $FE, $C0, dec3 angle
     
    '         delay_ms(100)
              PAUSE 100
     
     wend
    end
    Success ; 461 Words ...


    Really astonishing for such a simple work !!!, don't you think ???

    Alain

    PS; as we are under the 2K limit EVERYONE can verify it with the Demo available versions of MikroBasic and MikroBasic Pro ...
    Last edited by Acetronics2; - 1st May 2010 at 12:17. Reason: ask Dave !!!
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

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