How To Convert Another Basic To SF

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
ARd16
Posts: 10
Joined: Mon Apr 10, 2023 10:23 am

How To Convert Another Basic To SF

Post by ARd16 » Sun Apr 16, 2023 12:58 pm

Hi There,
I will tried start to discuss about how to convert another Basic compiler to SF Compiler, due a reason I want to change use under PIC18F2550.
Here are the code :

Code: Select all

 Sub Lcd_home()
   Local Mem_bit As Byte
   Mem_bit = 1
   Cls
   Locate 1 , 1
   Lcd "<Manual Handle>"
   Call Set_lcd()
   Locate 2 , 2
   Lcd Chr(0) ; " " ; Chr(1)

   Do
      'up
      If Pind.6 = 0 Then
         M_sel = 0
         Mem_bit = 0
         If Main_freq < 1080 Then Main_freq = Main_freq + 1
         Call Set_lcd()
         Waitms 180
      End If
      'down
      If Pinb.6 = 0 Then
         M_sel = 0
         Mem_bit = 0
         If Main_freq > 875 Then Main_freq = Main_freq - 1
         Call Set_lcd()
         Waitms 180
      End If
      'enter
      If Pind.7 = 0 Then
         If M_sel = 0 And Mem_bit = 0 Then
            Menu_index = 0
            Call Main()
         Else
            Incr Menu_index
            If Menu_index > 4 Then Menu_index = 0
            Bitwait Pind.7 , Set
            Select Case Menu_index
               Case 0 : Call Main()
               Case 1 : Call Lcd_home()
               Case 2 : Call Memory()
               Case 3 : Call Text()
               Case 4 : Call Svmem()
            End Select
         End If
      End If
   Loop
End Sub

'-----------EDIT TEXT---------------
'when you press ENTER you get this
' press UP or ENTER

Sub Text()
   Cls
   Locate 1 , 1
   'X = Menu_text                                            'the TEXT
   Lcd "<Freq Name>"
   Locate 2 , 1
   Lcd Klick_up

   Do
      ' If you press UP you can edit text  (sub Edit_text)
      If Pind.6 = 0 Then Call Edit_text()
      'if you press enter   it go back to freq steps (sub main)  or if you have more menu's
      If Pind.7 = 0 Then
         Incr Menu_index
         If Menu_index > 4 Then Menu_index = 0
         Bitwait Pind.7 , Set
         Select Case Menu_index
            Case 0 : Call Main()
            Case 1 : Call Lcd_home()
            Case 2 : Call Memory()
            Case 3 : Call Text()
            Case 4 : Call Svmem()
         End Select
      End If
   Loop
End Sub

'--------MEMORY----------
Sub Memory()
   Cls
   Locate 1 , 1
   Lcd "<Menu Save>"
   Locate 2 , 1
   Lcd Klick_up
   If Aa < 1 Or Aa > 10 Then Aa = 1
   Do
      ' If you press UP you can edit text  (sub Edit_text)
      If Pind.6 = 0 Then Call Store_mem()

      If Pind.7 = 0 Then
         Incr Menu_index
         If Menu_index > 4 Then Menu_index = 0
         Bitwait Pind.7 , Set
         Select Case Menu_index
            Case 0 : Call Main()
            Case 1 : Call Lcd_home()
            Case 2 : Call Memory()
            Case 3 : Call Text()
            Case 4 : Call Svmem()
         End Select
      End If
   Loop
End Sub

Sub Lcd_mem()
   M_sel = 1
   Locate 1 , 1
   X = Menu_text(aa)
   Lcd X
   Aa_lcd = Save_m(aa)
   Lcd_freq = Aa_lcd / 10

   Locate 2 , 1
   Lcd "M"
   If Aa < 10 Then Lcd "0"
   Lcd Aa
   Locate 2 , 7
   If Lcd_freq < 100 Then Lcd " "
   Lcd Lcd_freq ; " Mhz"
   Waitms 180
End Sub

Sub Store_mem()
   Bitwait Pind.6 , Set
   Cls
   Call Lcd_mem()

   Do
      'up
      If Pind.6 = 0 Then
         If Aa < 10 Then Incr Aa
         Aa_lcd = Save_m(aa)
         Cls
         Call Lcd_mem()
      End If
      'down
      If Pinb.6 = 0 Then
         If Aa > 1 Then Decr Aa
         Cls
         Call Lcd_mem()
      End If

      If Pind.7 = 0 Then
         Bitwait Pind.7 , Set
         Main_freq = Save_m(aa)
         M_sel = 1
         Call Set_freq_dip()                                                                        'save it
         Menu_index = 0                                                                             'menu index MAX is set to 1 (0 & 1)
         Call Main()
      End If
   Loop
End Sub

'-------SAVE_MEM---------

Sub Svmem()
   Cls
   Locate 1 , 1
   Lcd "<Product Memory>"
   Locate 2 , 1
   Lcd Klick_up

   Do
      ' If you press UP you can edit text  (sub Edit_text)
      If Pind.6 = 0 Then Call Svmem_save()
      If Pind.7 = 0 Then
         Incr Menu_index
         If Menu_index > 4 Then Menu_index = 0
         Bitwait Pind.7 , Set
         Select Case Menu_index
            Case 0 : Call Main()
            Case 1 : Call Lcd_home()
            Case 2 : Call Memory()
            Case 3 : Call Text()
            Case 4 : Call Svmem()
         End Select
      End If
   Loop
End Sub


Sub Svmem_save()
   Bitwait Pind.6 , Set
   If Aa > 10 Or Aa < 1 Then Aa = 1
   Cls
   Locate 1 , 1
   Lcd "<Stored It>"
   Locate 2 , 1
   Lcd "M"
   If Aa < 10 Then Lcd "0"
   Lcd Aa
   Lcd_freq = Main_freq / 10
   Locate 2 , 7
   If Lcd_freq < 100 Then Lcd " "
   Lcd Lcd_freq ; " Mhz"
   Do
      'add to lcd
      If Pind.6 = 0 Then
         If Aa < 10 Then Incr Aa
         Bitwait Pind.6 , Set
         Lcd_freq = Main_freq / 10
         Locate 2 , 7
         If Lcd_freq < 100 Then Lcd " "
         Lcd Lcd_freq ; " Mhz"
         Locate 2 , 1
         Lcd "M"
         If Aa < 10 Then Lcd "0"
         Lcd Aa
         Waitms 180
      End If

      If Pinb.6 = 0 Then
         If Aa > 1 Then Decr Aa
         Bitwait Pinb.6 , Set
         Lcd_freq = Main_freq / 10
         Locate 2 , 7
         If Lcd_freq < 100 Then Lcd " "
         Lcd Lcd_freq ; " Mhz"
         Locate 2 , 1
         Lcd "M"
         If Aa < 10 Then Lcd "0"
         Lcd Aa
         Waitms 180
      End If

      If Pind.7 = 0 Then
         Save_m(aa) = Main_freq
         Menu_index = 0                                                                             'menu index MAX is set to 1 (0 & 1)
         M_sel = 1
         Bitwait Pind.7 , Set
         Call Main()
      End If
   Loop
End Sub

'---------'SUB EDIT TEXT-----------------------

Sub Edit_text()
   Local My_chr As Byte
   Local X_chr As Byte                                                                              ' counter for the 16 chars long text
   Local My_string As String * 16
   Bitwait Pind.6 , Set
   My_chr = 65
    If Aa < 10 Then
     X_chr = 3
    Else
    X_chr = 4
    End If
     My_string = Str(aa) + " "
   Cls
   Locate 1 , 1
   X = Menu_text(aa)
   Lcd X
   Cursor On                                                                                        'Blink
   Locate 2 , X_chr
   Lcd Chr(my_chr)
   Shiftcursor Left
   Do
      'KEY UP
      If Pind.6 = 0 Then                                                                            'UP select the chr you like to use
         Incr My_chr
         If My_chr = 33 Then My_chr = 65                                                            'from space to A
         If My_chr > 127 Then My_chr = 33                                                           'from Z to 0
         If My_chr = 58 Then My_chr = 32
         Locate 2 , X_chr
         Lcd Chr(my_chr)
         Waitms 200
         Shiftcursor Left
      End If

      'KEY DOWN
      If Pinb.6 = 0 Then                                                                            'Down select the chr you like to use
         Decr My_chr
         If My_chr = 31 Then My_chr = 57
         If My_chr < 33 Then My_chr = 127
         If My_chr = 64 Then My_chr = 32
         Locate 2 , X_chr
         Lcd Chr(my_chr)
         Waitms 200
         Shiftcursor Left
      End If

      'KEY ENTER
      If Pind.7 = 0 Then                                                                            'enter/next
         My_string = My_string + Chr(my_chr)                                                        ' add the chr to the string jump to next 1 to 16
         'Waitms 200
         Bitwait Pind.7 , Set
         Incr X_chr
         My_chr = 32
         Locate 2 , X_chr
         Lcd Chr(my_chr)
         Shiftcursor Left
         ' you MUST enter 16 chars  to exit  (enter is space if you dont need more letters
         If X_chr = 17 Then
            Menu_text(aa) = My_string
            Exit Do                                                                                 ' you have put 16 chars in string now we exit
         End If
      End If
   Loop
   'the exit setup
   Cursor Off
   Cls
                                                                                  'text on lcd to show we are done editing text
   Locate 1 , 2
   Lcd "SAVING DATA"
   For B = 1 To 16
       Locate 2 , B
       Lcd Chr(255)
       Waitms 100
   Next
Wait 1
   Cls
   Menu_index = 0
   Call Main()
End Sub

'------------SUB SET LCD----------------------------------
'this is for setup lcd freq & text
Sub Set_lcd()

   Lcd_freq = Main_freq / 10
   Locate 2 , 7
   If Lcd_freq < 100 Then Lcd " "
   Lcd Lcd_freq ; " Mhz"
   If M_sel = 0 Then
      Locate 2 , 2
      Lcd Chr(0) ; " " ; Chr(1)
   Else
      Locate 2 , 1
      Lcd Spc(6)
   End If

   Waitms 100
End Sub



Sub Set_freq_dip()
   Subfreq = Main_freq
   For Con = 0 To 11
      Root = 2 ^ Con
      Temroot = Subfreq And Root
      If Temroot > 0 Then
         Datapll(con + 1) = 1
      Else
         Datapll(con + 1) = 0
      End If
  Next Con
   Portb.0 = Datapll(12)
   Portb.1 = Datapll(11)
   Portb.2 = Datapll(10)
   Portb.3 = Datapll(9)
   Portb.4 = Datapll(8)
   Portb.5 = Datapll(7)
   Portc.0 = Datapll(6)
   Portc.1 = Datapll(5)
   Portc.2 = Datapll(4)
   Portc.3 = Datapll(3)
   Portc.4 = Datapll(2)
   Portc.5 = Datapll(1)
End Sub  
Thanks.
Ar.

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: How To Convert Another Basic To SF

Post by Jerry Messina » Mon Apr 17, 2023 10:46 am

Do you have a particular question or are you asking someone to re-write the entire program for you?

ARd16
Posts: 10
Joined: Mon Apr 10, 2023 10:23 am

Re: How To Convert Another Basic To SF

Post by ARd16 » Mon Apr 17, 2023 1:03 pm

Hi Jerry,
Thanks for your answer.
As well as you knew, I still learning SF Compiler, back like a VB 6.0.
So far, above code has been done with another Basic Compiler, I was build this hw use that code and very well working, with some modified I did.
With above code if it can be convert to SF, it will be my sample how to do for next, my goal is only for understand if this XBasic like this then SF like this.

:D :D :D
Thanks,
Ar.

Post Reply