' ********************************************************************** ' * File: uk_BAS51_071.BAS * ' * Version: 1.1 * ' * Date: 13.10.12 * ' * 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 071 of BASCOM 8051 course. ' Optocoupled inputs management: the program acquires the status of 8 optocoupled ' digital inputs and it shows them on serial console. ' The 8 inputs are acquired through as many as I/O lines of microcontroller, ' connected to CN4 connector of GMM TST3, as described in electric diagram. ' The galavnic insulation circuit connected to these lines allows to acquire ' sensors (switches, proximity, photocells, etc.) of PNP type. ' On the console are continuously displayed the status of the Optocoupled inputs, ' that is equal to the status of external inputs (Px on the diagram), in ON or ' OFF format. ' The program describes its functionalities and uses 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 works only when the GMM 5115 is mounted on Z2 socket of GMM TST3!! ' ' Added instructions: None. ' ' 13/10/12: uk_BAS51_071.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 table. ' !!! 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!!! ' ' External GMM TST3 pin Z2 pin Signal Used uP ' signal resource GMM TST3 GMM 5115 GMM 5115 signal ' Opto-In 1 CN4.1 32 26 P1.1 ADC1 T2EX P1.1 ' Opto-In 2 CN4.4 31 25 P1.2 ADC2 ECI P1.2 ' Opto-In 3 CN4.15 25 19 P3.2 INT0 P3.2 ' Opto-In 4 CN4.16 24 18 P3.3 INT1 P3.3 ' Opto-In 5 CN4.13 23 17 P3.4 T0 P3.4 ' Opto-In 6 CN4.14 22 16 P3.5 T1 P3.5 ' Opto-In 7 CN4.11 21 15 P3.6 P3.6 ' Opto-In 8 CN4.12 19 13 P3.7 P3.7 ' GND CN4.17 20 14 GND - ' +5 Vdc CN4.18 34 28 +5 Vdc - ' ' 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. Pinopto1 Alias P1.1 ' Signal connected to Optocoupled input 1 Pinopto2 Alias P1.2 ' Signal connected to Optocoupled input 2 Pinopto3 Alias P3.2 ' Signal connected to Optocoupled input 3 Pinopto4 Alias P3.3 ' Signal connected to Optocoupled input 4 Pinopto5 Alias P3.4 ' Signal connected to Optocoupled input 5 Pinopto6 Alias P3.5 ' Signal connected to Optocoupled input 6 Pinopto7 Alias P3.6 ' Signal connected to Optocoupled input 7 Pinopto8 Alias P3.7 ' Signal connected to Optocoupled input 8 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 ' Carriage return ASCII code '************************* Variables declaration ******************************* Dim Inopto As Bit ' Variable with status of Optocoupled input '************************ Subroutines declaration **************************** Declare Sub Show_optoin() ' Show Optocoupled input on console '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Pinopto1 = 1 ' Initialize signal connected to Opto-In 1 as digital input Pinopto2 = 1 ' Initialize signal connected to Opto-In 2 as digital input Pinopto3 = 1 ' Initialize signal connected to Opto-In 3 as digital input Pinopto4 = 1 ' Initialize signal connected to Opto-In 4 as digital input Pinopto5 = 1 ' Initialize signal connected to Opto-In 5 as digital input Pinopto6 = 1 ' Initialize signal connected to Opto-In 6 as digital input Pinopto7 = 1 ' Initialize signal connected to Opto-In 7 as digital input Pinopto8 = 1 ' Initialize signal connected to Opto-In 8 as digital input Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " Acquire 8 Optocoupled inputs" Print "Mount Mini Module on Z2 of GMM TST3, connect circuit with Optocoupled" Print "buffered inputs to CN4, as described in electric diagram." Print "The status of the inputs is continuosly displayed.." Print " Opto-In 1 In 2 In 3 In 4 In 5 In 6 In 7 In 8" Do ' Begin endless loop Print " "; ' Align visualizations ' Acquire and show status of input Opto-In 1 Inopto = Pinopto1 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 2 Inopto = Pinopto2 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 3 Inopto = Pinopto3 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 4 Inopto = Pinopto4 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 5 Inopto = Pinopto5 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 6 Inopto = Pinopto6 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 7 Inopto = Pinopto7 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console ' Acquire and show status of input Opto-In 8 Inopto = Pinopto8 ' Acquire status of Optocoupled input Call Show_optoin() ' Show status of Optocoupled input on console Printbin Cret ' Mantain visualization on the same row Waitms 50 ' Delay between acquisitions Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Show the status of an Optocoupled input, on the console ' Input: Inopto = Status acquired from Optocoupled input ' Output: None Sub Show_optoin() Inopto = Not Inopto ' Convert status in positive logic If Inopto = 1 Then ' Show status of Optocoupled input on console Print " ON "; Else Print " OFF "; End If End Sub '******************* End of subroutines used by program ************************