' ********************************************************************** ' * File: uk_BASAVR_020.BAS * ' * Version: 1.1 * ' * Date: 02.08.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 20 of BASCOM AVR course. ' It manages an alphanumeric display with 2 x 20 characters. ' The program shows each characters received by console serial line on the ' GMM TST3 display. This display is LCD type backligted by LED, it is provided ' of controller and it has 2 rows of 20 characters. The program completely ' manages it through the high level instructions dedicated to display, available ' in BASCOM AVR. ' The character to show are received from a serial console provided of 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). ' The program works only when the GMM AM08 is mounted on Z1 socket of GMM TST3!! ' ' Added instructions: Config Lcdmode; Config Lcdbus; Config Lcdpin; Config Lcd; ' Cls; Lcd; Locate. ' ' 02/08/10: uk_BASAVR_020.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 | Compiler | LCD" set: ' LCD type = 20 * 2 ' BUS mode = 4 bit ' Data mode = pin ' Enable = PORTD.2 ' RS = PORTD.3 ' DB7 = PORTC.3 ' DB6 = PORTC.2 ' DB5 = PORTD.5 ' DB4 = PORTD.4 ' LCD-address = don't care ' RS-address = don't care ' Make upper 3 bits 1 in LCD designer = not selected ' 4) 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 ' 5) 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 ; J3 in 1-2 ; J10 in 1-2 ; J11 in 1-2 !!! ' ' hardware pin Z1 pin Signal Used uP ' resource GMM TST3 GMM AM08 GMM AM08 signal ' LCD.DB4 23 17 PD4 T0 XCK PD4 ' LCD.DB5 22 16 PD5 T1 PD5 ' LCD.DB6 21 15 PC2 ADC2 PC2 ' LCD.DB7 19 13 PC3 ADC3 PC3 ' LCD.E 25 19 PD2 INT0 PD2 ' LCD.RS 24 18 PD3 INT1 PD3 ' ' 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 ******************************* Const Maxcol = 20 ' Maximum number of display column Const Maxrow = 2 ' Maximum number of display rows '************************* Variables declaration ******************************* Dim Rxchr As Byte ' Character received from serial console Dim Rowlcd As Byte ' Row of current display position Dim Collcd As Byte ' Column of current display position '************************ Subroutines declaration ****************************** '****************************** Main program *********************************** Main: Pinrx = 0 ' Initialize signals for serial communication Pintx = 0 ' as digital inputs Print ' Separate from previous visualization by showing an empty new line Print Print " Management of alphanumeric LCD display 20 x 2" ' Introduce program on console Print "The program show the characters received from serial line on LCD display of" Print "GMM TST3: each key pressed on PC is shown on display." Print ' Lines connection of LCD (see on line help, GMM TST3 electric diagram and ' previous table for further informations) Config Lcdmode = Port ' Drive display through microcontroller's port lines Config Lcdbus = 4 ' Drive display with 4 bits Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portd.2 , Rs = Portd.3 Config Lcd = 20 * 2 ' LCD display with 20 columns and 2 rows Cls ' Clear LCD display and set position on first character Rowlcd = 1 ' Initialize current display position Collcd = 1 Do ' Begin endless loop Rxchr = Waitkey() ' Wait character reception and save it Print Chr(rxchr); ' Show received character on console Lcd Chr(rxchr) ' Show received character on LCD display Incr Collcd ' Update current display position If Collcd > Maxcol Then ' If current column is after the last one Collcd = 1 ' Set first display column Rowlcd = Rowlcd + 1 ' Set next display row If Rowlcd > Maxrow Then ' If current row is after the last one Rowlcd = 1 ' Set first display row End If Locate Rowlcd , Collcd ' Set cursor on current display position End If Loop ' End endless loop End '*************************** End of main program *******************************