• AVR Freaks

Hot!JAL (Just Another Language) source code for PICs

Author
PStechPaul
Super Member
  • Total Posts : 2667
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
2020/04/09 17:03:26 (permalink)
5 (1)

JAL (Just Another Language) source code for PICs

I just came across a project for a Morse code decoder, that had its source code written in "JAL", which appears to be a language similar to Pascal or pseudo-code. Apparently it is an open source project and has multiple libraries for PICs. I have not (yet) delved into it, but it looks interesting and may be useful.
 
More info on syntax and usage:
ht tps://www.casadeyork.com/jalv2/jalv2/index.html
 
The JAL website:
ht tp://www.justanotherlanguage.org/
 
(Having trouble posting - Access Denied crap...)

 
#1

4 Replies Related Threads

    PStechPaul
    Super Member
    • Total Posts : 2667
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: JAL (Just Another Language) source code for PICs 2020/04/09 17:04:31 (permalink)
    0
    The code for the Morse code decoder:

    -- Morse key decoder with LCD display and sounder.
    --
    -- Pins are:
    --
    -- B4        - Morse key
    -- CCP1 (C5) - Sounder
    -- C0-C3     - LCD data 0-3
    -- C6        - LCD RS
    -- C7        - LCD EN

    include 18f14k50

    -- Internal clock runs at 16MHz.
    pragma target clock         16_000_000

    -- Fuse settings.
    pragma target OSC           INTOSC_NOCLKOUT
    pragma target CPUDIV        P1
    pragma target PLLEN         DISABLED
    pragma target FCMEN         DISABLED
    pragma target IESO          DISABLED
    pragma target BROWNOUT      DISABLED
    pragma target WDT           CONTROL
    pragma target WDTPS         P64
    pragma target MCLR          EXTERNAL
    pragma target LVP           DISABLED
    pragma target DEBUG         DISABLED

    WDTCON_SWDTEN = OFF
    OSCCON_SCS = 0b00
    OSCCON_IRCF = 0b111

    -- Delay functions.
    include delay

    -- Switch debounce functions.
    include debounce

    -- Morse encoded to binary.
    include cwtable

    enable_digital_io()

    -- How long do we stay idle (ms) before we
    -- go back to the welcome screen?
    const dword RESETTIME = 120000

    -- How quickly do we adjust to changing
    -- speeds? (0-255)
    const dword ADJUSTRATE = 50

    -- How many milliseconds do we delay inside
    -- the loops?
    const byte MSDELAY = 1

    -- This counts how long the key presses and
    -- gaps are.
    var dword timer = 0

    -- Roughly the speed I send at. A dit of 120ms
    -- corresponds to 10 words per minute.
    var dword dittime = 120

    -- The morse key. Use B4 with weak pullup.
    INTCON2_NRABPU = off
    WPUB_WPUB4 = on
    alias cwkey is pin_b4
    pin_b4_direction = input
    var word dbstate = debounce_init(10)

    -- Sounder so our morse key can make beeps.
    pin_CCP1_direction = output
    include pwm_hardware
    pwm_set_frequency(1200)
    pwm1_set_dutycycle_percent(50)
    pwm1_off()

    -- Our LCD display
    alias lcd_rs is pin_C6
    alias lcd_rs_direction is pin_C6_direction
    alias lcd_en is pin_C7
    alias lcd_en_direction is pin_C7_direction
    alias lcd_dataport is portC_low
    alias lcd_dataport_direction is portC_low_direction
    lcd_rs_direction = output
    lcd_en_direction = output
    lcd_dataport_direction = output
    const byte lcd_rows = 2
    const byte lcd_chars = 8
    include lcd_hd44780_4

    -- Send a one-second beep as we start up.
    -- Largely for debugging.
    pwm1_on()
    delay_1ms(1000)
    pwm1_off()

    -- Initialise the display.
    lcd_init()

    -- A copy of the screen.
    const byte DISPLAYSIZE = 16
    var byte screen[DISPLAYSIZE] = {
        " ", " ", " ", " ", " ", " ", " ", " ",
        " ", " ", " ", " ", " ", " ", " ", " "
    }

    -- Add a character to the right of the
    -- the screen, scrolling left.
    procedure putc(byte in c) is
        var byte i
        lcd_cursor_position(0, 0)
        for DISPLAYSIZE-1 using i loop
            if i == 8 then
                lcd_cursor_position(1, 0)
            end if
            screen[i] = screen[i+1]
            lcd = screen[i]
        end loop
        screen[DISPLAYSIZE-1] = c
        lcd = c
        lcd_cursor_position(0, 0)
    end procedure

    -- Set the entire screen to a string.
    procedure puts(byte in s[DISPLAYSIZE]) is
        lcd_cursor_position(0, 0)
        var byte i
        for DISPLAYSIZE using i loop
            if i == 8 then
                lcd_cursor_position(1, 0)
            end if
            screen[i] = s[i]
            lcd = screen[i]
        end loop
        lcd_cursor_position(0, 0)
    end procedure

    -- OK, here we go!
    forever loop

        -- Welcome message. Must be exactly 16 characters.
        puts("CW decode by auj")

        -- Wait for the key to be pressed for the first time.
        -- No debounce here.
        while cwkey == 1 loop
            delay_1ms(MSDELAY)
        end loop

        -- Clear the screen.
        puts("                ")

        -- "found" holds the binary coding of what
        -- we've received so far. With a leading "1".
        var word found = 1

        -- Enter the decoder
        forever loop

            -- Turn on the beep.
            pwm1_on()

            -- Wait for debounced keyup.
            timer = 0
            while (debounce_fast(cwkey, dbstate) & 1) == 0 loop
                timer = timer + 1
                delay_1ms(MSDELAY)
            end loop

            -- Turn off the beep.
            pwm1_off()

            -- Shift this keypress into "found" and
            -- adjust the dit rate.
            found = found * 2
            if timer < dittime * 2 then
                lcd = "."
                dittime = (dittime * (256 - ADJUSTRATE) + timer*ADJUSTRATE) / 256
            else
                lcd = "_"
                found = found + 1
                dittime = (dittime * (256 - ADJUSTRATE) + timer*ADJUSTRATE/3) / 256
            end if

            -- Peg found so we don't overflow the table when someone
            -- sends rubbish.
            if found > CWTABLESIZE then
                found = CWTABLESIZE
            end if

            -- Now time the keyup. We need to do stuff
            -- inside this loop though.
            timer = 0
            while (timer < RESETTIME) & ((debounce_fast(cwkey, dbstate) & 1) == 1) loop
                timer = timer + 1
                delay_1ms(MSDELAY)

                -- A delay for one dash is an inter-character
                -- delay. Decode the character.
                if timer == dittime*3 then
                    if found >= CWTABLESIZE then
                        putc("?")
                    else
                        putc(cwtable[found])
                    end if
                    found = 1

                -- A delay for 7 dits is an inter-word delay.
                elsif timer == dittime*7 then
                    putc(" ")
                end if
            end loop

            -- RESETTIME reached - exit the decoder loop
            -- to the welcome text.
            if timer == RESETTIME then
                exit loop
            end if
        end loop
    end loop



     
    #2
    upand_at_them
    Super Member
    • Total Posts : 431
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: JAL (Just Another Language) source code for PICs 2020/04/14 12:32:49 (permalink)
    +1 (1)
    I've used JAL quite a bit over the years, as I'm too cheap to pay for Microchip's C compiler.
    #3
    PStechPaul
    Super Member
    • Total Posts : 2667
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: JAL (Just Another Language) source code for PICs 2020/04/14 22:18:44 (permalink)
    +2 (2)
    I paid for C18 about 16 years ago, but then XC8 was introduced, and I've been using the free version upgrades with no problems. JAL looks interesting, but it would require learning a new language and IDE, so I don't see any reason to switch. If I were just starting out without a long history of C programming, I might give it a shot. But C is more portable.

     
    #4
    ric
    Super Member
    • Total Posts : 26942
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: JAL (Just Another Language) source code for PICs 2020/04/14 22:25:15 (permalink)
    +4 (4)
    And the latest version of XC8 allows up to optimisation level 2 in the free version.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5