' ********************************************************************** ' * File: uk_BAS51_038.BAS * ' * Version: 1.1 * ' * Date: 10.01.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 038 of BASCOM 8051 course. ' Reflexes test. ' The program pre-notice the user with two beeps, then it activates one of ' the two LEDs of GMM TST3 (L2,L3) after a randomic delay time and it waits ' the pressure of corresponding button (T1,T2), by measuring the time elapsed ' between LED deactivation and button pressure, through TIMER1. A third audible ' beep indicates the button pressure or a 2 seconds maximum timeout. Finally ' it is shown the test result (measured time) on the console. ' The program describe 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 Z1 socket of GMM TST3!! ' Inside the program the terms that identify the used signals refers to electric ' diagram and technical manual of GMM TST3!! ' ' Added instructions: Rnd, Fusing. ' ' 10/01/11: uk_BAS51_038.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 following jumpers must be properly configured: ' J1 in 2-3 ; J2 in 2-3 ; J3 in 1-2 ; J8 in 2-3 !!! ' ' GMM TST3 pin Z2 pin Signal Used uP ' resource GMM TST3 GMM 5115 GMM 5115 signal ' LED L2,Button T1 12 6 P2.1 P2.1 ' LED L3.Button T2 13 7 P2.0 P2.0 ' Buzzer BZ1 15 9 P4.1 P4.1 ' ' 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. Pinl2 Alias P2.1 ' Signal connected to red LED L2 Pint1 Alias P2.1 ' Signal connected to red button T1 Pinl3 Alias P2.0 ' Signal connected to green LED L3 Pint2 Alias P2.0 ' Signal connected to green button T2 Pinbz1 Alias P4.1 ' Signal connected to buzzer BZ1 Pinrx Alias P3.0 ' Signal connected to GMM 5115 RxD Pintx Alias P3.1 ' Signal connected to GMM 5115 TxD '************************* Constants declaration ******************************* Const Tmrper = 1000 /(14745600 / 12) ' Counting period of TIMER0 in msec '************************* Variables declaration ******************************* Dim T1stat As Bit ' Boolean variable with red button T1 status Dim T2stat As Bit ' Boolean variable with green button T2 status Dim Pressok As Bit ' Boolean variable with correct button pressure Dim Dtbeep As Word ' Beep duration generated by buzzer Dim Deldt As Word ' Random value for delayed LED activation Dim Dtpressl As Byte ' Passed time up to button pressure: byte L Dim Dtpressm As Byte ' Passed time up to button pressure: byte M Dim Dtpressh As Byte ' Passed time up to button pressure: byte H Dim Dtpress As Long ' Passed time up to button pressure: byte H,M,L Dim Dttime As Single ' Passed time up to button pressure in msec Dim Dtstr As String * 10 ' String with formatted passed time Dim Hlpl As Long ' General purpose long help variable '************************ Subroutines declaration ****************************** Declare Sub Beep(dtbeep As Word) ' Generate beep with GMM TST3 buzzer '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Pinl2 = 1 ' Initialize signal connected to L2 as digital output at high level Pinl3 = 1 ' Initialize signal connected to L3 as digital output at high level Pinbz1 = 1 ' Initialize signal connected to BZ1 as digital output at high level Print ' Separate from previous visualization by showing an empty new line Print Print " Test reflexes with LEDs and buttons of GMM TST3" Print "Mount Mini Module on Z1 of GMM TST3." Print "Tests under execution..." Config Timer0 = Timer , Gate = Internal , Mode = 1 ' TIMER0 as 16 bit timer with internal activation Do ' Begin endless loop Print "Test started" ' Generate two beep with GMM TST3 buzzer Call Beep(200) ' Generate first long beep (200 msec) Waitms 500 ' Delay between two beeps Call Beep(100) ' Generate second short beep (100 msec) ' Perform random delay up to 5 sec Deldt = Rnd(5000) ' Obtain randomic number from 0 to 5000 Waitmse Deldt ' Activate randomly one of the two LEDs L2,L3 for 100 msec Deldt = Deldt And &H0408 ' Mantains some bits of randomic delay If Deldt = 0 Then ' Determine which LED must be enabled Pinl2 = 0 ' Enable red L2 Else Pinl3 = 0 ' Enable green L3 End If Waitms 100 ' Mantain LED enabled for 100 msec Pinl2 = 1 ' Disable LEDs and set lines as inputs Pinl3 = 1 ' Enable TIMER0 in order to measure the time passed up to pressure of T1,T2 ' button or timeout of about 2 secs. The TIMER0 is updated with a frequency ' equal to Clock frequency/12 and its 16 bits overflow happens about every ' 53 msec = 65536*(1/(14745600/12)). ' For this reason in 2 secs occour 38 overflows = 2/0.053. Load Timer0 , 0 ' Reset TIMER0 Start Timer0 ' Enable TIMER0 Dtpressh = 0 ' Clear byte H of passed time up to button pressure Dtpressm = 0 ' Clear byte M of passed time up to button pressure Do If Th0 < Dtpressm Then ' If occured overflow on TIMER0 Incr Dtpressh ' Increase byte H of passed time End If Dtpressl = Tl0 ' Acquire current TIMER0 value and save it into byte L Dtpressm = Th0 ' and M of passed time Loop Until Pint1 = 0 Or Pint2 = 0 Or Dtpressh > 38 ' Wait pressure of T1,T2 or 2 secs timeout Stop Timer0 ' Stop TIMER0 T1stat = Pint1 ' Save red button T1 status T2stat = Pint2 ' Save green button T2 status ' Obtain passed time in msec Hlpl = Dtpressh ' Shift byte H of passed time 16 bits to the left Shift Hlpl , Left , 16 Dtpress = Hlpl ' Save shifted byte H Hlpl = Dtpressm ' Shift byte M of passed time 8 bits to the left Shift Hlpl , Left , 8 Dtpress = Dtpress Or Hlpl ' Save shifted byte M Hlpl = Dtpressl ' Save byte L without shift Dtpress = Dtpress Or Hlpl ' Dttime contain passed time counter with 3 bytes H,M,L Dttime = Dtpress * Tmrper ' Obtain passed time in msec Dtstr = Fusing(dttime , 0000.###) ' Mantains significant digits of passed time ' Show on console the result of the just performed reflexes test Pressok = 0 ' Wrong button pressure If Deldt = 0 Then ' Check wich LED has been turned on Print "Activated red L2, "; If T1stat = 0 Then ' If red T1 pressed Print "pressed red T1 in " ; Dtstr ; " msec: OK"; Pressok = 1 ' Correct button pressure Else If T2stat = 0 Then ' If green T2 pressed Print "pressed green T2 in " ; Dtstr ; " msec: ERROR"; Else Print "no button pressed: ERROR"; End If End If Else Print "Activated green L3, "; If T2stat = 0 Then ' If green T2 pressed Print "pressed green T2 in " ; Dtstr ; " msec: OK"; Pressok = 1 ' Correct button pressure Else If T1stat = 0 Then ' If red T1 pressed Print "pressed red T1 in " ; Dtstr ; " msec: ERROR"; Else Print "no button pressed: ERROR"; End If End If End If Print If Pressok = 1 Then ' If correct button pressure Call Beep(100) ' Signal end of test with short beep Else ' Wrong button pressure Call Beep(500) ' Signal end of test with long beep End If Waitmse 3000 ' 3 secs delay before to restart new test Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Generate beep with buzzer of GMM TST3 with passed duration in msec, into ' dtbeep argument parameter Sub Beep(dtbeep As Word) Pinbz1 = 0 ' Enable buzzer for beep Waitmse Dtbeep ' Perform delay for beep duration Pinbz1 = 1 ' Disable buzzer End Sub '******************* End of subroutines used by program ************************