Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
'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
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.
the multiline is actually an extension.. ieonly some lines are longer?
try dark chocolate, more cocoa, more "punch" ! feels great, like you know what.Reason No chocolate
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.
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.
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.
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