' ********************************************************************** ' * File: uk_BAS51_072.BAS * ' * Version: 1.1 * ' * Date: 11.08.13 * ' * 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 072 of BASCOM 8051 course. ' It prints a string, typed from console, on a parallel printer provided of ' CENTRONICS interface. ' First of all the string is acquired and then it is sent with additional codes ' CR (Carriage Return) and LF (Line Feed) that ensure the correct printing. ' The CENTRONICS interface of the printer must be connected to I/O lines of ' Mini Module; this connection must be performed with the relationship ' described below in the definitions, and it can be easily performed with ' the card GMM TST3 and DEB 01. In details the program requires the following ' connections: ' - GMM 5115 mounted on socket Z2 of GMM TST3; ' - CN5 of GMM TST3 connected to serial line of console; ' - CN4 of GMM TST3 connected to CN14 of DEB 01, through a 20 wires flat cable; ' - CN13 of DEB 01 connected to CENTRONICS interface of the printer, by using ' a proper cable (i.e. those used to connect parallel printer to PC). ' The CENTRONICS interface has many signals and this program initializes all ' them but then it uses only a small subset reduced to /STROBE and BUSY. ' The program describes its functionalities and ask for the string to print ' on a serial console provided of monitor and keyboard 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 uses some names in order to identify the used signals, that are ' those already used in electric diagrams and technical manuals of GMM TST3 and ' DEB 01 cards!! ' The program works only when the GMM 5115 is mounted on Z2 socket of GMM TST3!! ' ' Added instructions: None. ' ' 11/08/13: uk_BAS51_072.BAS - Ver 1.1 - By G.A. ' First version. ' ' '**************************** IDE Configurations ******************************* ' NOTE: in order to correctly 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 | 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 ' 4) 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 tables. ' !!! Note: On GMM TST3 the jumpers must be set in following positions: ' 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!!! ' ' GMM TST3 'CENTRONICS CENTRONICS -DEB 01 pin Z2 pin Signal Used uP ' signal DB 25 resource GMM TST3 GMM 5115 GMM 5115 signal ' D1 2 CN4-CN14.2 33 27 P1.0 DSW1.1 T2 DL1 P1.0 ' D2 3 CN4-CN14.1 32 26 P1.1 ADC1 T2EX P1.1 ' D3 4 CN4-CN14.4 31 25 P1.2 ADC2 ECI P1.2 ' D4 5 CN4-CN14.3 30 24 P1.3 ADC3 CEX0 P1.3 ' D5 6 CN4-CN14.6 29 23 P1.4 ADC4 CEX1 P1.4 ' D6 7 CN4-CN14.5 28 22 P1.5 ADC5 P1.5 ' D7 8 CN4-CN14.8 27 21 P1.6 ADC6 P1.6 ' D8 9 CN4-CN14.7 26 20 P1.7 ADC7 P1.7 ' /STROBE 1 CN4-CN14.15 25 19 P3.2 INT0 P3.2 ' /AUTOLF 14 CN4-CN14.16 24 18 P3.3 INT1 P3.3 ' /RESET 16 CN4-CN14.13 23 17 P3.4 T0 P3.4 ' MODE 17 CN4-CN14.14 22 16 P3.5 T1 P3.5 ' PE 12 CN4-CN14.11 21 15 P3.6 P3.6 ' /ACK 10 CN4-CN14.12 19 13 P3.7 P3.7 ' SELECT 13 CN4-CN14.9 14 8 P4.0 P4.0 ' BUSY 11 CN4-CN14.10 15 9 P4.1 P4.1 ' GND 19,20,..,29 CN4-CN14.17 20 14 GND -- ' ' 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 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. Pinstb Alias P3.2 ' Signal connected to /STROBE CENTRONICS Pinmode Alias P3.5 ' Signal connected to MODE CENTRONICS Pinack Alias P3.7 ' Signal connected to /ACK CENTRONICS Pinpempty Alias P3.6 ' Signal connected to PE CENTRONICS Pinselect Alias P4.0 ' Signal connected to SELECT CENTRONICS Pinbusy Alias P4.1 ' Signal connected to BUSY CENTRONICS Pinrx Alias P3.0 ' Signal connected to GMM 5115 RxD Pintx Alias P3.1 ' Signal connected to GMM 5115 TxD '************************* Constants declaration ******************************* Const Cret = 13 ' ASCII code for carriage return Const Lf = 10 ' ASCII code for new line '************************* Variables declaration ******************************* Dim Oldbusy As Bit ' Previous printer busy status Dim Toutprn As Word ' Printer timeout counter Dim Del As Byte ' Variable for delay generation Dim Chrtoprn As Byte ' Character to print Dim Strtoprn As String * 80 ' Variable with string to print Dim Chrstr As String * 1 ' One character string to print Dim Lstr As Byte ' Length of the string to print Dim Pstr As Byte ' Pointer to string to print Dim Hlpf As Bit ' General purpose bit variable '************************ Subroutines declaration ****************************** Declare Sub Ini_prn() ' Initialize lines for CENTRONICS printer management Declare Sub Prn_chr() ' Print a character with CENTRONICS parallel printer Declare Sub Prn_str() ' Print a string with CENTRONICS parallel printer '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Call Ini_prn() ' Initialize lines for CENTRONICS printer management Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " CENTRONICS parallel printer management" Print "Mount Mini Module on Z2 of GMM TST3, connect GMM TST3: CN4 to DEB 01:CN14" Print "(20 wires flat cable) and DEB 01:CN13 to CENTRONICS interface of the printer." Print "The strings inserted on the console are sent to the printer, through the" Print "CENTRONICS interface, that print them on a row." Do ' Begin endless loop Print "Insert string to print (max. 80 characters): " Input Strtoprn ' Acquire and save string to print Call Prn_str() ' Print string Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Initialize resource, variable and peripherals used for the management of a ' parallel printer with CENTRONICS interface. ' Input: None ' Output: None Sub Ini_prn() Adcf = &H00 ' Set signals for printer as digital I/O P1 = &HFF ' Initialize signals connected to Dx lines of the ' CENTRONICS printer as digital output at high level = disabled Pinstb = 1 ' Initialize signal connected to /STROBE line of the ' CENTRONICS printer as digital output at high level = disabled Pinmode = 1 ' Initialize signal connected to MODE line of the ' CENTRONICS printer as digital output at high level = enabled Pinack = 1 ' Initialize signal connected to /ACK line of the Hlpf = Pinack ' CENTRONICS printer as digital input Pinpempty = 1 ' Initialize signal connected to PE line of the Hlpf = Pinpempty ' CENTRONICS printer as digital input Pinselect = 1 ' Initialize signal connected to SELECT line of the Hlpf = Pinselect ' CENTRONICS printer as digital input Pinbusy = 1 ' Initialize signal connected to BUSY of the Hlpf = Pinbusy ' CENTRONICS printer as digital input Oldbusy = 0 ' Previous printer status not busy End Sub ' Print one character through the parallel printer with CENTRONICS interface, ' by using only two control signals: /STROBE and BUSY. ' Input: chrtoprn = character to print ' Output: None Sub Prn_chr() If Pinbusy = 0 Or Oldbusy = 0 Then ' If printer not busy or previously not busy Toutprn = 0 ' Reset printer timeout counter While Pinbusy = 1 And Toutprn < 5000 ' Wait printer ready for a maximum time of 5 seconds Waitms 1 ' 1 msec delay Incr Toutprn ' Increase printer timeout counter Wend If Pinbusy = 0 Then ' If printer ready P1 = Chrtoprn ' Print character: set Dx lines For Del = 1 To 40 ' About 40 usec delay Next Del ' Generates negative pulse on /STROBE signal in order to activate it and let ' the printer accept the data to print Pinstb = 0 ' /STROBE at low level For Del = 1 To 20 ' About 20 usec delay Next Del Pinstb = 1 ' /STROBE at high level For Del = 1 To 80 ' About 80 usec delay Next Del Oldbusy = 0 ' Set printer previously not busy Else Oldbusy = 1 ' Set printer previously busy End If Else ' Printer not ready and previously busy ' In this condition the subroutine exits without printing the character. The user can add here ' the management of not ready printer End If End Sub ' Send a string to parallel printer with CENTRONICS interface and it adds the ' final characters CR and LF that ensure the immediate printing od the same string. ' Input: strtoprn = variable with string to print ' Output: None Sub Prn_str() Lstr = Len(strtoprn) ' Obtain length of string to print For Pstr = 1 To Lstr ' Loop repeated for all string characters Chrstr = Mid(strtoprn , Pstr , 1) ' Get current character of the string Chrtoprn = Asc(chrstr) ' Obtain ASCII code of current character Call Prn_chr() ' Print current character Next Pstr Chrtoprn = Cret ' Print Carriage Return Call Prn_chr() Chrtoprn = Lf ' Print Line Feed Call Prn_chr() End Sub '******************* End of subroutines used by program ************************