' ********************************************************************** ' * File: uk_BASAVR_059.BAS * ' * Version: 1.1 * ' * Date: 19.02.12 * ' * 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 059 of BASCOM AVR course. ' A/D converter: one conversion for each key pressure. ' The program perform a single conversion, of one analog input of Mini Module, ' in correspondence of a key pressure and then it shows the resulted combination. ' The conversion is executed with the A/D converter section of microcontroller, ' that has the following features: ' - 10 bits maximum resolution; ' - programmable conversion time up to a minimum value of 13 usec; ' - successive approximation conversion technique; ' - analog sample & hold that reduce conversions noise; ' - 8 different inputs, multiplexed; ' - voltage applicable to analog inputs: 0÷Vref; ' - internal or external reference voltage Vref, variable in the 0÷5.0 V range; ' This program converts only one of the 8 analog inputs available on GMM AM08 ' Mini Module, as described in following definitions. The program uses the ' internally generated reference voltage Vref, as it is more stable than those ' supplied by GMM TST3 (resistor divider on power supply voltage). ' The program describes its functionalities and shows conversions 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 AVR (see IDE Configuration). ' The program works only when the GMM AM08 is mounted on Z2 socket of GMM TST3!! ' ' Added instructions: CONFIG ADC ; START ADC ; GETADC. ' ' 19.02.12: uk_BASAVR_059.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, copy it if not present and then restart the IDE. ' 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 ' 3) Into the window "Options | Communication" set: ' COM port = the PC line connected to GMM AM08, through GMM TST3 ' Baudrate = 19200 ' Parity = None ' Databits = 8 ' Stopbit = 1 ' Handshake = None ' Emulation = TTY ' Font = Terminal, Normal, 12 points, white colour ' Backcolor = Navy ' 4) At the end of compilation, after the code is programmed on GMM AM08, open ' the terminal emulation window of BASCOM AVR with the option: Tools | ' Terminal emulator (Ctrl+T) and then reset or powen on the Mini Module. '************************* 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 $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 configured as below described: ' J1 N.C. ; J2 in 1-2 ; J3 in 1-2 ; J5 in 2-3 ; J7 in 2-3 ; J8 in 2-3 ' J9 in 2-3 !!! ' ' GMM TST3 pin Z2 pin Signal Used uP ' resource GMM TST3 GMM AM08 GMM AM08 signal ' CN4.2 33 27 ADC7 ADC7 ' CN4.17 20 14 GND GND ' ' Signal pin COMx pin CN5 pin Z1 pin Signal Signal ' PC DB9 GMM TST3 GMM TST3 GMM AM08 GMM AM08 uP ' TX 3 3 9 3 RxD RS232 PD0 ' RX 2 2 10 4 TxD RS232 PD1 ' 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 Ddrd.0 ' Bit with direction signal connected to GMM AM08 Rxd Pintx Alias Ddrd.1 ' Bit with direction signal connected to GMM AM08 TxD '************************* Constants declaration ******************************* '************************* Variables declaration ******************************* Dim Choice As Byte ' Operation selected on console Dim Chadc As Byte ' Channel of A/D converter section Dim Cmbadc As Word ' Combination obtained from A/D converter '************************ Subroutines declaration ****************************** Declare Sub Ini_adc() ' Initialize A/D converter section '****************************** Main program *********************************** Main: Pinrx = 0 ' Initialize signals for serial communication Pintx = 0 ' as digital inputs Print ' Separate from previous visualization by showing 2 empty new line on console Print Print " Single conversion of GMM AM08 analog input with key pressure" Print "Mount Mini Module on Z2 of GMM TST3, connect analog input to convert" Print "between pins 17 (GND) and 2 (ADC7) on CN4 of GMM TST3." Print "When a key is pressed on the console, the analog input is converted" Print "and the obtained numeric combination is displayed on the console." Print Print "Acquired combination from ADC7 (points)" Call Ini_adc() ' Initialize lines and A/D converter section, used by program Do ' Begin endless loop Choice = Waitkey() ' Wait key pressure on console Cmbadc = Getadc(7) ' Convert channel ADC7 of A/D converter Print Cmbadc ' Show combination obtained by conversion, on console Loop ' End endless loop End '*************************** End of main program ******************************* '*********************** Subroutines used by program *************************** ' Initialize resources, variables and peripheral devices used for A/D conversion. ' Input: None ' Output: None Sub Ini_adc() ' The used A/D signal (ADC7) doesn't have multifunctions and thus it must not ' be set as input without pull up ' Define conversion on request, Prescaler=64 (50% of clock A/D), internal Vref=2,56V Config Adc = Single , Prescaler = 64 , Reference = Internal_2.56 Start Adc ' Enable A/D converter section End Sub '******************* End of subroutines used by program ************************