Continue to Site

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.

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

PIC basic Morse decoder

Status
Not open for further replies.

camerart

Well-Known Member
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.
 
you can do like this. : i wrote this for you and its crude and im using osconsoft. do reply.
its self explained
Code:
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
 
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
 
Code:
'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:
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.
 
Hi Magvitron,

I have closed the other thread this will save jumping around: https://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.
 
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.
 
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.

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.
 
only some lines are longer?
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.

Reason No chocolate
try dark chocolate, more cocoa, more "punch" ! feels great, like you know what.
 
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.

Ok, I'll make a note.

I tried some 90% at Christmas, a bit too much I think.
 
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.
 

Attachments

  • MORSE RECEIVER 160112.bas
    2.1 KB · Views: 442
  • 16F648A pins.jpg
    16F648A pins.jpg
    86.2 KB · Views: 553
I tried this in Oshonsoft simulator:

It stalled at LCD 'Lcdinit LcdCurBlink 'init lcd'
 

Attachments

  • MORSE RECEIVER 160112.bas
    2.4 KB · Views: 395
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.
 
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.

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

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.
 
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.
 
Ahaa!

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

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

Hurrah! It showed "MORSE DECODER" first then 'A'

Thanks very much for your help Ian.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top