Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with counter in swordfish

be80be

Well-Known Member
Code:
Dim count As Word         'symbol not expected
count = 0




While True
   ' Initialize or reset counter (optional)
   ' You can skip this if you're doing it conditionally inside the loop
   ' count = 0 

   ' Convert count to individual digits
   Number(0) = count Mod 10
   Number(1) = (count \ 10) Mod 10
   Number(2) = (count \ 100) Mod 10
   Number(3) = (count \ 1000) Mod 10

   ScanDisplay()

   DelayMS(5)
   Inc(count)

   If count = 10000 Then
      count = 0
   End If
Wend

I get error symbol not expected when i declare count as word
 
I played with swordfish and see what i do is write the code and then AI reads it makes it look good and changes stuff back you done had fixed but its really working my brain
 
I like it because i don't have a lot of time and it clean up my code and tell what each part is doing but writing code it's good at only some things the pico its dead on arduino dead on pic never right But swordfish basic its probably going to get right cause I spent 16 hours showing and writing code using swordfish help files

I mean look at this

Code:
'===============================================================================
' Project:      LED Blink
' Target:       PIC18F25Q10
' Compiler:     Swordfish BASIC
' Author:       Burt Ratliff & Gemini
' Description:  This program blinks an LED connected to pin RB0 once per second.
'===============================================================================

' --- Device and Clock Configuration ---

' Tell the compiler which PIC microcontroller we are using.
Device = 18F25Q10
Clock=64
' Set the clock speed. The 18F25Q10 has a high-frequency internal oscillator.
' We'll use the default 64MHz, which Swordfish will automatically configure.
' For higher speeds, you would set it here, e.g., Clock = 32
Include "intosc.bas"                ' Alternative: this library can auto-configure the internal oscillator (if available)
Include "system.bas"                  ' System library (provides NOP, Delay routines, etc.)
Include "Utils.bas"                  'for SetAllDigital()
' --- Fuses / Configuration Words ---
' Swordfish handles many fuses automatically based on the 'Device' and 'Clock'
' commands. For a simple blink, we don't need to manually set them.
' For more complex projects, you would add 'Config' lines here to disable
' things like the Watchdog Timer (WDT). For example:
' Config WDT = False

' --- Pin Alias ---

' It's good practice to give a descriptive name to the pin you are using.
' Let's assume the LED is connected to Port B, pin 0.
Dim LED As PORTB.0

' --- Main Program ---

' Set the data direction for the LED pin to an output.
' In the TRIS register, 0 = Output and 1 = Input.
SetAllDigital()      'Sets All Digital
    OSCCON1 = $60   'sets osc to 64
    OSCFRQ = $08      'need this to if you wan't 64 mhz
    ANSELB = $00      ' turns off adc
    TRISB = $00 ' Set all PORTb pins as output for simplicity
    LATB = $00  'Start with all pins low

' Ensure the LED starts in a known state (off).
Low(LED)
DelayMS(500) ' A brief pause before starting the loop.

' Start an infinite loop that will run forever.
While True
    ' Toggle the state of the LED pin (if it's on, turn it off; if off, turn on).
    Toggle(LED)

    ' Wait for 500 milliseconds (half a second).
    ' The LED will be on for 500ms and off for 500ms, resulting in a 1-second blink.
    DelayMS(500)
Wend
 
I find AI helpful for identifying what registers are involved in a function.
 
I pay for it so I can train it I had it read swordfish language Reference so it can now write code a lot better

But micropython its great hard part is me telling what i want happen the code is dead on plus its opened my blind eyes
I can see things lot better.
 
Funny one i ask it too show how to wire a 7 segment and pic 4 transistors it shorted all the pins it drawed a breadboard
but put chip across the short side not down the center.
 
Burt! Don't get me wrong. You can do what ever you like.. But if someone does your homework, how will you know for definite, how every thing works..

Assume what we learn here.. Many Many newbe's ask "Can you do it for me" and we always say. You'll never learn if we do it for you. We are teaching these people NOT to learn..
 
Ian I wrote the blinks ai did the comments
Ai didn’t write any code that works in xc 8 or swordfish I wrote code that did I like how it cleans it up and tells how it works you can learn from that plus I’m 62 still work 6 to 7 days a week and I love making things I leaned a lot from AI in the last week I’m not being lazy I still trying to write good code
 
Last edited:
Ian I wrote the blinks ai did the comments
Ai didn’t write any code that works in xc 8 or swordfish I wrote code that did I like how it cleans it up and tells how it works you can learn from that plus I’m 62 still work 6 to 7 days a week and I love making things I leaned a lot from AI in the last week I’m not being lazy I still trying to write good code
Same age.. My son uses AI to draw all his pictures for the books he writes.. All in all , it does a good job. But having said that! Its a good job I'm pretty good with Gimp!! So I can fix the lil issues. LOL.
 
I love Glimp I'm working on doing what i love to do I'm really what they call a automation electrician I fix fully automatic car washes I'm now working on there show lighting I found a cheap rasberry pi pico which is a arm mo that can run micropython and its dead simple to code using there neopixel libraries. $4 bucks so i probably go with it.
the video shows it lighting 300 ws2815 same as the ws2812 as code goes but there 12 volt and if one dies the leds that are good still work.

 

Latest threads

New Articles From Microcontroller Tips

Back
Top