Menu

SAA1057 PLL listing in Oshonsoft BASIC-Can this be translated to GCB?

2023-12-11
2023-12-17
  • David Briscoe

    David Briscoe - 2023-12-11

    I would like to know if it is possible to translate the attached Oshonsoft Basic code listing into GCB format? The code drives an old Philips SAA1057 phase locked loop chip. I will post the data sheet in the next post. The listing is a bit long to post inline but I can do that if it is preferred. I just want someone experienced in GCB Basic to cast a quick eye over the code before I make an attempt at conversion. Thanks.

     

    Last edit: David Briscoe 2023-12-11
  • David Briscoe

    David Briscoe - 2023-12-11

    Here is the data sheet of the SAA1057.

     
  • Anobium

    Anobium - 2023-12-11

    Yes, the conversion is very practical.

    I would rewrite major pieces of the program as things are easier in GCBASIC.

    I would start with a blank project. And, start with following program. ( See the attachment.. it works).

        #chip 16F628, 4 
        #option Explicit
    
    
    // --- lcd ini ---
    
        'LCD connection settings
        #define LCD_IO 4 
        #define LCD_NO_RW 
        #define LCD_RS             PORTA.2 
        #define LCD_Enable         PORTA.3 
        #define LCD_DB4            PORTB.0 
        #define LCD_DB5            PORTB.1 
        #define LCD_DB6            PORTB.2 
        #define LCD_DB7            PORTB.3 
    
    
    // Main Program
        Locate 1,0
        Print "Tube oscillator"
        Locate 2,0
        Print "Heater warmup"
    
        Do
    
        Loop
    

    And, then, when you have the LCD working you will have the confidence to develop the next piece.

    Ask here as you may have questions. Folks will help.

     
  • David Briscoe

    David Briscoe - 2023-12-11

    Thanks. How does GCB handle these 2 lines

    Define CONF_WORD = 0x3f41

    AllDigital

    Is the fuse configuration handled elsewhere than in the source file? I'm used to having to write the fuse information explicitly into the source code listing (I mainly use CCS C compiler).

     
    • Anobium

      Anobium - 2023-12-11

      The config is automatically handled, but, it you want/need to change then you can use PICINFO. PICINFO with generate the correct config - that is compatible with GCBASIC, MPASM and PIC-AS assemblers.

      Access PICINFO via Function Key <f4> and select PICINFO.</f4>


      A config of 0x3f41 is the default with Code Protect = ALL, MCLRE=OFF, OSC=XT, PWRTE=ON

      So, this tells me you have an external OSC and you want to protect the code.

      So, using PICINFO would generate

      #CONFIG CPD=OFF
      #CONFIG LVP=OFF
      #CONFIG MCLRE=OFF
      #CONFIG OSC=XT
      #CONFIG PWRTE=ON
      #CONFIG WDTE=OFF
      #CONFIG CP=ALL
      

      added to the example program as follows:

       #chip 16F628, 4 
          #option Explicit
      
      #CONFIG CPD=OFF
      #CONFIG LVP=OFF
      #CONFIG MCLRE=OFF
      #CONFIG OSC=XT
      #CONFIG PWRTE=ON
      #CONFIG WDTE=OFF
      #CONFIG CP=ALL
      
      // --- lcd ini ---
      
          'LCD connection settings
          #define LCD_IO 4 
          #define LCD_NO_RW 
          #define LCD_RS             PORTA.2 
          #define LCD_Enable         PORTA.3 
          #define LCD_DB4            PORTB.0 
          #define LCD_DB5            PORTB.1 
          #define LCD_DB6            PORTB.2 
          #define LCD_DB7            PORTB.3 
      
      
      // Main Program
          Locate 1,0
          Print "Tube oscillator"
          Locate 2,0
          Print "Heater warmup"
      
          Do
      
          Loop
      
       
  • David Briscoe

    David Briscoe - 2023-12-16

    Thanks.
    This is what i've got so far.

    '''GCBASIC Program.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''Description:Simple GCBASIC Blinky program.
    '''This program puts some text on an LCD (LATER)
    '''And makes 4 LEDs flash repeatably in sequence.
    '''@author    David J S Briscoe
    '''@licence    GPL
    '''@version   1.0
    '''@date      16th December 2023
    '''********************************************************************************
    
    #chip 16F628a, 4 
    #option Explicit
    
    
    #CONFIG CPD=OFF
    #CONFIG LVP=OFF
    #CONFIG MCLRE=ON
    #CONFIG OSC=INTOSCIO
    #CONFIG PWRTE=OFF
    #CONFIG WDTE=OFF
    #CONFIG CP=OFF
    #CONFIG BOREN=ON
    
    //! Set the port as an output
    DIR PORTB OUT
    //! Set the LED on
    PORTB.3 = 1
    
    
    
    // --- lcd ini ---
    
    /*
    
    'LCD connection settings
    #define LCD_IO 4 
    #define LCD_NO_RW 
    #define LCD_RS             PORTA.2 
    #define LCD_Enable         PORTA.3 
    #define LCD_DB4            PORTB.0 
    #define LCD_DB5            PORTB.1 
    #define LCD_DB6            PORTB.2 
    #define LCD_DB7            PORTB.3 
    
    */
    
    
    // Main Program
    
    /*
    Locate 1,0
    Print "Tube oscillator"
    Locate 2,0
    Print "Heater warmup"
    */
    
    Do
    
    //! Rotate to shift the port values to the right.  We use the carry bit to reset the sequence
    ROTATE PORTB RIGHT
    
    //! Set the port.bit to the value of C.  This will only be 1 when the portb.0 is shifted to the carry by the ROTATE
    PORTB.3 = C
    
    //! Wait 100 ms
    Wait 100 ms
    
    Loop
    

    I've used these PIC16F628A's in the past with assembly language and the comparator/s needed setting up. Is this done automatically in GCBASIC or do I have to include a line to do this?
    I've not tested this on hardware yet, will do that next week. Are there any problems with GCBASIC when using an ICD3 programmer? I'm assuming I can program the *.hex files using MPLAB IPE V6.15? Thanks.

    PS Is there a simulator or debugger included in GCB and where do I read about using it.

     

    Last edit: David Briscoe 2023-12-16
    • Anobium

      Anobium - 2023-12-16

      GBASIC will Turn off the comparator - this is the default setting

      CMCON = 7


      Programming. Yes, you can use ICD3 direct from GCCODE IDE leveraging MPLAB IPE.

      Select MPLAB-IPE ICD3 CLI for PIC using external power in Programmer Preferences and drag to the top of the list.

      When you compile you can program with ease.

       
      • David Briscoe

        David Briscoe - 2023-12-16

        I can't find MPLAB-IPE ICD3 CLI for PIC using external power in programmer preferences. It has an add button and I don't mind doing some editing to a batch file or config file if that's whats needed. Just tell me how. Thanks.

         
        • Anobium

          Anobium - 2023-12-16

          We dont use batch files any more.

          Do you see the following in Prefs Editor?
          What version are you on ? Compile something.. post the top lines of the ASM file producd. It will look like this.. It will tell me loads of things.

          ;Program compiled by GCBASIC (1.01.00 2023-12-11 (Windows 64 bit) : Build 1313) for Microchip MPASM/MPLAB-X Assembler using FreeBASIC 1.07.1/2023-12-13 CRC29
          ;Need help? 
          ;  See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
          ;  Check the documentation and Help at http://gcbasic.sourceforge.net/help/,
          ;or, email us:
          ;   w_cholmondeley at users dot sourceforge dot net
          ;   evanvennn at users dot sourceforge dot net
          ;********************************************************************************
          ;   Source file    : D:\GreatCowBASICGits\Help.git\trunk\seven_inch_gcld\code\gcbasic\009_GLCDProgram.gcb
          ;   Setting file   : C:\GCstudio\gcbasic\use.ini
          ;   Preserve mode  : 2
          ;   Assembler      : "C:\Program Files\Microchip\xc8\v2.45\pic-as\bin\pic-as.exe"
          ;   Programmer     : C:\GCstudio\gcbasic\..\PICKitPlus\PICKitCommandline.exe
          ;   Output file    : D:\GreatCowBASICGits\Help.git\trunk\seven_inch_gcld\code\gcbasic\009_GLCDProgram.asm
          ;********************************************************************************
          
           
          • David Briscoe

            David Briscoe - 2023-12-16

            As requested

            ;Program compiled by GCBASIC (1.01.00 2023-11-23 (Windows 64 bit) : Build 1308) for Microchip MPASM/MPLAB-X Assembler using FreeBASIC 1.07.1/2023-11-25 CRC29
            ;Need help? 
            ;  See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums,
            ;  Check the documentation and Help at http://gcbasic.sourceforge.net/help/,
            ;or, email us:
            ;   w_cholmondeley at users dot sourceforge dot net
            ;   evanvennn at users dot sourceforge dot net
            ;********************************************************************************
            ;   Source file    : C:\Users\david\Desktop\PIC16F628A_SAA1057_EXPERIMENTS\GCBASIC\Blinky_628A\main.gcb
            ;   Setting file   : C:\GCstudio\gcbasic\use.ini
            ;   Preserve mode  : 0
            ;   Assembler      : "C:\Program Files\Microchip\xc8\v2.45\pic-as\bin\pic-as.exe"
            ;   Programmer     : 
            ;   Output file    : C:\Users\david\Desktop\PIC16F628A_SAA1057_EXPERIMENTS\GCBASIC\Blinky_628A\main.asm
            ;********************************************************************************
            
            ;Set up the assembler options (Chip type, clock source, other bits and pieces)
             LIST p=16F628A, r=DEC
            #include <P16F628A.inc>
             __CONFIG _CP_OFF & _CPD_OFF & _LVP_OFF & _BOREN_ON & _MCLRE_ON & _PWRTE_OFF & _WDTE_OFF & _FOSC_INTOSCIO
            
            ;********************************************************************************
            
             
            • Anobium

              Anobium - 2023-12-16

              You are on a current toolchain.

              Did you scroll down in Prefs Editor to find the programmer ?


              But, as we do not upgrade/change the use.ini file. You may need to add this to the C:\GCstudio\gcbasic\use.ini file. See attachment(s).

              See specifically 1227 file.

               
              • David Briscoe

                David Briscoe - 2023-12-16

                Yes. Please find attached a screenshot of the full list presented.

                 
                • Anobium

                  Anobium - 2023-12-16

                  Did you edit the USE.INI ?

                  You place just above the [toolvariables] section.

                   
                  • David Briscoe

                    David Briscoe - 2023-12-16

                    Attached is my copy of the use.ini file in which I have added the contents of the 127 file just above the [toolvariables] section as requested. Give me about 15 mins while I have a brew and an apple. then I'll restart the IDE to see if there are any changes. Thanks.

                     

                    Last edit: David Briscoe 2023-12-16
                  • Anobium

                    Anobium - 2023-12-16

                    My apologies....

                    [tool = mplab_ipe_icd3_use_ext_power]
                    desc = MPLAB-IPE ICD3 CLI for PIC using external power
                    type = programmer
                    useif = 
                    progconfig = 
                    command = %mplabxipedirectory%\ipecmd.exe
                    params = -TPICD3 -P%chipmodel% -M -F"%filename%" -OL
                    workingdir = %mplabxipedirectory%\ipecmd.exe
                    

                    This is from the master which is in your GCstudio\use_in_master folder.

                     
                    • David Briscoe

                      David Briscoe - 2023-12-16

                      The ICD3 line shows up at the bottom of the list now. I will test this over the Christmas break as I have an ICD3 here at home but I'll have to dig out my development board and grab a few 628a's that we dont use any more.
                      Does the PICKIT4 work as well? We have a few of those hanging around at work. Thanks.

                       
                      • Anobium

                        Anobium - 2023-12-16

                        Yes, PK4 is should be shown.

                        PK4/5/ICD3 are all slow compared to PK2/PK3. Choose carefully... :-)

                         
  • Jerry Messina

    Jerry Messina - 2023-12-16

    I've used these PIC16F628A's in the past with assembly language and the comparator/s needed setting up. Is this done automatically in GCBASIC or do I have to include a line to do this?

    It should be done for you. To check out what gets done automatically, compile the file and open the resulting .asm file. Find the routine labeled 'INITSYS'... here's what I get compiling your file:

    INITSYS
    ;asm showdebug This code block sets the internal oscillator to ChipMHz
    ;asm showdebug _Complete_the_chip_setup_of_BSR_ADCs_ANSEL_and_other_key_setup_registers_or_register_bits
        movlw   7
        movwf   CMCON
        clrf    PORTA
        clrf    PORTB
        return
    
     
  • David Briscoe

    David Briscoe - 2023-12-17

    Continuing with my original question about the Oshonsoft listing how would these variables be defined in GCBASIC?

    Dim data(15) As Byte
    Dim tlr As Byte
    Dim deler As Word
    Dim deler1 As Word
    deler = 0
    deler1 = 32768
    
    Dim freq As Word
    Dim freq1 As Word
    Dim freqhun As Byte
    Dim freqten As Byte
    
    Dim ht As Byte
    

    Are they EXACTLY the same? Here is the Oshonsoft reference

    https://www.oshonsoft.com/picbasiccompilerreferencemanual.php#23

    Thanks.

     

    Last edit: David Briscoe 2023-12-17
    • David Briscoe

      David Briscoe - 2023-12-17

      The next section is writing to and reading from the internal EEPROM

      '---- firstime on ----
      Read 0, freqhun
      If freqhun < 87 Or freqhun > 108 Then
          freqhun = 87
          Write 0, freqhun
          freqten = 50
          Write 1, freqten
      Endif
      Read 1, freqten
      
      freq1 = freqhun * 100 + freqten
      

      According to the Oshonsoft help file in the link above Read and Write are aliases for EEPROM_Read and EEPROM_Write respectively. Are there any built in function/subroutines for the internal EEPROM for the 628A or do I have to create my own with the help of the examples? Thanks.

       
      • Anobium

        Anobium - 2023-12-17

        Have you looked at the Help?

        EPREAD and EPWRITE do the same.

         
  • Anobium

    Anobium - 2023-12-17

    Looks the same, but, ensure these variables are not controlling the chip/mcu frequency as this is done via the #chip <chip>, 'frequency'

    See the Help for lots of details but note the Arrays are 1-based. The first element is element zero but your first element is at element 1.

     

Log in to post a comment.