' ********************************************************************** ' * File: uk_BAS51_037.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 037 of BASCOM 8051 course. ' The program generates a square wave with a frequency defined by console, ' through Timer, on the signal connected to red LED L2. Of course, the LED ' activation doesn't change with inserted frequency in fact the generated ' signal is always a square wave with a 50% duty cycle. ' 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: None. ' ' 10/01/11: uk_BAS51_037.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 ' L2 12 6 P2.1 P2.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 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 Freq As Byte ' Value inserted for frequency setting '************************ Subroutines declaration ****************************** Declare Sub Ini_tmrirq() ' Initialize timer for periodic interrupt generation '****************************** 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 Call Ini_tmrirq() ' Initialize timer for frequency generation Print ' Separate from previous visualization by showing an empty new line Print Print " Generate programmable frequency on signal connected to red LED of GMM TST3" Print "Mount Mini Module on Z1 of GMM TST3." Print "The frequency generated on signal connected to L2 is inversal proportional to" Print "inserted time constant, from a minimum value 255->2409 Hz to a maximum value" Print "9->68267 Hz. For further detail please see program remarks." Do ' Begin endless loop Input "Insert new time constant, for frequency (1..255): " , Freq ' The inserted value defines the generated frequency, through the time constant" ' loaded into Timer0. In details: ' Timer0 counting frequency = Clock frequency/12 = 14745600/12 = 1228800 Hz ' Timer0 interrupt frequency = Timer0 counting frequency/time constant ' Frequency generated by program = Timer0 interrupt frequency/2 ' in fact the signal is generated by periodic interrupt service routine of ' Timer0, that complement it. So, two interrupts are required in order to ' obtain the complete period (half period low+half period high). ' The interrupt time (entry, execution and exit from service routine) in ' this program belong about 14 usec, so the very low time constants (from ' 1 to 8) generate anyway the same maximum frequency of about 68587 Hz. Load Timer0 , Freq ' Load inserted time constant and set frequency Loop ' End endless loop Stop Timer0 ' Stop TIMER0 and associated functions End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Initialize periodic interrupt generation with auto reload from compare, ' through TIMER0 of microcontroller, used for all time management of program. ' The remarks of this subroutine briefly describes the operations performed, ' but detailed information are available in microcontroller data sheet and in ' BASCOM on line help. Sub Ini_tmrirq() Config Timer0 = Timer , Gate = Internal , Mode = 2 ' TIMER0 as 8 bit timer with auto reload and internal activation On Timer0 Timer0_irq Nosave ' Definine interrupt service routine for TIMER0 overflow Load Timer0 , 255 ' Load maximum time constant -> minimum frequency Priority Set Timer0 ' Higher priority for TIMER0 interrupt Enable Timer0 ' Enable interrupt from TIMER0 overflow Enable Interrupts ' Enable general interrupts Start Timer0 ' Enable TIMER2 End Sub ' Periodic interrupt service routine associated to TIMER0. ' It complements the output signal that generates the selected frequency. ' the service routine is very short and simple and thus it doesn't uses ' microprocessor's registers and consequently it is declared with Nosave ' directive, in order to make it as fast as possible. Timer0_irq: Pinl2 = Not Pinl2 ' Invert status of signal connected to L2 Return '******************* End of subroutines used by program ************************