' ********************************************************************** ' * File: uk_BASAVR_008.BAS * ' * Version: 1.1 * ' * Date: 03.05.10 * ' * Development Tools: Bascom-AVR Demo Ver. 1.11.9.1 + * ' * + AVR bootloader grifo(r) Ver. 1.2 * ' * Cards: GMM AM08 + 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 008 of BASCOM AVR course. ' It executes simple operations on digital I/O, by using the on board activity ' LED, one push button and the buzzer available on GMM TST3, related to time. ' The program acquires the status of red push button T1 and when not pressed, it ' chnages status to activity LED DL1 on Mini Module and it generates a beep with ' GMM TST3 buzzer each second. When T1 is pressed the same operations are speed ' up and they are executed 5 time per second. All timings are generated by ' calibrated loop and DELAY instruction of BASCOM AVR. ' The program works only when the GMM AM08 is mounted on Z1 socket of GMM TST3!! ' ' Added instructions: * (multiplication), \ (integer division). ' ' 03/05/10: uk_BASAVR_008.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 M8DEF.DAT file into the directory where the ' BASCOM AVR is installed and copy it if not present. ' 2) Into the window "Options | Compiler | Chip" set: ' Chip: m8def.dat ' XRAM: None ' HW Stack: 64 ' Soft Stack: 32 ' Framesize: 64 ' XRAM waitstate: disabled ' External Access Enable: disabled '************************* Compiler directives ********************************* $regfile "M8DEF.DAT" ' Definitions file for used microcontroller $romstart = &H0 ' Code start address on FLASH $crystal = 7372800 ' Microcontroller crystal frequency $hwstack = 64 ' Hardware stack space $swstack = 32 ' Software stack space $framesize = 64 ' Frame space $map ' Generate debug information '******************************* Definitions *********************************** ' The resources used by program are connected as described in following table. ' ' Resource GMM TST3 Z1 pin GMM AM08 pin uP signal ' LED DL1 18 12 PB5 , SCK ' T1 Button 12 6 PC5 , ADC5 , SCL ' Buzzer BZ1 15 9 PB4 , MISO Pindl1 Alias Portb.5 ' Bit with output signal connected to DL1 on GMM AM08 Pint1 Alias Pinc.5 ' Bit with input signal connected to red push button T1 on GMM TST3 Pinbz1 Alias Portb.4 ' Bit with output signal connected to buzzer BZ1 on GMM TSt3 '************************* Constants declaration ******************************* Const Del1sec = 993 ' Cycles number to obtain 1 sec delay (experimentally calibrated) Const Del20msec = Del1sec * 20 \ 1000 ' Cycles number to obtain 20 msec delay Const Del180msec = Del1sec * 180 \ 1000 ' Cycles number to obtain 180 msec delay Const Del980msec = Del1sec * 980 \ 1000 ' Cycles number to obtain 980 msec delay '************************* Variables declaration ******************************* Dim T1stat As Bit ' Boolean variable for T1 Button status Dim Dl1stat As Bit ' Boolean variable for DL1 LED status Dim Del As Long ' Cycles counter variable for delay '************************ Subroutines declaration ****************************** '****************************** Main program *********************************** Main: Ddrc.5 = 0 ' Initialize signal connected to T1 as digital input Ddrb.5 = 1 ' Initialize signal connected to DL1 as digital output, high Ddrb.4 = 1 ' Initialize signal connected to BZ1 as digital output, high Dl1stat = 1 ' Initialize DL1 status as disabled Do ' Begin endless loop Dl1stat = Not Dl1stat ' Invert variable with DL1 status Pindl1 = Dl1stat ' Set DL1 LED with new status ' Perfor a beep with buzzer on GMM TST3 by enabling it for about 20 milliseconds Pinbz1 = 0 ' Enable buzzer BZ1 Del = 0 ' Reset cycles counter for delay Do ' Begin loop for 20 milliseconds delay Delay ' Perfor a delay of about 1000 microseconds Del = Del + 1 ' Increase cycles counter for delay Loop Until Del > Del20msec ' End loop for delay Pinbz1 = 1 ' Disable buzzer BZ1 T1stat = Pint1 ' Acquire and save T1 Button status If T1stat = 1 Then ' If button not pressed ' Perform 980 milliseconds delay, that added to 20 milliseconds of beep, make the endless ' loop time equal to 1000 milliseconds. So the same cycle is executed one time for second. Del = 0 ' Reset cycles counter for delay Do ' Begin loop for 980 milliseconds delay Delay ' Perfor a delay of about 1000 microseconds Del = Del + 1 ' Increase cycles counter for delay Loop Until Del > Del980msec ' End loop for delay Else ' If button pressed ' Perform 180 milliseconds delay, that added to 20 milliseconds of beep, make the endless ' loop time equal to 200 milliseconds. So the same cycle is executed five times for second. Del = 0 ' Reset cycles counter for delay Do ' Begin loop for 180 milliseconds delay Delay ' Perfor a delay of about 1000 microseconds Del = Del + 1 ' Increase cycles counter for delay Loop Until Del > Del180msec ' End loop for delay End If Loop ' End endless loop End '*************************** End of main program *******************************