PDA

View Full Version : Blinking LED will not Blink



andybarrett1
- 16th August 2014, 22:24
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

mark_s
- 17th August 2014, 00:50
I think you need to change your tris settings. Unless I missed something?

You Have



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

EarlyBird2
- 17th August 2014, 08:36
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


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".


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

andybarrett1
- 17th August 2014, 08:58
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

EarlyBird2
- 17th August 2014, 09:16
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.

andybarrett1
- 17th August 2014, 09:27
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

EarlyBird2
- 17th August 2014, 09:33
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.

andybarrett1
- 17th August 2014, 09:37
Hi

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

D: GOSUB Dash, Dot, Dot

Or could I ?

TY Again !!

EarlyBird2
- 17th August 2014, 09:38
What PBP do you have?

andybarrett1
- 17th August 2014, 09:43
2.50C

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

EarlyBird2
- 17th August 2014, 09:48
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.

andybarrett1
- 17th August 2014, 09:57
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

EarlyBird2
- 17th August 2014, 10:12
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.

mackrackit
- 17th August 2014, 14:06
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.

Acetronics2
- 17th August 2014, 15:02
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

andybarrett1
- 20th September 2014, 19:25
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

space:pause 1000 'space
return



end

Demon
- 21st September 2014, 01:49
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
:)

EarlyBird2
- 21st September 2014, 09:12
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

AndyHi 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.

7449

The first 32 characters are often ignored as they are not keyboard characters, with a few exceptions obviously.


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.


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


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

Demon
- 22nd September 2014, 21:51
....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

andybarrett1
- 24th September 2014, 21:20
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