Blinking LED will not Blink


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Blinking LED will not Blink

    Quote Originally Posted by andybarrett1 View Post
    Hi Steve.

    My attempt at using gosubs... First thing I notice is the memory saving. I Know I could improve things by putting all the letters in a table and calling them up....Ideally I would like to be able to use a 24C32 or similar but how do I get the table in there ??

    That way I could have lots more messages !!!

    Anyway... Any suggestions on how to improve on my basics here.

    Thank you

    Andy
    Hi Andy,

    To use the code tags go advanced and use the # icon.

    A way forward is to use a bit pattern within a byte simply by indicating . as 0 and - as 1.

    this would make S 000 or the whole byte %00000000 which will not work but if we add a start bit 1 we get %00001000 or $08 in hex.

    and O would be 111 and with the start bit 1111 we get $00001111 or $0F

    and so on for all of the ASCII characters.

    One way to encode each character in a message is to use a lookup table using the ASCII decimal value.

    Name:  Capture.PNG
Views: 1451
Size:  87.6 KB

    The first 32 characters are often ignored as they are not keyboard characters, with a few exceptions obviously.
    Code:
    TranslateASCIIMorse:
        MorseCode=0
            '
            ' Translate Numerics (0-9)
            ' ------------------------
        If ASCIIData>47 then
            If ASCIIData<58 then
                Lookup (ASCIIData-53),[$20,$30,$38,$3C,$3E],MorseCode            ' 5 6 7 8 9
                endif
            If ASCIIData<53 then
                Lookup (ASCIIData-48),[$3F,$2F,$27,$23,$21],MorseCode            ' 0 1 2 3 4
                endif
            endif
            '
            ' Translate Alphabetics (A-Z)
            ' ---------------------------
        If ASCIIData>96 then
            If ASCIIData<123 then ASCIIData=ASCIIData-32
            endif
        If ASCIIDATA>64 then
            If ASCIIData<91 then
                  Lookup (ASCIIData-82),[$0A,$08,$03,$09,$11,$0B,$19,$1B,$1C],MorseCode              ' R S T U V W X Y Z
                  endif
            If ASCIIData<82 then
                  Lookup (ASCIIData-73),[$04,$17,$0D,$14,$07,$06,$0F,$16,$1D],MorseCode              ' I J K L M N O P Q
                  endif
            If ASCIIData<73 then
                  Lookup (ASCIIData-65),[$05,$18,$1A,$0C,$02,$12,$0E,$10],MorseCode              ' A B C D E F G H
                  endif
            endif
            '
            ' Translate special characters
            ' ----------------------------
        If ASCIIData=39 then MorseCode=$5E            ' ' Apostrophe
        If ASCIIData=40 then MorseCode=$6D            ' ( Brackets
        If ASCIIData=41 then MorseCode=$6D            ' ) Brackets
        If ASCIIData=58 then MorseCode=$78            ' : Colon
        If ASCIIData=44 then MorseCode=$73            ' , Comma
        If ASCIIData=45 then MorseCode=$61            ' - Hyphen
        If ASCIIData=47 then MorseCode=$32            ' / Oblique Stroke
        If ASCIIData=46 then MorseCode=$55            ' . Period
        If ASCIIData=63 then MorseCode=$4C            ' ? Question
        If ASCIIData=34 then MorseCode=$52            ' " Quotation Moarks
            '
            ' Translate Space
            ' ---------------
        If ASCIIData=32 then MorseCode=$FF
        Return
    Now we have encoded the character we need a decode routine.
    Code:
    SendMorseCode:
        If MorseCode=$FF then                          ' Execute Word Pause
            MorseEnable=MorseDot*80
            Pause MorseEnable
            Return
            endif
        MorseEnable=0        ' Reset Enable
        For MorseBitPointer=0 to 7                   ' Loop Up to 8 Times
            If MorseEnable=0 then                     ' Check for Character Start Flag
                If MorseCode.7=1 then MorseEnable=1            ' Set Morse Character Start Flag
                else            ' If Morse sub-element Enabled, Send sub-element
                ToneTime=(50000/DefaultBeepPitch/10)*MorseDot            ' Determine Morse Dot Time
                If MorseCode.7=1 then
                    ToneTime=ToneTime*3                                                ' Determine Morse Dash Time
                    endif
                Gosub BeepOut
                ToneTime=MorseDot*10
                Pause ToneTime
                endif
            MorseCode=MorseCode<<1        ' Shift to next Morse sub-element
            Next MorseBitPointer
        MorseEnable=MorseDot*30        ' Determine & Execute End of Character Pause
        Pause MorseEnable
        Return
    Melanie used a beeper in the above code it needs changing to use LED and PAUSE
    Code:
    MorseDot con 500
    MorseDash con 1500
    MorseSpace con 4000
    
    SendMorseCode:
        If MorseCode=$FF then                                          ' Execute Word Pause                        
            Pause MorseSpace
            Return
        endif
        MorseEnable=0                                                      ' Reset Enable
        For MorseBitPointer=0 to 7                                      ' Loop Up to 8 Times
            If MorseEnable=0 then                                        ' Check for Character Start Bit
                If MorseCode.7=1 then MorseEnable=1            ' Set Morse Character Start Flag
                else  
                    High LED                                                             ' If Morse sub-element Enabled, Send sub-element
                    If MorseCode.7=0 then  Pause MorseDot                ' Dot
                    If MorseCode.7=1 then  Pause MorseDash              ' Dash
                    Low LED
                    If MorseBitPointer !=7 then Pause MorseDot
                endif
            MorseCode=MorseCode<<1        ' Shift to next Morse sub-element
            Next MorseBitPointer
           Pause MorseDash                        'End of character pause same pause as dash but LED is low
        Return
    These snippets need stitching together along with other parts of Melanie's code which can be found following the link in post #15. I will leave that to you to do but as usual if you have any questions just ask. BTW I have not tested the above and have only simulated the code in my mind, again I leave that to you to do.

    Andy you get all the fun!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Blinking LED will not Blink

    Quote Originally Posted by EarlyBird2 View Post
    ....A way forward is to use a bit pattern within a byte simply by indicating . as 0 and - as 1.

    ... we add a start bit 1 we get %00001000 or $08 in hex.

    and O would be 111 and with the start bit 1111 we get $00001111 or $0F

    and so on for all of the ASCII characters.
    ...
    Weird, I was sure morse was up to 3 characters, turns out it's up to 5 characters.


    I've tried all sorts of ways to try to store morse in as little space. Turns out the start bit technique is the best one yet.


    There's non-English code ś and special character $ here that can be up to 7 characters; so you could still fit that in 8 bits.
    http://en.wikipedia.org/wiki/Morse_code


    The only character I haven't figured how to store is prosign ERROR; 8 dots. I suppose that could be hard-coded?

    Robert

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: Blinking LED will not Blink

    Hi All…

    Thank you for all your words of wisdom.

    Away at moment but will read and make sense of the advice when I am back

    Thank you for replies


    Andy

Similar Threads

  1. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 06:19
  2. PIC16F819 LED not blinking
    By ronbowalker in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 1st December 2009, 02:04
  3. blinking LED
    By kindows in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 31st July 2009, 16:08
  4. PIC18f452 blinking led ?
    By iugmoh in forum General
    Replies: 5
    Last Post: - 7th March 2008, 14:12
  5. Why is my LED not blinking?
    By Gary Goddard in forum General
    Replies: 14
    Last Post: - 1st January 2007, 20:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts