' ********************************************************************** ' * File: uk_BASAVR_013.BAS * ' * Version: 1.1 * ' * Date: 31.05.10 * ' * Development Tools: Bascom-AVR Demo Ver. 1.11.9.1 + * ' * + AVR bootloader grifo(r) Ver. 1.2 * ' * Cards: GMM AM08 + GMM TST3 * ' * Developed by: GRIFO(r) Italian Technology * ' * via Dell'Artigiano 8/6 * ' * 40016 S. Giorgio di Piano (BO) * ' * Tel. +39 051 892052 Fax. +39 051 893661 * ' * http://www.grifo.com http://www.grifo.it * ' * Author: Gianluca Angelini * ' ********************************************************************** ' Example program 13 of BASCOM AVR course. ' It manages a Morse characters generator with GMM TST3 on board buzzer. ' The program waits the reception of letters or digits from serial line and ' it generates them on buzzer with Morse code. The Morse codes generation ' speed is slow in order to allow the right recognition even from users with ' no experience; the time unit used by example is fixed and equal to about ' 200 msec. ' The reception of characters is perfrormed through a serial console provided ' of keyboard and monitor and it must communicate with a fixed physical protocol ' at 19200 Baud, 8 Bit x chr, 1 Stop bit, No parity. ' This console can be another system capable to support a serial RS 232 ' communication. In order to simplify the use it can be used a PC provided of ' one COMx line, that execute a terminal emulation program as HYPERTERMINAL or ' the homonym modality provided by BASCOM AVR (see IDE Configuration). ' ' Added instructions: And, Restore, Read, Data, Shift. ' ' 24/05/10: uk_BASAVR_013.BAS - Ver 1.1 - By G.A. ' First version. ' ' '**************************** IDE Configurations ******************************* ' NOTE: in order to coorectly use this demo program, please execute the following ' steps: ' 1) Check the availability of M8DEF.DAT file into the directory where the ' BASCOM AVR is installed and copy it if not present. ' 2) Into the window "Options | Compiler | Chip" set: ' Chip: m8def.dat ' XRAM: None ' HW Stack: 64 ' Soft Stack: 32 ' Framesize: 64 ' XRAM waitstate: disabled ' External Access Enable: disabled ' 3) Into the window "Options | Communication" set: ' COM port = the PC line connected to GMM AM08, through GMM TST3 ' Baudrate = 19200 ' Parity = None ' Databits = 8 ' Stopbit = 1 ' Handshake = None ' Emulation = TTY ' Font = Terminal, Normal, 12 points, white colour ' Backcolor = Navy ' 4) At the end of compilation, after the code is programmed on GMM AM08, open ' the terminal emulation window of BASCOM AVR with the option: Tools | ' Terminal emulator (Ctrl+T) and then reset or powen on the Mini Module. '************************* Compiler directives ********************************* $regfile "M8DEF.DAT" ' Definitions file for used microcontroller $romstart = &H0 ' Code start address on FLASH $crystal = 7372800 ' Microcontroller crystal frequency $hwstack = 64 ' Hardware stack space $swstack = 32 ' Software stack space $framesize = 64 ' Frame space $map ' Generate debug information $baud = 19200 ' Serial communication speed: 19200 Baud ' Other parameters fixed to: 8 bit x chr ' 1 Stop bit ' No parity '******************************* Definitions *********************************** ' The resources used by program are connected as described in following table. ' !!! Note: On GMM TST3 the jumpers must be set in following positions: ' J1 in 2-3 ; J2 in 2-3 ; J3 in 1-2 ; J8 in 2-3 !!! ' ' hardware pin Z1 pin Signal Signal ' resource GMM TST3 GMM AM08 GMM AM08 uP ' Buzzer BZ1 15 9 PB4 , MISO PB4 ' ' Signal pin COMx pin CN5 pin Z1 pin Signal Signal ' PC DB9 GMM TST3 GMM TST3 GMM AM08 GMM AM08 uP ' TX 3 3 9 3 RxD RS232 PD0 ' RX 2 2 10 4 TxD RS232 PD1 ' GND 5 5 20 14 GND - ' This table shows that the connection cable between PC COM line and CN5 of ' GMM TST3 is a normal pin to pin cable or direct. Grifo(r) can supply it by ' requesting the CCR 9+9E code. Pinbz1 Alias Portb.4 ' Bit with output signal connected to buzzer BZ1 Pinrx Alias Ddrd.0 ' Bit with direction signal connected to GMM AM08 Rxd Pintx Alias Ddrd.1 ' Bit with direction signal connected to GMM AM08 TxD '************************* Constants declaration ******************************* '************************* Variables declaration ******************************* Dim Mchr As Byte ' Character to generate with Morse Dim Ichr As Byte ' Index for character to generate search Dim Mcod As Byte ' Morse code of character to generate Dim Ncmp As Byte ' Component number of Morse code Dim Icmp As Byte ' Component index of Morse code Dim Mbit As Byte ' Current bit of Morse code Dim Del As Long ' Variable that count cycles for delay '************************ Subroutines declaration ****************************** Declare Sub Del_1unit() ' Generate delay of one Morse time unit Declare Sub Morse_chr() ' Generates a character with Morse code '****************************** Main program *********************************** Main: Pinrx = 0 ' Initialize signals for serial communication Pintx = 0 ' as digital inputs Pinbz1 = 1 ' Initialize signal connected to BZ1 as digital output, high Ddrb.4 = 1 Print ' Separate from previous visualization by showing an empty new line Print " Morse codes generator with buzzer" Print Print "Press digit and/or letter (0..9 , A..Z) to generate with Morse code..." Do ' Begin endless loop Mchr = Waitkey() ' Wait character received and save it If Mchr >= "0" And Mchr <= "Z" Then ' Check if character is valid: from "0" to "Z" Printbin Mchr ' Hows valid received character on console Call Morse_chr() ' Generate received character with Morse End If Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' It perform a delay of one Morse time unit. This endurance generates the Morse ' code slowly in order to allow right recognition. ' Input: None ' Output: None Sub Del_1unit() Del = 0 ' Reset performed loops counter for delay Do ' Begin delay loop Del = Del + 1 ' Increment variable that counts delay loops Loop Until Del > 23200 ' End delay loop of about 200 milliseconds End Sub ' It generates one letter with Morse code by using the table defined in the ' program. The codes generation speed is slow in order to allow the right ' recognition. ' Input: Mchr = variable with character to generate ' Output: None Sub Morse_chr() ' Get Morse code and number of components associated to character to generate ' from table defined at the end of program Mchr = Mchr - &H30 ' ASCII code of character to generate start from 0 Restore Morse ' Point to start of Morse table For Ichr = 0 To Mchr ' Loop that read the table from the start to character to generate Read Mcod ' Get Morse code of Ichr character from table Read Ncmp ' Get components of Ichr character from table Next Ichr ' It generates character with Morse by using the code and the number of ' components acquired from table. It is important to remind that on code ' a 0 bit equals to a point (buzzer enabled for a time unit) while a 1 bit ' equals to a line (buzzer enabled for 3 time units). Each components is ' normally separated from following one by one space (buzzer disabled for a ' time unit). For Icmp = 1 To Ncmp ' Loop repeated for the number of components Mbit = Mcod And &H01 ' Obtain less significant bit of code Pinbz1 = 0 ' Enable BZ1 buzzer If Mbit = 0 Then ' If current component is a point Call Del_1unit() ' Generate 1 time unit delay Else ' Current component is a line Call Del_1unit() ' Generate 3 time units delay Call Del_1unit() Call Del_1unit() End If Pinbz1 = 1 ' Disable BZ1 buzzer Call Del_1unit() ' Generate space of 1 time unit Shift Mcod , Right , 1 ' Shift code of one bit right Next Icmp ' Generate space between one character and following one (buzzer disabled for ' 3 time units) Call Del_1unit() ' Generate 3 time units delay Call Del_1unit() Call Del_1unit() End Sub '******************* End of subroutines used by program ************************ '************************** Data used by program ******************************* ' Each character is coded by two numbers: the first is the real bits code of ' the components and the second is the components number. The term components ' refers either to points and lines that compose each letters with Morse code, ' as follows: ' - the point equals to a bit at 0; ' - the line equals to a bit at 1; ' - in the code the less significant bit is the first to generate; ' - the characters are ordered with ASCII standard codes, starting from "0"=&H30. ' ' For example the character 1 is coded by: point line line line line ' with bits it becomes: 0 1 1 1 1 ' with inverted generation order it becomes: 1 1 1 1 0 ' that in Hexadecimal HEX is: 1E ' with a components number: 5 ' with BASCOM AVR it becomes: Data &H1E , 5 ' ' For example the character D is coded by: line point point ' with bits it becomes: 1 0 0 ' with inverted generation order it becomes: 0 0 1 ' that in Hexadecimal HEX is: 01 ' with a components number: 3 ' with BASCOM AVR it becomes: Data &H01 , 3 ' Morse: Data &H1F , 5 ' Character 0 Data &H1E , 5 ' Character 1 Data &H1C , 5 ' Character 2 Data &H18 , 5 ' Character 3 Data &H10 , 5 ' Character 4 Data &H00 , 5 ' Character 5 Data &H01 , 5 ' Character 6 Data &H03 , 5 ' Character 7 Data &H07 , 5 ' Character 8 Data &H0F , 5 ' Character 9 Data &H00 , 0 ' Character : Data &H00 , 0 ' Character ; Data &H00 , 0 ' Character < Data &H00 , 0 ' Character = Data &H00 , 0 ' Character > Data &H00 , 0 ' Character ? Data &H00 , 0 ' Character @ Data &H02 , 2 ' Character A Data &H01 , 4 ' Character B Data &H05 , 4 ' Character C Data &H01 , 3 ' Character D Data &H00 , 1 ' Character E Data &H04 , 4 ' Character F Data &H03 , 3 ' Character G Data &H00 , 4 ' Character H Data &H00 , 2 ' Character I Data &H0E , 4 ' Character J Data &H05 , 3 ' Character K Data &H02 , 4 ' Character L Data &H03 , 2 ' Character M Data &H01 , 2 ' Character N Data &H07 , 3 ' Character O Data &H06 , 4 ' Character P Data &H0B , 4 ' Character Q Data &H02 , 3 ' Character R Data &H00 , 3 ' Character S Data &H01 , 1 ' Character T Data &H04 , 3 ' Character U Data &H08 , 4 ' Character V Data &H06 , 3 ' Character W Data &H09 , 4 ' Character X Data &H0D , 4 ' Character Y Data &H03 , 4 ' Character Z '********************** End of data used by program ****************************