' ********************************************************************** ' * File: uk_BAS51_047.BAS * ' * Version: 1.1 * ' * Date: 10.06.11 * ' * 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 047 of BASCOM 8051 course. ' Test and management program for Microwire EEPROM Microchip 93LC46A. ' It performs the foundamental operations on the component by using a software ' Microwire interface and by interacting with user 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 works only when the GMM 5115 is mounted on Z2 socket of GMM TST3!! ' ' Added instructions: None. ' ' 10/06/11: uk_BAS51_047.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 !!! ' ' 93LC46A GMM TST3 pin Z2 pin Signal Signal ' signal resource GMM TST3 GMM 5115 GMM 5115 uP ' CS CN4.1 32 26 P1.1 ADC1 T2EX P1.1 ' SK CN4.4 31 25 P1.2 ADC2 ECI P1.2 ' DI CN4.3 30 24 P1.3 ADC3 CEX0 P1.3 ' DO CN4.6 29 23 P1.4 ADC4 CEX1 P1.4 ' Vcc CN4.18 34 28 +5 Vdc Vcc ' GND CN4.17 20 14 GND 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. Pincs Alias P1.1 ' Bit with output signal connected to CS of EE Pinsk Alias P1.2 ' Bit with output signal connected to SK of EE Pindi Alias P1.3 ' Bit with output signal connected to DI of EE Pindo Alias P1.4 ' Bit with input signal connected to DO of EE 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 Hlpb As Byte ' General purpose help byte variable Dim Choice As Byte ' Selected operation Dim Mwnbit As Byte ' Bits number to comunicate on Microwire interface Dim Mwout As Word ' Data to send with Microwire interface Dim Mwin As Word ' Data received from Microwire interface Dim Addmw As Word ' Address to send with Microwire interface Dim Datmw As Byte ' Data to communicate on Microwire interface '************************ Subroutines declaration ****************************** Declare Sub Ask_key() ' Ask and wait a key pressure Declare Sub Ini_mw() ' Initialize lines used for the software Microwire interface Declare Sub Com_mw(mwout As Word , Mwin As Word , Mwnbit As Byte ) ' Comunicate on software Microwire interface Declare Sub Read_mwee() ' Read a byte from Microwire EE Declare Sub Write_mwee() ' Write a byte son Microwire EE Declare Sub Enaew_mwee() ' Enable erase and write on Microwire EE Declare Sub Disew_mwee() ' Disable erase and write on Microwire EE '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Call Ini_mw() ' Initialize lines used for software Microwire interface Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " 93LC46A Microwire EE management with GMM 5115 + GMM TST3" Print "Mount Mini Module on Z2 of GMM TST3, connect EE to CN4 as described in electric" Print " diagram." ' Please note that the variables dedicated to address and communication with ' Microwire device are declared with 16 bits Word type, in order to easily ' manage even EE with higher capacity Do ' Begin endless loop Print ' Shows menu with available operations Print "R -> Read location" Print "W -> Write location" Print "E -> Enable erase and write" Print "D -> Disable erase and write" Print "Perform the choice by pushing the associated key: "; Choice = Waitkey() ' Wait selection of operation to execute Printbin Choice ' Shows performed choice Print If Choice >= "a" Then ' If choice is lower case Choice = Choice And &HDF ' Convert it in upper case End If Print ' Separate menu from following visualizations Select Case Choice ' Check converted choice Case "R": ' Selected operation is read EE location Input "Addrress of location to read (0..128): " , Addmw Call Read_mwee() ' Read byte from Microwire EE Print "Read data= " ; Datmw Call Ask_key() ' Ask and wait a key pressure on console to allow results reading Case "W": ' Selected operation is write EE location Input "Addrress of location to write (0..128): " , Addmw Input "Data to write (0..255): " , Datmw Call Write_mwee() ' Write byte on Microwire EE Print "Write performed." Call Ask_key() ' Ask and wait a key pressure on console to allow results reading Case "E": ' Selected operation is enable erase and write operations Call Enaew_mwee() ' Enable erase and write operations on Microwire EE Print "Erase and write operations enabled." Call Ask_key() ' Ask and wait a key pressure on console to allow results reading Case "D": ' Selected operation is disable erase and write operations Call Disew_mwee() ' Enable erase and write operations on Microwire EE Print "Erase and write operations disabled." Call Ask_key() ' Ask and wait a key pressure on console to allow results reading Case Else: ' Selected operation is not valid Printbin &H07 ' Generate an advise BEL on console End Select Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Require and wait a key pressure on console ' Input: None ' Output: None Sub Ask_key() Print "Press a key to continue..."; Hlpb = Waitkey() Print End Sub ' Initialize signals and variables used for the Microwire interface managed by ' software ' Input: None ' Output: None Sub Ini_mw() Pindo = 1 ' Initialize P1.4=DO as digital input Pinsk = 0 ' Initialize P1.2=SK as digital output at low level Pindi = 0 ' Initialize P1.3=DI as digital output at low level Pincs = 0 ' Initialize P1.1=CS as digital output at low level End Sub ' Communicate on Microwire interface managed by software by sending and receiving ' the passed number of bits, up to 16 maximum. ' Input: Mwout = Data to send ' Mwnbit = number of bits to communicate ' Output: Mwin = Received data Sub Com_mw(mwout As Word , Mwin As Word , Mwnbit As Byte ) If Mwnbit < 16 Then ' If not all the data bits must be sent Hlpb = 16 - Mwnbit ' Obtain number of bits not to send Shift Mwout , Left , Hlpb ' Discard bits not to send End If For Hlpb = 1 To Mwnbit ' Loop repeated for all the bits to communicate Shift Mwin , Left , 1 ' Update current bit of received data Pindi = Mwout.15 ' Set current bit status of data to send on DI signal Pinsk = 1 ' SK signal at high level Mwin.0 = Pindo ' Get current bit from DO signal and save it on received data Pinsk = 0 ' SK signal at high level Shift Mwout , Left , 1 ' Update current bit of data to send Next Hlpb End Sub ' Read a byte from 93LC46A Microwire EE. ' Input: Addmw = EE location address to read ' Output: Datmw = data read from EE Sub Read_mwee() Pincs = 1 ' CS signal at high level Call Com_mw(&H06 , Mwin , 3) ' Send 3 bits of READ command to Microwire EE Call Com_mw(addmw , Mwin , 7) ' Send 7 bits of address to Microwire EE Call Com_mw(&H00 , Mwin , 8) ' Get 8 bits of data to read from Microwire EE Datmw = Low(mwin) Pincs = 0 ' CS signal at low level End Sub ' Write a byte on 93LC46A Microwire EE. ' Input: Addmw = EE location address to write ' Datmw = data to write on EE ' Output: None Sub Write_mwee() Pincs = 1 ' CS signal at high level Call Com_mw(&H05 , Mwin , 3) ' Send 3 bits of WRITE command to Microwire EE Call Com_mw(addmw , Mwin , 7) ' Send 7 bits of address to Microwire EE Mwout = Datmw ' Cast data to write (8 bits) to parameter (16 bits) Call Com_mw(mwout , Mwin , 8) ' Send 8 bits of data to write to Microwire EE Pincs = 0 ' CS signal at low level Waitms 10 ' Wait end of write time for Microwire EE (6 msec on data sheet) End Sub ' Enable erase and write operations on 93LC46A Microwire EE ' Input: None ' Output: None Sub Enaew_mwee() Pincs = 1 ' CS signal at high level Call Com_mw(&H04 , Mwin , 3) ' Send 3 bits of EWEN command to Microwire EE Call Com_mw(&H60 , Mwin , 7) ' Complete command by sending 7 bits of address to Microwire EE Pincs = 0 ' CS signal at low level End Sub ' Disable erase and write operations on 93LC46A Microwire EE ' Input: None ' Output: None Sub Disew_mwee() Pincs = 1 ' CS signal at high level Call Com_mw(&H04 , Mwin , 3) ' Send 3 bits of EWEN command to Microwire EE Call Com_mw(&H00 , Mwin , 7) ' Complete command by sending 7 bits of address to Microwire EE Pincs = 0 ' CS signal at low level End Sub '******************* End of subroutines used by program ************************