' ********************************************************************** ' * File: uk_BAS51_056.BAS * ' * Version: 1.1 * ' * Date: 18.01.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 056 of BASCOM 8051 course. ' Program for 1-WIRE BUS management, that identify and shows the information ' about the connected devices. ' The program uses a 1-WIRE interface with three wires, one (DQ) for the data ' and two (GND, Vdd) for the power supply, but it can operate even with devices ' provided of only two wires. From electric point of view, this signals have ' been freely selected as listed in following definitions and they can be ' easily re-assigned, as described in BASCOM on line help. ' The program count the possible devices connected to 1-WIRE BUS and for each ' one of the identified it shows the information that feature and describe it ' or, in other words, its ROM code. This work is performed only by using the ' ROM Commands, always available on each device with 1-WIRE protocol. Further ' information about ROM Commands and ROM code can be found into data sheet of ' the used devices, or on the 1-WIRE documents from DALLAS. ' 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: CONFIG 1WIRE, 1WRESET, 1WIRECOUNT, 1WSEARCHFIRST, 1WSEARCHNEXT. ' ' 18/01/12: uk_BAS51_056.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!!! ' ' 1-WIRE GMM TST3 pin Z2 pin Signal Used uP ' signal resource GMM TST3 GMM AM08 GMM AM08 signal ' DQ CN4.16 24 18 P3.3 INT1 P3.3 ' Vdd CN4.18 34 28 +5 Vdc - ' GND CN4.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. Pinrx Alias P3.0 ' Signal connected to GMM 5115 RxD Pintx Alias P3.1 ' Signal connected to GMM 5115 TxD '************************* Constants declaration ******************************* '************************* Variables declaration ******************************* Dim Ndev_ow As Word ' Devices number on 1-WIRE BUS Dim Romcode_ow(8) As Byte ' Array for 8 bytes of 1-WIRE ROM code Dim Hlpw As Word ' General purpose word help variable Dim Key As Byte ' Key pressed on console '************************ Subroutines declaration ****************************** '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " 1-WIRE devices management with GMM 5115 + GMM TST3" Print "Mount Mini Module on Z2 of GMM TST3, connect 1-WIRE line and devices" Print "as described in electric diagram." Print "The program identifies and shows the information about connected devices," Print "on console." Config 1wire = P3.3 ' Initialize 1-WIRE interface Do ' Begin endless loop Print Print "Press a key to start 1-WIRE BUS scanning..."; Key = Waitkey() ' Wait key pressed on console Print Ndev_ow = 1wirecount() ' Obtain number of connected 1-WIRE devices Print Ndev_ow ; " 1-WIRE device/s connected" ' Show number of connected 1-WIRE devices on console If Ndev_ow > 0 Then ' If at least an 1-WIRE device connected Print " N. Family Serial Control" Print "device code number CRC" For Hlpw = 1 To Ndev_ow ' Loop that shows devices information If Hlpw = 1 Then Romcode_ow(1) = 1wsearchfirst() ' Obtain ROM code of first 1-WIRE device Else Romcode_ow(1) = 1wsearchnext() ' Obtain ROM code of other 1-WIRE devices End If Print " " ; Hlpw ; ' Show device number in decimal format Printhex " " ; Romcode_ow(1); ' Show "family code" field in hexadecimal format Printhex " " ; Romcode_ow(7); ' Show "unique serial number" field in hexadecimal format Printhex Romcode_ow(6); Printhex Romcode_ow(5); Printhex Romcode_ow(4); Printhex Romcode_ow(3); Printhex Romcode_ow(2); Printhex " " ; Romcode_ow(8) ' Show "CRC" field in hexadecimal format Next Hlpw End If Loop ' End endless loop End '*************************** End of main program *******************************