1. 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.
    Dismiss Notice

PIC basic Morse decoder

Discussion in 'Oshonsoft' started by camerart, Jan 14, 2013.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I am trying to make a PIC chip Morse decoder.

    First I need to accept signals from a tone chip NE567. Then calculated the dots and dashes to make letters and numbers.

    I want it to be in PIC basic, so that I can edit it, if anyone can help.

    Cheers, Camerart.
     
  2. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    you can do like this. : i wrote this for you and its crude and im using osconsoft. do reply.
    its self explained
    Code (text):

    Define LCD_BITS = 8
    Define LCD_DREG = PORTB
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTD
    Define LCD_RSBIT = 1
    Define LCD_EREG = PORTD
    Define LCD_EBIT = 3
    Define LCD_RWREG = PORTD
    Define LCD_RWBIT = 2
    Dim a As Word
    Dim i As Word
    Dim j As Word
    Dim k As Word
    Dim arr(10) As Byte
    Lcdinit LcdCurBlink
    Lcdout "Morse decoder"
    loop:
    i = i + 1
    While PORTC.0 = 0
    Wend
    While PORTC.0 = 1
    k = k + 1
    WaitMs 10  'you can change delay here for suit your need
    If k >= 3 Then
    Goto break_off
    Endif
    Wend
    break_off:
    While PORTC.0 = 1
    WaitMs 10  'you can change delay here for suit your need
    a = a + 1
    Wend

    If k = 3 Then
    arr(j) = 2  'dash
    Else
    If k = 1 Then
    arr(j) = 1  'dot
    Endif
    j = j + 1
    Endif
    If a = 3 Then
    arr(j) = 2  'one letter
    Call display(1)
    Else
    If a = 1 Then
    arr(j) = 1  'space b/w char
    Endif
    Endif
    k = 0
    If i = 10 Then
    j = 0  'maxchar 10 (0)
    Endif
    Goto loop
    End                                              
    'short mark, dot Or "dit"(·) — 1
    'longer mark, dash Or "dah" (–) — 111
    'intra-character gap (between the dots And dashes within a character) — 0
    'short gap (between letters) — 000
    'medium gap(between words) — 0000000

    Proc display(arg1 As Byte)
    WaitMs 100
    Lcdcmdout LcdLine2Home
    Lcdcmdout LcdLine2Clear
    If arr(0) = 1 And arr(1) = 2 Then
    Lcdout "A"
    Endif


    End Proc                                          
     
     
    • Like Like x 1
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Hi Magvitron,

    It might be crude, but brilliant. Thanks for doing that.

    It will take me a while to put it into Oshonsoft, and go through it. Can you tell me in a little detail what it does please?

    What I need is to convert a tone from an earphone, which goes through a tone decoder chip NE or LM567 then the program will read Morse code from this chip and look up a table to match to a letter on number in Ascii, then print it onto the LCD.

    Thanks, Camerart
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.

    Code (text):
    'short mark, dot Or "dit"(·) — 1
    'longer mark, dash Or "dah" (–) — 111
    'intra-character gap (between the dots And dashes within a character) — 0
    'short gap (between letters) — 000
    'medium gap(between words) — 0000000
     
    Define LCD_BITS = 8' 8bit interface
    Define LCD_DREG = PORTB'data at port b
    Define LCD_DBIT = 0'start at portb.0
    Define LCD_RSREG = PORTD'register select at portd.1
    Define LCD_RSBIT = 1
    Define LCD_EREG = PORTD'enable bit at d3
    Define LCD_EBIT = 3
    Define LCD_RWREG = PORTD'rw bit at port d.2
    Define LCD_RWBIT = 2

    'defining some variables
    Dim a As Word
    Dim i As Word
    Dim j As Word
    Dim k As Word
    Dim arr(10) As Byte
    Lcdinit LcdCurBlink 'init lcd
    Lcdout "Morse decoder"'display test
    loop: 'loop (main loop)
    i = i + 1 ' test variable (for the array becuase its only 10 member array)
    While PORTC.0 = 0 'test the portc .0 (connect the pin from 567 here) if there is no data
    'control will remain here
    Wend
    While PORTC.0 = 1 'registered a change (+ve)
    k = k + 1 'increment variable
    WaitMs 10  'you can change delay here for suit your (need delay for some time)
    'one symbol is 10ms wide here
    If k >= 3 Then ' if the symbol is 30 ms wide
    Goto break_off
    Endif
    Wend ' return to while
    break_off:
    While PORTC.0 = 0 '
    WaitMs 10  'you can change delay here for suit your need
    a = a + 1
    if(a >3)
    goto ends
    endif
    Wend
    'test for dot dash . .. etc
     ends:
    If k = 3 Then
    arr(j) = 2  'dash
    Else
    If k = 1 Then
    arr(j) = 1  'dot
    Endif
    j = j + 1
    Endif
    If a = 3 Then
    arr(j) = 2  'one letter
    Call display(1)
    Else
    If a = 1 Then
    arr(j) = 1  'space b/w char
    Endif
    Endif
    k = 0
    If i = 10 Then
    j = 0  'maxchar 10 (0)
    Endif
    Goto loop
    End                                              

    Proc display(arg1 As Byte)
    WaitMs 100
    Lcdcmdout LcdLine2Home
    Lcdcmdout LcdLine2Clear
    'test : i.e if dot dash ==character 'A'
    If arr(0) = 1 And arr(1) = 2 Then
    Lcdout "A"
    Endif
     
     
    End Proc
     
    Last edited by a moderator: Jan 15, 2013
  6. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    i have replied with the crude logic i have used. I dont know its helpful or not, but its a start. you can experiment with it. change timings etc.
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Hi Magvitron,

    I have closed the other thread this will save jumping around: http://www.electro-tech-online.com/threads/interfacing-20-x-4-lcd-display.132410/

    Thank you for your reply, never apologise for your code, it's really helpful, and a great help to me.

    I entered the 1st code into Oshonsoft. I use 16F648A PIC which has 2X ports. (I can change) I had to alter your 1st code which broke it, but it has gone in, now I can read through and change it.

    Thanks for your 2nd code, I will join it to the 1st part in Oshonsoft, then work through it as you suggest.

    I'm not a good programmer though, so hopefully you can correct my mistakes as I get stuck?

    Regarding the LCD, I didn't get data sheets with them, but they look like they are recent. I still haven't found out whether they are serial or parallel yet. I have never worked with serial.

    Cheers, Camerart.
     
  8. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    hey cam,
    >>if you are using 20x4 LCD display majority uses a hitachi controller for decoding. Its like a pseudo-multi line thing. the 3rd line is actually the extension of the first and the 4th line the extension of the second one. so you can code using this.

    >>great to know that my code was helpful to you :) I Am offering my full support for your project.

    >> the codes are identical.. didn't you notice that? the second code has been commented by me for you to better understand what i meant with some assignations and increment etc. try to have a logic picture for what you need to code. I will calm my mind for 5 minutes and then think about how to solve issues. Works every time. Try to code with calm mind and when you feel that you are not getting to anywhere just do something else like listening to music or something

    TIP: have some dark chocolate with you. In times of magical coding give your brain a a treat of endorphin by having a piece of chocolate.
     
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Thanks Tron,

    I have now corrected the program. No I didn't notice they were the same. (Reason No chocolate:D this will be remedied immediately).

    I am waiting for some more LCds 16X2, they are 'on the boat'. I will choose which ones I prefer later, they look to have similar connections, and might have data sheets this time. If I understand correctly, both 2 and 4 line LCDs have the same program, only some lines are longer?

    While I'm waiting for them I will print out your program and familiarise myself with it.

    I really appreciate your help, I was getting nowhere with it before.

    Cheers, Camerart.
     
  10. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    the multiline is actually an extension.. ie
    for a 4 line lcd; 3rd line is an extension of the first, 4 th line an extension of 2nd.

    try dark chocolate, more cocoa, more "punch" ! feels great, like you know what.
     
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Ok, I'll make a note.

    I tried some 90% at Christmas, a bit too much I think.
     
  12. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I had a look at the program and nearly understand. I have changed the ports so it would compile on Oshonsoft. These need to be changed to fit the 16F648A PIC.

    Will it go onto this PIC? If so how many pins will I have left over?

    Most of the changes are marked >>>>>>>>>>>>>>

    2X attachments.

    Cheers, Camerart.
     

    Attached Files:

  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    I tried this in Oshonsoft simulator:

    It stalled at LCD 'Lcdinit LcdCurBlink 'init lcd'
     

    Attached Files:

  14. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    you have to change the speed of simulation to ultimate to see whats going on. the delays must be small because osconsoft is not powerful enough to simulate realtime. So you gotta increase the speed of simulation.
     
  15. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    I put my foot down, and at the higher speed, it did initilise the LCD and the cursor blinks. Then at the next line 'LCD test', it seemed to pass that and go to the loop, I tried it with a wait, but it didn't change anything.

    Can you check the pin outs of the PIC 16F648 to make sure it is configured correctly please? I simply changed your program to ports that the PIC has without any thought, as I don't know how to set-up an LCD.
     
  16. magvitron

    magvitron Active Member

    Joined:
    Jan 11, 2013
    Messages:
    257
    Likes:
    28
    Location:
    John Lennon !magine land.
    the oschon soft software automatically detects all of those things and adjust automatically.. so no need for that.. did you notice a dialog box showing "do you want to get lcd module parameter*" if yes then click yes. it will load the lcd module with the pin assigned by us.
     
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    I went through the ports and assigned the pins better?, and did press 'yes'. It could be working now. It didn't type "MORSE DECODER", after initialisation, but went straight into the loop. I have been trying to enter an 'A' into the input to make it type A, but so far no luck.
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Camerart... Two things!!

    1) The pic you are using has comparators on PORTA... Start the code with the " ALLDIGITAL" command, this will sort this out.

    2) When simulating within oshonsoft you can increase simulation speed by using the " DEFINE SIMULATION_WAITMS_VALUE = 1"

    This will change ALL delays to there fastest level. When you run it for real change to " DEFINE SIMULATION_WAITMS_VALUE = 0".


    Also there is suppose to be a delay after LCDinit but as you are on the sim it won't matter.
     
  19. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Ahaa!

    I've now changed to 16F819, does all of your message still apply?

     
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Even more so... That pic defaults to analog pins on boot.... The ALLDIGITAL command makes them digital pins..

    Also!! Remember to tris port a and b as they default to inputs...

    Good luck
     
  21. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,396
    Likes:
    11
    Location:
    Dorset UK.
    Hurrah! It showed "MORSE DECODER" first then 'A'

    Thanks very much for your help Ian.
     

Share This Page