' ********************************************************************** ' * File: uk_BASAVR_053.BAS * ' * Version: 1.1 * ' * Date: 16.11.11 * ' * 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 053 of BASCOM AVR course. ' It manages an additional asynchronous serial line. ' The Mini Module GMM AM08 is provided with only one hw serial line, connected ' to USART peripheral device, and this program adds a second sw serial line, ' connected to two I/O lines. The sw serial line is managed through the high ' level instructions of BASCOM that are suspensive, or in other words, they ' stop program execution during transmission and reception of characters. ' By comparing a sw serial line to an hw one, many differences came out as ' limits on communication speed (Baud rate), a really higher execution load ' for the microcontroller and the denied possibility to transmit and receive ' contemporaneously. ' The program supports the following operations on sw serial line: ' - comunicate with 4800 Baud, 8 Bits x chr, 1 Stop bit, No parity physical ' protocol; ' - receive characters in suspensive mode and shows then on console; ' - transmit the characters typed on console. ' About electric protocol, the sw serial line of Mini Module is at TTL level ' and normally it must be buffered in order to communicate with other external ' serial devices. For this scope we remind the MSI 01 interface that convert a ' TTL serial line in RS 232, RS 422, RS 485 o Current Loop electric standard. ' The user can comunicate with sw serial line by using a console provided of ' monitor and keyboard, connected to hw serial line, with a fixed physical ' protocol at 19200 Baud, 8 Bits 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). ' The program works only when the GMM AM08 is mounted on Z2 socket of GMM TST3!! ' ' Added instructions: OPEN, PUT, GET, CLOSE. ' ' 16/11/11: uk_BASAVR_053.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, copy it if not present and then restart the IDE. ' 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 configured as below described: ' J1 in 2-3 ; J2 in 1-2 ; J3 in 1-2 ; J5 in 2-3 ; J7 in 2-3 ; J8 in 2-3 ' J9 in 2-3 !!! ' ' Software GMM TST3 pin Z2 pin Signal Used uP ' serial line resource GMM TST3 GMM AM08 GMM AM08 signal ' RX SW CN4.16 24 18 PD3 INT1 PD3 ' TX SW CN4.13 23 17 PD4 T0 PD4 ' ' 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. 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 Crxsw As Byte ' Character received from sw serial line Dim Ctxsw As Byte ' Character to transmit on sw serial line Dim Key As Byte ' Key pressed on console '************************ Subroutines declaration ****************************** '****************************** Main program *********************************** Main: Pinrx = 0 ' Initialize signals for serial communication Pintx = 0 ' as digital inputs Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " Sw serial line management on GMM AM08 + GMM TST3" Print "Mount Mini Module on Z2 of GMM TST3 and connect the external serial device" Print "(configured at 4800 Baud, 8 Bits, 1 Stop, No parity) as described in electric" Print "diagram." Print "The program waits the reception of characters from sw serial line, it shows" Print "them on console, and it transmits the keys pressed on sw serial line" Print Print "The reception of sw serial line is suspensive and the program goes on only" Print "when the serial device is connected and transmit characters!!" ' Initializes the sw serial line for 4800 Baud, 8 Bits x chr, 1 stop Bit, No parity ' on the I/O signals defined in previous table. ' In the program source the following two instructions must be used before each ' other instructions that use the sw serial line. Open "comd.4:4800,8,N,1" For Output As #1 ' Associate signal used as transmission line, to channel 1 Open "comd.3:4800,8,N,1" For Input As #2 ' Associate signal used as reception line, to channel 2 Do ' Begin endless loop Get #2 , Crxsw ' Wait character from sw serial line associated to channel 2 Printbin Crxsw ' Shows received characters on console Key = Inkey() ' Get possible key pressed on console If Key <> 0 Then ' If key pressed Ctxsw = Key ' Copy key pressed on character to transmit Put #1 , Ctxsw ' Transmit character on sw serial line, associated to channel 1 End If Loop ' End endless loop ' In the program source the following two instructions must be used after each ' other instructions that use the sw serial line. Close #1 ' Close channels associated to sw serial line Close #2 End '*************************** End of main program *******************************