' ********************************************************************** ' * File: uk_BAS51_034.BAS * ' * Version: 1.1 * ' * Date: 06.12.10 * ' * 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 034 of BASCOM 8051 course. ' The program performs an alternative shift of one LED turned on with a drop ' effect, by using the 16 LEDs available on TIO 16 board that is connected to ' I/O connectors of GMM TST3. In other words it moves a turned on LED with a ' following wake, before from left to right and then from right to left, in a ' continuos cycle (SUPERCAR effect). ' The program describe its functionalities 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!! ' Inside the program the terms that identify the used signals refers to electric ' diagram and technical manual of GMM TST3!! ' ' Added instructions: None. ' ' 06/12/10: uk_BAS51_034.BAS - Ver 1.1 - By G.A. ' First version. ' ' '**************************** IDE Configurations ******************************* ' NOTE: in order to coorectly 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 1-2 ; J3 in 1-2 ; J5 in 2-3 ; J7 in 2-3 ; J8 in 2-3 ' J9 in 2-3!!! ' ' TIO 16 GMM TST3 pin Z2 pin Signal Used uP ' LED resource GMM TST3 GMM 5115 GMM 5115 signal ' LD1 CN4.2 33 27 P1.0 DSW1.1 T2 DL1 P1.0 ' LD2 CN4.1 32 26 P1.1 ADC1 T2EX P1.1 ' LD3 CN4.4 31 25 P1.2 ADC2 ECI P1.2 ' LD4 CN4.3 30 24 P1.3 ADC3 CEX0 P1.3 ' LD5 CN4.6 29 23 P1.4 ADC4 CEX1 P1.4 ' LD6 CN4.5 28 22 P1.5 ADC5 P1.5 ' LD7 CN4.8 27 21 P1.6 ADC6 P1.6 ' LD8 CN4.7 26 20 P1.7 ADC7 P1.7 ' LD9 CN4.15 25 19 P3.2 INT0 P3.2 ' LD10 CN4.16 24 18 P3.3 INT1 P3.3 ' LD11 CN4.13 23 17 P3.4 T0 P3.4 ' LD12 CN4.14 22 16 P3.5 T1 P3.5 ' LD13 CN4.11 21 15 P3.6 P3.6 ' LD14 CN4.12 19 13 P3.7 P3.7 ' LD15 CN4.9 14 8 P4.0 P4.0 ' LD16 CN4.10 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. Pinrx Alias P3.0 ' Signal connected to GMM 5115 RxD Pintx Alias P3.1 ' Signal connected to GMM 5115 TxD '************************* Constants declaration ******************************* Const Dtshift = 240 ' LEDs settings keeping time, in cycles '************************* Variables declaration ******************************* Dim Dirio As Byte ' Variable with digital I/O direction Dim Iod As Byte ' Variable with digital I/O status Dim Nset As Byte ' Variable for current setting index Dim Nled As Byte ' Variable for LED index Dim Modcnt As Byte ' Variable for current LEDs modulation Dim Modled(16) As Byte ' Array with settings=LEDs modulation Dim Delshift As Word ' Counter for LEDs settings keeping time '************************ Subroutines declaration ****************************** Declare Sub Ini_pa(dirio As Byte) ' Initialize GMM TST3 port A Declare Sub Ini_pc(dirio As Byte) ' Initialize GMM TST3 port C Declare Sub Ini_modled() ' Inizialize timer for periodic interrupt generation '****************************** Main program *********************************** Main: Pinrx = 1 ' Initialize signals for serial communication Pintx = 1 ' as digital inputs Call Ini_pa(&H00) ' Initialize lines connected to port A as outputs Call Ini_pc(&H00) ' Initialize lines connected to port C as outputs Call Ini_modled() ' Inizialize timer for LEDs modulation Print ' Separate from previous visualization by showing an empty new line Print Print " Alternate shift of one LED of TIO 16 with drop effect" Print "Mount Mini Module on Z2 of GMM TST3 and connect TIO 16 to CN4." Print "Shift in execution.."; Do ' Begin endless loop Restore Leds_settings ' Point to begin of table with LEDs settings For Nset = 1 To 36 ' Cycle that move LED through the 36 settings of the table For Nled = 1 To 16 ' Cycle that get current LEDs setting Read Modled(nled) ' Save settings=modulation in proper array Next Nled Delshift = 0 ' Reset counter for LEDs settings keeping time Do ' The LEDs of TIO 16 are defined directly with the states obtained by ' settings in table, related to elapsed time, scanned by occured periodic ' interrupts counter Modcnt. The direct settings on microcontroller pins ' optimize the execution time that must be reduced to minimum, in order ' to decrease the same LEDs flicking. If Modcnt > Modled(1) Then ' Obtain LD1 setting according with its status and elapsed time P1.0 = 0 Else P1.0 = 1 End If If Modcnt > Modled(2) Then ' Obtain LD2 setting according with its status and elapsed time P1.1 = 0 Else P1.1 = 1 End If If Modcnt > Modled(3) Then ' Obtain LD3 setting according with its status and elapsed time P1.2 = 0 Else P1.2 = 1 End If If Modcnt > Modled(4) Then ' Obtain LD4 setting according with its status and elapsed time P1.3 = 0 Else P1.3 = 1 End If If Modcnt > Modled(5) Then ' Obtain LD5 setting according with its status and elapsed time P1.4 = 0 Else P1.4 = 1 End If If Modcnt > Modled(6) Then ' Obtain LD6 setting according with its status and elapsed time P1.5 = 0 Else P1.5 = 1 End If If Modcnt > Modled(7) Then ' Obtain LD7 setting according with its status and elapsed time P1.6 = 0 Else P1.6 = 1 End If If Modcnt > Modled(8) Then ' Obtain LD8 setting according with its status and elapsed time P1.7 = 0 Else P1.7 = 1 End If If Modcnt > Modled(9) Then ' Obtain LD9 setting according with its status and elapsed time P3.2 = 0 Else P3.2 = 1 End If If Modcnt > Modled(10) Then ' Obtain LD10 setting according with its status and elapsed time P3.3 = 0 Else P3.3 = 1 End If If Modcnt > Modled(11) Then ' Obtain LD11 setting according with its status and elapsed time P3.4 = 0 Else P3.4 = 1 End If If Modcnt > Modled(12) Then ' Obtain LD12 setting according with its status and elapsed time P3.5 = 0 Else P3.5 = 1 End If If Modcnt > Modled(13) Then ' Obtain LD13 setting according with its status and elapsed time P3.6 = 0 Else P3.6 = 1 End If If Modcnt > Modled(14) Then ' Obtain LD14 setting according with its status and elapsed time P3.7 = 0 Else P3.7 = 1 End If If Modcnt > Modled(15) Then ' Obtain LD15 setting according with its status and elapsed time P4.0 = 0 Else P4.0 = 1 End If If Modcnt > Modled(16) Then ' Obtain LD16 setting according with its status and elapsed time P4.1 = 0 Else P4.1 = 1 End If Incr Delshift ' Increase counter for LEDs settings keeping time Loop Until Delshift = Dtshift ' Repeat until LEDs settings keeping time is elapsed Next Nset Loop ' End endless loop Stop Timer0 ' Stop TIMER0 and associated functions '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Initializes the 8 pins of uP connected to port A on CN4 of GMM TST3: ' PA.0 -> P1.0 PA.1 -> P1.1 PA.2 -> P1.2 PA.3 -> P1.3 ' PA.4 -> P1.4 PA.5 -> P1.5 PA.6 -> P1.6 PA.7 -> P1.7 ' with the I/O modality passed in dirio parameter (bit at 0=output at low ' level; bit at 1=input), by leaving unchanged the status of all the other ' lines. ' Note: On GMM 5115 the digital I/O are quasi-bidirectional and they don't have ' direction settable. Thus the subroutine doesn't set direction on these lines ' and it has been developed for compatibility and code exchange with other ' Mini Modules. Sub Ini_pa(dirio As Byte) P1 = &HFF ' Set lines direction Iod = P1 End Sub ' Initializes the 8 pins of uP connected to port C on CN4 of GMM TST3: ' PC.0 -> P3.2 PC.1 -> P3.3 PC.2 -> P3.4 PC.3 -> P3.5 ' PC.4 -> P3.6 PC.5 -> P3.7 PC.6 -> P4.0 PC.7 -> P4.1 ' with the I/O modality passed in dirio parameter (bit at 0=output at low ' level; bit at 1=input), by leaving unchanged the status of all the other ' lines. ' Note: On GMM 5115 the digital I/O are quasi-bidirectional and they don't have ' direction settable. Thus the subroutine doesn't set direction on these lines ' and it has been developed for compatibility and code exchange with other ' Mini Modules. Sub Ini_pc(dirio As Byte) P3 = P3 Or &HFC ' Set direction of lines P3.2-P3.7 Iod = P3 P4 = P4 Or &H03 ' Set direction of lines P4.0-P4.1 Iod = P4 End Sub ' Initialize periodic interrupt generation by TIMER0 of microcontroller, used ' for all the times management of the program. The remarks of this subroutine ' briefly specify the executed operations but detailed informations are ' available in data sheet of microcontroller and inside on line help of BASCOM. ' The 39 usec time has been selected in order obtain a LEDs modulation period ' of about 10 msec with 8 bits: 10 msec/256=39 usec. Sub Ini_modled() Modcnt = 0 ' Clear LEDs modulation counter Config Timer0 = Timer , Gate = Internal , Mode = 2 ' TIMER0 as 8 bit timer with auto reload and internal activation On Timer0 Timer0_irq Nosave ' Define TIMER0 overflow interrupt service routine Load Timer0 , 48 ' Load time constant for 39 usec Priority Set Timer0 ' Set higher priority for TIMER0 interrupt Enable Timer0 ' Enable interrupt from TIMER0 Enable Interrupts ' General interrupts enable Start Timer0 ' Enable TIMER0 End Sub ' Interrupt service routine associated to periodic TIMER0 overflow. ' It increases the occured periodic interrupts counter and it generates a 39 ' usec timing base of the program. ' The routine is very short and it doesn't use registers of microprocessor; so ' it has been declared with Nosave directive, in order to make it as fast as ' possible Timer0_irq: Incr Modcnt ' Increase LEDs modulation counter Return '******************* End of subroutines used by program ************************ '********************* Begin of data used by program *************************** ' The turned on LED shifting with drop is obtained with different settings of ' the LEDs on TIO 16. The data below reports these settings, with the following ' organization: ' - each setting corresponds to a different LEDs status that, once carried out ' in sequence, produces the moving with drop in both the directions; ' - the drop consist of four LEDs activated rispectively with 100%, 50%, 25% ' and 12% light intensity; ' - the activation percentages are expresssed as most significant bits at 1, on ' the total 8 of the modulation period, in hexadecimal: ' 100%->00000000=000=00H; ' 50%->10000000=128=80H; ' 25%->11000000=192=C0H; ' 12%->11100000=224=E0H; ' 0%->11111111=255=FFH; ' - each setting is composed by the 16 LEDs status (from LD1 to LD16), and it ' is expressed with activation values just described; Leds_settings: ' LD1 LD2 LD3 LD4 LD5 LD6 LD7 LD8 LD9 LD10 LD11 LD12 LD13 LD14 LD15 LD16 Data &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H80 , &H00 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &HC0 , &H00 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HE0 , &H00 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &HFF , &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &H00 , &H80 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &H00 , &HC0 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF Data &H00 , &HE0 , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF '*********************** End of data used by program ***************************