'------------------------------------------------------------------ ' MAX6 test MORSE ' By Jarek SP3SWJ sp3swj@gmail.com ' based on PA3CKR morse sender ' Created with Bascom-Avr: 1.11.9.3 '------------------------------------------------------------------ $regfile = "m128def.dat" $crystal = 11059200 $baud = 115200 ' use baud rate $loadersize = 1024 '$hwstack = 128 '$swstack = 128 '$framesize = 196 'some routines to control the display are in the glcdKS108.lib file 'First we define that we use a graphic LCD KS0108 $lib "glcdKS108.lbx" Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portc , Ce = 7 , Ce2 = 6 , Cd = 3 , Rd = 4 , Reset = 5 , Enable = 2 Config Timer1 = Pwm , Prescale = 1 , Pwm = 8 , Compare B Pwm = Clear Down 'The AUTO feature, will select the highest clockrate possible Config Adc = Single , Prescaler = Auto Config Pinb.4 = Input '1=on-MAX 0=0ff-MAX - start OFF Key_power_on Alias Pinb.4 Key_power_on_pullup Alias Portb.4 Config Portb.5 = Output Buzer Alias Portb.5 'use as PWM backlit output Portb.6 'POWER on SWITCH 1=ON Config Porte.7 = Output Switch_power_on Alias Porte.7 'ON=1 OFF=0 Config Pine.2 = Input Key_function Alias Pine.2 Key_function_pullup Alias Porte.2 Config Pine.3 = Input Key_mode Alias Pine.3 Key_mode_pullup Alias Porte.3 Config Pine.4 = Input Key_down Alias Pine.4 Key_down_pullup Alias Porte.4 Config Pine.5 = Input Key_up Alias Pine.5 Key_up_pullup Alias Porte.5 Config Pind.1 = Input ' USB=0 LCD=1 Key_lcd_mode Alias Pind.1 Key_lcd_mode_pullup Alias Portd.1 '=============================================================================== Dim Lcd_light As Byte Dim Second_old As Byte '============================== START ====================================== Cls 'provide pull-up for KEYBOARD Set Key_function_pullup Set Key_down_pullup Set Key_up_pullup Set Key_mode_pullup Set Key_power_on_pullup Set Key_lcd_mode_pullup Lcd_light = 0 Setfont Font16x16 Reset Switch_power_on Lcdat 2 , 1 , "HOLD PWR" Wait 1 Pwm1b = Lcd_light Set Switch_power_on Lcdat 2 , 1 , "RELASE !" Pwm1b = 255 Wait 1 'Setfont Font8x8 Dim Sendstring As String * 45 Dim Sendchar As String * 1 Dim Charcode As Byte Dim Dataindex As Byte Dim Charindex As Byte Dim Nextcharindex As Byte Dim Charstring As String * 12 Dim Stringlength As Byte Dim Codelength As Byte Dim Codeindex As Byte Dim Codeelement As String * 1 Dim Concatindex As Byte Morsepin Alias Portb.5 Soundpin Alias Pinb.5 Config Soundpin = Output 'Set Speed and Dot, they determine the remaining constants Const Speed = 12 Const Dot = 600 / Speed Const Dash = 3 * Dot Const Letter = Dash Const Wordw = 7 * Dot Const Frequency = 1300 Print "Sendchar Charcode Dataindex" Do Sendstring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 ?><" 'get length of string Stringlength = Len(sendstring) 'for each character in this string For Charindex = 1 To Stringlength 'extract character and get decimal ascii code Sendchar = Mid(sendstring , Charindex , 1) Charcode = Asc(sendchar) Cls 'is space, wait space time If Charcode = 32 Then Lcdat 4 , 1 , "space" Print " " Waitms Wordw 'if other than "<" handle character Elseif Charcode <> 60 Then 'get ranknumber and looup corresponding morse string Dataindex = Charcode - 35 Lcdat 1 , 1 , Sendchar ; " " ; Charcode ; " " ; Dataindex , 0 Print Sendchar ; " " ; Charcode ; " " ; Dataindex Charstring = Lookupstr(dataindex , Morse_alfabet) Lcdat 3 , 1 , Charstring 'get length of morse string Codelength = Len(charstring) 'for each character in this string For Codeindex = 1 To Codelength 'extract character Codeelement = Mid(charstring , Codeindex , 1) 'send dot sound If Codeelement = "." Then Sound Morsepin , Dot , Frequency Morsepin = 1 'send dash sound Else Sound Morsepin , Dash , Frequency Morsepin = 1 End If 'wait dot time, but not after last character If Codeindex < Codelength Then Waitms Dot Next Codeelement 'if next character in sendstring is not "<", wait letter time Nextcharindex = Charindex + 1 Sendchar = Mid(sendstring , Nextcharindex , 1) Charcode = Asc(sendchar) If Charcode <> 60 Then Waitms Letter 'else wait dot time Else Waitms Dot End If End If Next Charindex Waitms 500 Loop End Morse_alfabet: Data "........." '# Data "........." '$ Data "........." '% Data "........." '& Data ".----." ' ' Data "-.--." ' ( Data "-.--.-" ') Data "........." '* Data "........." '+ Data "--..--" ', Data "-...._" '- Data ".-.-.-" '. Data "-..-." '/ Data "-----" '0 Data ".----" '1 Data "..---" '2 Data "...--" '3 Data "....-" '4 Data "....." '5 Data "-...." '6 Data "--..." '7 Data "---.." '8 Data "----." '9 Data "---..." ': Data "........." '; Data "........." '< Data "........." '= Data "........." '> Data "..--.." '? Data "........." '@ Data ".-" 'A Data "-..." 'B Data "-.-." 'C Data "-.." 'D Data "." 'E Data "..-." 'F Data "--." 'G Data "...." 'H Data ".." 'I Data ".---" 'J Data "-.-" 'K Data ".-.." 'L Data "--" 'M Data "-." 'N Data "---" 'O Data ".--." 'P Data "--.-" 'Q Data ".-." 'R Data "..." 'S Data "-" 'T Data "..-" 'U Data "...-" 'V Data ".--" 'W Data "-..-" 'X Data "-.--" 'Y Data "--.." 'Z 'we need to include the font files $include "font8x8.font" $include "font16x16.font"