' ********************************************************************** ' * File: uk_BAS51_022.BAS * ' * Version: 1.1 * ' * Date: 06.08.10 * ' * Development Tools: Bascom 8051 COMP.,IDE 2.0.14.0 + FLIP 2.4.6 * ' * Cards: GMM 5115 + 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 022 of BASCOM 8051 course. ' It manages an alphanumeric display with 2 x 20 characters. ' It manages an alphanumeric display with 2 x 20 characters. ' The program saves/load messages long 40 characters on/from EEPROM and it ' shows them on 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 8051. ' All the functionalities are established through a serial console provided of ' monitor and keyboard 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 8051 (see IDE Configuration). ' The program works only when the GMM 5115 is mounted on Z1 socket of GMM TST3!! ' ' Added instructions: None. ' ' 06/08/10: uk_BAS51_022.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 89C5115.DAT file into the directory where the ' BASCOM 8051 is installed and copy it if not present. ' 2) Into the window "Options | Compiler | Misc" set: ' Register File = 89C5115.DAT ' Byte End(Hex) = A0 ' Size warning = selected at 16384 (=4000H) ' 3) Into the window "Options | Compiler | LCD" set: ' DB7 = P3.7 ' DB6 = P3.6 ' DB5 = P3.5 ' DB4 = P3.4 ' Enable = P3.2 ' RS = P3.3 ' Make upper 3 bits high in LCD designer = not selected ' 4) Into the window "Options | Communication" set: ' COM port = the PC line connected to GMM 5115, through GMM TST3 ' Baudrate = 19200 ' Parity = None ' Databits = 8 ' Stopbit = 1 ' Handshake = None ' Emulation = TTY ' Font = Terminal, Normal, 12 points, white colour ' Backcolor = Navy ' Run emulator modal = not selected ' 5) At the end of compilation, after the code is programmed on GMM 5115, select ' RUN mode and open the terminal emulation window of BASCOM 8051 with the ' option: Tools | Terminal emulator (Ctrl+T) and then reset or powen on the ' Mini Module. '************************* Compiler directives ********************************* $regfile "89C5115.DAT" ' Definitions file for used microcontroller $romstart = &H0 ' Code start address on FLASH $iramstart = &H0 ' Data start address on internal RAM $ramstart = &H0 ' Data start address on external RAM $ramsize = &H100 ' External RAM size $crystal = 14745600 ' Microcontroller crystal frequency $large ' Code size > 2K $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 following jumpers must be properly configured: ' 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 5115 GMM 5115 signal ' LCD.DB4 23 17 P3.4 T0 P3.4 ' LCD.DB5 22 16 P3.5 T1 P3.5 ' LCD.DB6 21 15 P3.6 P3.6 ' LCD.DB7 19 13 P3.7 P3.7 ' LCD.E 25 19 P3.2 INT0 P3.2 ' LCD.RS 24 18 P3.3 INT1 P3.3 ' ' Signal pin COMx pin CN5 pin Z1 pin Signal Used up ' PC DB9 GMM TST3 GMM TST3 GMM 5115 GMM 5115 signal ' TX 3 3 9 3 RxD RS232 P3.0 ' RX 2 2 10 4 TxD RS232 P3.1 ' 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 P3.0 ' Signal connected to GMM 5115 RxD Pintx Alias P3.1 ' Signal connected to GMM 5115 TxD '************************* Constants declaration ******************************* Const Ee_timeout = 5000 ' Timeout for waiting end of EEPROM write Const Max_msg_ee = 5 ' Maximum number of messages on EEPROM Const Cod_msg_ee = &H5A ' Code that denote message saved on EEPROM Const Maxcol = 20 ' Maximum number of display column Const Maxrow = 2 ' Maximum number of display rows '************************* Variables declaration ******************************* Dim Choice As Byte ' Selected peration Dim Disrow As Byte ' Row of current cursor display position Dim Discol As Byte ' Column of current cursor display position Dim Disstr As String * 20 ' String with message to show on display Dim Msgstr As String * 40 ' String with message to generate Dim Lstr As Byte ' String with message length Dim Pstr As Byte ' Pointer to string with message Dim Chrstr As String * 1 ' Character of the message to generate Dim Datee As Byte ' Data to write on or read from EEPROM Dim Addee As Word ' EEPROM location address to write or read Dim Hlpb As Byte ' General purpose help variable Dim Tout As Word ' Counter for security timeout Dim Nmsg As Byte ' Message number to read/write from/on EEPROM Dim Msgsaved As Boolean ' Message saved on EEPROM flag '************************ Subroutines declaration ****************************** Declare Sub Rd_ee() ' Read a byte from internal EEPROM of uP Declare Sub Wr_ee() ' Write a byte on internal EEPROM of uP Declare Sub Read_msg_ee() ' Read a message from EEPROM Declare Sub Write_msg_ee() ' Write a message on EEPROM Declare Sub Show_msg_ee() ' Show the messages saved on EEPROM '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' 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 saves/loads messages long 40 characters on/from EEPROM, and it" Print "shows them on LCD display of GMM TST3: thanks to a menu displayed on PC you" Print "can perform the selected operations." Print ' Lines connection of LCD (see on line help, GMM TST3 electric diagram and ' previous table for further informations) Config Lcdpin = Pin , Db4 = P3.4 , Db5 = P3.5 , Db6 = P3.6 , Db7 = P3.7 , E = P3.2 , Rs = P3.3 Config Lcd = 20 * 2 ' LCD display with 20 columns and 2 rows Lcdinit ' Ensures LCD display initialization Cls ' Clear LCD display and set position on first character Do ' Begin endless loop Print ' Show menu with available operations on console Print "S -> Save message on EEPROM" Print "L -> Load message from EEPROM" Print "D -> Show message on display" Print "Perform the choice by typing the pressed key: "; Choice = Waitkey() ' Wait selection of operation to execute Printbin Choice ' Show performed selection Print If Choice >= "a" Then ' If selection is lower case Choice = Choice And &HDF ' Convert selection in upper case End If Select Case Choice ' Check converted selection Case "S": ' Selected operation is: save a message on EEPROM Call Show_msg_ee() ' Show the messages saved on EEPROM Input "Message number to save: " , Nmsg ' Ask and gest the message number to save Print "Insert message to save on EEPROM (40 characters max.): " Input Msgstr ' Get message to save on EEPROM Call Write_msg_ee() ' Save message on EEPROM Case "L": ' Selected operation is: load a message from EEPROM Call Show_msg_ee() ' Show the messages saved on EEPROM Input "Message number to read: " , Nmsg ' Ask and gest the message number to read Call Read_msg_ee() ' Read message from EEPROM Case "D": ' Selected operation is: show message on display Cls ' Erase LCD display and place cursor on first character Disstr = Left(msgstr , 20) ' Obtain first 20 characters of string Locate 1 , 1 ' Show first 20 characters on first row of LCD display Lcd Disstr Lstr = Len(msgstr) ' Obtain string length If Lstr > Maxcol Then ' If string is longer than first row of display Disstr = Mid(msgstr , 21 , 20) ' Obtain second 20 characters of string Locate 2 , 1 ' Show second 20 characters on second row of LCD display Lcd Disstr End If End Select Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Read a byte from internal EEPROM of uP. ' Input: Addee = variable with EEPROM location address to read ' Output: Datee = variable with data read from EEPROM Sub Rd_ee() Auxr = &H2E ' Deselect ERAM of uP, extend MOVX duration Disable Interrupts ' General interrupts disable Eecon = &H02 ' Select EEPROM of uP, allocated on external data area Datee = Inp(addee) ' Read byte from EEPROM Eecon = &H00 ' Deselect EEPROM of uP Enable Interrupts ' General interrupts re-enable Auxr = &H0C ' Selects ERAM of uP son external data area End Sub ' Write a byte on internal EEPROM of uP, with security timeout ' Input: Addee = variable with EEPROM location address to write ' Datee = variable with data read from EEPROM ' Output: None ' It uses global variables Hlpb, Tout Sub Wr_ee() Auxr = &H2E ' Deselect ERAM of uP, extend MOVX duration Disable Interrupts ' General interrupts disable Eecon = &H02 ' Select EEPROM of uP, allocated on external data area Out Addee , Datee ' Write byte on EEPROM column latch Eecon = &H52 ' Start write operation on internal EEPROM Eecon = &HA2 Eecon = &H00 ' Deselect EEPROM of uP Enable Interrupts ' General interrupts re-enable Auxr = &H0C ' Selects ERAM of uP son external data area Tout = 0 ' Reset timeout counter Do ' Cycle that wait write end with timeout Incr Tout Hlpb = Eecon ' Read and mask EEPROM busy bit Hlpb = Hlpb And &H01 Loop Until Hlpb = 0 Or Tout >= Ee_timeout ' Exit when EEPROM not busy or timeout elapsed End Sub ' Each message occupies 42 bytes of EEPROM: the first dedicated to a message ' saved indicator, the second dedicated to message length and the following ' 40 bytes dedicated to the maximum 40 characters of the message. ' ' Read a message from EEPROM, by checking if it has been previously saved. ' Input: Nmsg = variable with message number to read ' Output: Msgstr = string variable with read message ' Msgsaved = flag for message saved and thus read Sub Read_msg_ee() Addee = Nmsg * 42 ' Calculate start address of message saved on EEPROM Call Rd_ee() ' Get message saved indicator from EEPROM If Datee = Cod_msg_ee Then ' If message is already saved on EEPROM Incr Addee ' Increase the EEPROM read address Call Rd_ee() ' Get message length from EEPROM Lstr = Datee Msgstr = Space(lstr) ' Arrange string long as message to read For Pstr = 1 To Lstr ' Cycle repeated for characters of message Incr Addee ' Increase the EEPROM read address Call Rd_ee() ' Get ASCII code of current character from EEPROM Chrstr = Chr(datee) ' Obtain character from Ascii code Mid(msgstr , Pstr , 1) = Chrstr ' Save current character of message Next Pstr Msgsaved = 1 ' Message was saved on EEPROM and it has been read Else Msgsaved = 0 ' Message was not saved on EEPROM and it hasn't been read End If End Sub ' Write a message from EEPROM, by adding proper message saved indicator ' Input: Nmsg = variable with message number to write ' Msgstr = string variable with message to write ' Output: None Sub Write_msg_ee() Addee = Nmsg * 42 ' Calculate start address of message saved on EEPROM Datee = Cod_msg_ee ' Write message saved indicator on EEPROM Call Wr_ee() Lstr = Len(msgstr) ' Obtain length of string with message Datee = Lstr ' Write message length on EEPROM Incr Addee ' Increase EEPROM write address Call Wr_ee() For Pstr = 1 To Lstr ' Cycle repeated for characters of message Chrstr = Mid(msgstr , Pstr , 1) ' Get current character of message Datee = Asc(chrstr) ' Obtain ASCII code of current character Incr Addee ' Increase EEPROM write address Call Wr_ee() ' Write current character ASCII code on EEPROM Next Pstr End Sub ' Show on serial console the list of message currently written=saved on EEPROM ' Input: None ' Output: None Sub Show_msg_ee() Print "Message currently saved on EEPROM:" ' Show list head description For Nmsg = 1 To Max_msg_ee Print Nmsg ; " = "; ' Show message number of the list Call Read_msg_ee() ' Read current message of EEPROM list If Msgsaved = 1 Then ' If message saved on EEPROM and read Print Msgstr ' Show read message of the list Else ' Message not saved and not read Print ' Show empty message of the list End If Next Nmsg End Sub '******************* End of subroutines used by program ************************