Blinking LED will not Blink


+ Reply to Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Angry Blinking LED will not Blink

    Hi thank you for reading this:-

    I am attempting to do simple litle program using a 627 / 628 that just loops a sequence of morse Led port on and off ... to Say "Don't Panic"

    ll works ok as it should but for one flash of LED 2nd or 3rd charactor (dots) in the D'

    See attached code.... I have attempted to re write the code... Use another chip... I have used another compiler but the thing will not flash that one last dot for me... I just get Dash, dot... D is Dash,dot,dot !!!!

    What am I doing wrong.... Have marked up the line :--

    XXXX dot !!!

    I have stuggled with this all afternoon....... Help !!!

    BR
    Andy
    Attached Files Attached Files

  2. #2

    Default Re: Blinking LED will not Blink

    I think you need to change your tris settings. Unless I missed something?

    You Have
    Code:
           TRISA=0          'All A Port outs
           TRISB=15         'All B Port Ins
           CMCON=7
            
           LED VAR PORTB.0
    TRISB = 15 = %00001111 which means you have portb 0 - 3 as inputs

    Try Trisb.0 = 0 or trisb = 0

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

    Default Re: Blinking LED will not Blink

    Quote Originally Posted by andybarrett1 View Post
    Hi thank you for reading this:-

    I am attempting to do simple litle program using a 627 / 628 that just loops a sequence of morse Led port on and off ... to Say "Don't Panic"

    ll works ok as it should but for one flash of LED 2nd or 3rd charactor (dots) in the D'

    See attached code.... I have attempted to re write the code... Use another chip... I have used another compiler but the thing will not flash that one last dot for me... I just get Dash, dot... D is Dash,dot,dot !!!!

    What am I doing wrong.... Have marked up the line :--

    XXXX dot !!!

    I have stuggled with this all afternoon....... Help !!!

    BR
    Andy
    There is nothing wrong with your code.

    Except
    Code:
    morse:pause 3500
          High led
          pause 5000       'Led on for 5 seconds
    
    D:    high led          'dash
          pause 1500      low led
          pause 500
          high LED         'XXXX  dot !!!
          pause 500
          low led
          pause 500
          high LED         'XXXX  dot !!!
          pause 500
          low led
          pause 1500       'gap
    The LED is high for five seconds then stays high for another 1.5 seconds on the "D dash" therefore you will not see any change and this could be the flash you are missing. To check add another "low led pause 500" after the "pause 5000".

    Code:
    morse:pause 3500
          High led
          pause 5000       'Led on for 5 seconds
          low led
          pause 500
    
    D:    high led          'dash
          pause 1500
          low led
          pause 500
          high LED         'XXXX  dot !!!
          pause 500
          low led
          pause 500
          high LED         'XXXX  dot !!!
          pause 500
          low led
          pause 1500       'gap

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

    Red face Re: Blinking LED will not Blink

    Hi Steve...

    It was the missing pause.. I worked it out just now...All working now :-)

    Totally didn't see that for 4 hours yesterday.....


    Thank you both Mark and Steve

    Have also righted the port setup too

    BR
    Andy

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

    Default Re: Blinking LED will not Blink

    I can make some suggestions for improvements if you want. Like use GOSUB. Bye the way as you use HIGH and LOW the tris is set automatically and you do not need to set it in your code. If you used LED=1 and LED=0 then you have to set tris in your code.

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

    Default Re: Blinking LED will not Blink

    Hi

    Always open to suggestion…. I did think of using Gosubs…But then reasoned as my code only 0k5 not worth it..

    Seems to be TRIS's seem to depend on how the sea state is in Liverpool as to when to set or not set. :-)

    Thank you again…..

    All help / suggestions welcome

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

    Default Re: Blinking LED will not Blink

    The only reason is to learn as one never knows when or indeed if what one learns will be useful.

    Create two subroutines one for dot and one for dash. Then in main D will be

    Gosub Dash
    Gosub Dot
    Gosub Dot

    Just as a start.

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

    Default Re: Blinking LED will not Blink

    Hi

    Thank you…. Pity I couldn't have them all on same line…:-

    D: GOSUB Dash, Dot, Dot

    Or could I ?

    TY Again !!

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

    Default Re: Blinking LED will not Blink

    What PBP do you have?

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

    Default Re: Blinking LED will not Blink

    2.50C

    Thinking of PBP3 Silver but is it that much different…?

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

    Default Re: Blinking LED will not Blink

    Quote Originally Posted by andybarrett1 View Post
    2.50C

    Thinking of PBP3 Silver but is it that much different…?
    With PBP3 you can create user commands so you could have

    D: Dash: Dot: Dot

    which is the only reason I asked.

    With 3 there is arrayread and arraywrite which you could use in this example. But as I am on 2.46 I am in no position to advise.

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

    Default Re: Blinking LED will not Blink

    Ah OK…..

    Maybe stay where I am then :-)

    Arrays are a hole new minefield for me….. Although I am OK with my Antenna Array on the roof. (Radio Ham)

    Whole lot of learning for me yet!

    BR and TY

    Andy

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

    Default Re: Blinking LED will not Blink

    Have a go with gosubs as a start, we can progress to arrays later. I could write examples for you but I believe you will learn more doing it yourself. As always if you need help just ask.

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Blinking LED will not Blink

    Quote Originally Posted by andybarrett1 View Post
    Hi

    Thank you…. Pity I couldn't have them all on same line…:-

    D: GOSUB Dash, Dot, Dot

    Or could I ?

    TY Again !!
    From the book...
    4.13. Multi-statement Lines

    In order to allow more compact programs and logical grouping of related commands, PBP supports the use of the colon ( to separate statements placed on the same line. Thus, the following two examples are equivalent:

    W2 = W0
    W0 = W1
    W1 = W2

    is the same as:

    W2 = W0 : W0 = W1 : W1 = W2

    This does not, however, change the size of the generated code.
    Dave
    Always wear safety glasses while programming.

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,573

    Default Re: Blinking LED will not Blink

    Hi,

    May be it is a bit overkill here ....

    but, When Melanie deals with something ....

    WOOOOHOOOO !!! ...

    that's great !!!

    http://www.picbasic.co.uk/forum/showthread.php?t=5510

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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

    Default Re: Blinking LED will not Blink

    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


    '************************************************* ***************
    '* Name : Morse_beta.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 17/08/2014 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    TRISA=0 'All A Port outs
    TRISB=0 'All B Port outs
    CMCON=7

    LED VAR PORTB.0 'LED Indicator

    Mess: pause 2000

    High led
    pause 5000 'Led on for 5 seconds
    low led
    pause 2000 'off for 2 seconds

    begin:
    m: gosub dash : gosub dash : gosub lgap
    o: gosub dash : gosub dash : gosub dash : gosub lgap
    s: gosub dot : gosub dot : gosub dot : gosub lgap
    t: gosub dash : gosub lgap
    l: gosub dot : gosub dash : gosub dot : gosub dot : gosub lgap
    y: gosub dash : gosub dot : gosub dash : gosub dash : gosub lgap

    spc: gosub space

    h: gosub dot : gosub dot : gosub dot : gosub dot : gosub lgap
    a: gosub dot : gosub dash : gosub lgap
    r: gosub dot : gosub dash : gosub dot : gosub lgap
    mm: gosub dash : gosub dash : gosub lgap
    ll: gosub dot : gosub dash : gosub dot : gosub dot : gosub lgap
    e: gosub dot : : gosub lgap
    ss: gosub dot : gosub dot : gosub dot : gosub lgap
    sss: gosub dot : gosub dot : gosub dot : gosub lgap


    pause 3500 '3.5 sec delay

    goto mess

    dash: high led 'dash
    pause 1500
    low led
    pause 500
    return

    dot: high led 'dot
    pause 500
    low led
    pause 500
    return

    lgap: pause 1000 'letter gap
    return

    spaceause 1000 'space
    return



    end

  17. #17
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,256

    Default Re: Blinking LED will not Blink

    Just thinking, use ASCII value of letter, load morse at that array element using special notation (letters have 1 to 3 codes).

    Only need 6 bits of 1 byte to store morse code of a letter:

    Bit 7, 1st code:
    0 not used
    1 used

    Bit 6, 1st code value:
    0 dot
    1 dash

    Bit 5, 2nd code:
    ...and so on...

    That way you can store morse code for entire alphabet using 1 byte each into an array.

    Then loop through a text string, gosub a routine that converts letter to ascii, looks up the array element and generates morse code.

    Only need a text string, main loop and morse subroutine.

    Robert

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

    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: 289
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!

  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,256

    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

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

    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

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