' ********************************************************************** ' * File: uk_BASAVR_029.BAS * ' * Version: 1.1 * ' * Date: 25.10.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 29 of BASCOM AVR course. ' The program acquire status of 16 push buttons available on the TIO 16 ' board that is connected to I/O connectors of GMM TST3. ' The program describe its functionalities and the buttons status on a serial ' console provided of monitor 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!! ' Inside the program the terms that identify the used signals refers to electric ' diagram and technical manual of GMM TST3!! ' ' Added instructions: None. ' ' 25/10/10: uk_BASAVR_029.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 ' 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 set in following positions: ' 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 ' BUTTON resource GMM TST3 GMM AM08 GMM AM08 signal ' T1 CN4.2 33 27 ADC7 ADC7 ' T2 CN4.1 32 26 PCO ADC0 PC0 ' T3 CN4.4 31 25 PC1 ADC1 PC1 ' T4 CN4.3 30 24 PB1 OC1A PB1 ' T5 CN4.6 29 23 PB0 ICP PB0 ' T6 CN4.5 28 22 PB2 OC1B /SS PB2 ' T7 CN4.8 27 21 PD6 AIN0 PD6 ' T8 CN4.7 26 20 PD7 AIN1 PD7 ' T9 CN4.15 25 19 PD2 INT0 PD2 ' T10 CN4.16 24 18 PD3 INT1 PD3 ' T11 CN4.13 23 17 PD4 T0 XCK PD4 ' T12 CN4.14 22 16 PD5 T1 PD5 ' T13 CN4.11 21 15 PC2 ADC2 PC2 ' T14 CN4.12 19 13 PC3 ADC3 PC3 ' T15 CN4.9 14 8 PB3 MOSI OC2 PB3 ' T16 CN4.10 15 9 PB4 MISO PB4 ' ' 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 ******************************* Const Cret = &H0D ' ASCII code of Carriage Return '************************* Variables declaration ******************************* Dim Dirio As Byte ' Variable with digital I/O direction Dim Iod As Byte ' Variable with digital I/O status Dim Hlpb As Byte ' General purpose help variable Dim Curkey As Byte ' Current button state variable '************************ Subroutines declaration ****************************** Declare Sub Ini_pa(byval Dirio As Byte) ' Initialize GMM TST3 port A Declare Sub Get_pa(iod As Byte) ' Get GMM TST3 port A Declare Sub Ini_pc(byval Dirio As Byte) ' Initialize GMM TST3 port C Declare Sub Get_pc(iod As Byte) ' Get GMM TST3 port C '****************************** Main program *********************************** Main: Pinrx = 0 ' Initialize signals for serial communication Pintx = 0 ' as digital inputs Call Ini_pa(&H00) ' Initialize lines connected to port A as inputs Call Ini_pc(&H00) ' Initialize lines connected to port c as inputs Print ' Separate from previous visualization by showing an empty new line Print Print " Acquisition of 16 push button of TIO 16" Print "Mount Mini Module on Z2 of GMM TST3 and connect TIO 16 to CN4." Print "The push buttons states are continuosly displayed.." Print "T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16" Do ' Begin endless loop Call Get_pa(iod) ' Get red push buttons states Iod = Iod Xor &HFF ' Convert value in reversed logic For Hlpb = 1 To 8 ' Loop repeated for eigth red buttons Curkey = Iod And &H01 ' Obtain current button status Print " " ; Curkey ; " "; ' Show status of current button Shift Iod , Right , 1 ' Shift states to change current buttons Next Hlpb Call Get_pc(iod) ' Get yellow and grren push buttons states Iod = Iod Xor &HFF ' Convert value in reversed logic For Hlpb = 1 To 8 ' Loop repeated for eigth yellow and green buttons Curkey = Iod And &H01 ' Obtain current button status Print " " ; Curkey ; " "; ' Show status of current button Shift Iod , Right , 1 ' Shift states to change current buttons Next Hlpb Printbin Cret ' Mantain visualization on same row Waitms 50 ' Delay between acquisition Loop ' End endless loop End '*************************** 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 -> ADC7 PA.1 -> PC0 PA.2 -> PC1 PA.3 -> PB1 ' PA.4 -> PB0 PA.5 -> PB2 PA.6 -> PD6 PA.7 -> PD7 ' with the I/O modality passed in dirio parameter (bit at 1=output at high ' level; bit at 0=input), by leaving unchanged the status of all the other ' lines. ' Note: On GMM AM08 all the 8 lines of port A can be defined as input, but only ' 7 lines as output. Sub Ini_pa(byval Dirio As Byte) ' Initialize line connected to microcontroller analog signal, managed through ' the relative A/D converter section, as input Config Adc = Single , Prescaler = Auto , Reference = Avcc ' Initialize A/D section with conversion on request, Start Adc ' best prescaler, Vref=5 V and enable it ' Initialize other 7 lines of port A, connected to digital signals of ' microcontroller Portc.0 = 1 ' Set initial status high for PA.1->PC0 as output Ddrc.0 = Dirio.1 ' Define direction for PA.1->PC0 Portc.1 = 1 ' Set initial status high for PA.2->PC1 as output Ddrc.1 = Dirio.2 ' Define direction for PA.2->PC1 Portb.1 = 1 ' Set initial status high for PA.3->PB1 as output Ddrb.1 = Dirio.3 ' Define direction for PA.3->PB1 Portb.0 = 1 ' Set initial status high for PA.4->PB0 as output Ddrb.0 = Dirio.4 ' Define direction for PA.4->PB0 Portb.2 = 1 ' Set initial status high for PA.5->PB2 as output Ddrb.2 = Dirio.5 ' Define direction for PA.5->PB2 Portd.6 = 1 ' Set initial status high for PA.6->PD6 as output Ddrd.6 = Dirio.6 ' Define direction for PA.6->PD6 Portd.7 = 1 ' Set initial status high for PA.7->PD7 as output Ddrd.7 = Dirio.7 ' Define direction for PA.7->PD7 End Sub ' Get states of the 8 lines of uP connected to port A on CN4 of GMM TST3, ' and returns it in Iod parameter. Sub Get_pa(iod As Byte) Local Adres As Word ' Local variable for A/D conversion result ' Get state of line connected to analog signal of microcontroller, ' managed through relative A/D converter section Adres = Getadc(7) ' Acquire input A/D 7 state, connected to PA.0 If Adres < 100 Then ' Control and set PA-0->ADC7 state Iod.0 = 0 Else Iod.0 = 1 End If Iod.1 = Pinc.0 ' Get state of line PA.1->PC0 Iod.2 = Pinc.1 ' Get state of line PA.2->PC1 Iod.3 = Pinb.1 ' Get state of line PA.3->PB1 Iod.4 = Pinb.0 ' Get state of line PA.4->PB0 Iod.5 = Pinb.2 ' Get state of line PA.5->PB2 Iod.6 = Pind.6 ' Get state of line PA.6->PD6 Iod.7 = Pind.7 ' Get state of line PA.7->PD7 End Sub ' Initializes the 8 pins of uP connected to port C on CN4 of GMM TST3: ' PC.0 -> PD2 PC.1 -> PD3 PC.2 -> PD4 PC.3 -> PD5 ' PC.4 -> PC2 PC.5 -> PC3 PC.6 -> PB3 PC.7 -> PB4 ' with the I/O modality passed in dirio parameter (bit at 1=output at high ' level; bit at 0=input), by leaving unchanged the status of all the other ' lines. Sub Ini_pc(byval Dirio As Byte) ' Initialize 8 lines of port A, all connected to digital signals of ' microcontroller Portd.2 = 1 ' Set initial status high for PC.0->PD2 as output Ddrd.2 = Dirio.0 ' Define direction for PC.0->PD2 Portd.3 = 1 ' Set initial status high for PC.1->PD3 as output Ddrd.3 = Dirio.1 ' Define direction for PC.1->PD3 Portd.4 = 1 ' Set initial status high for PC.2->PD4 as output Ddrd.4 = Dirio.2 ' Define direction for PC.2->PD4 Portd.5 = 1 ' Set initial status high for PC.3->PD5 as output Ddrd.5 = Dirio.3 ' Define direction for PC.3->PD5 Portc.2 = 1 ' Set initial status high for PC.4->PC2 as output Ddrc.2 = Dirio.4 ' Define direction for PC.4->PC2 Portc.3 = 1 ' Set initial status high for PC.5->PC3 as output Ddrc.3 = Dirio.5 ' Define direction for PC.5->PC3 Portb.3 = 1 ' Set initial status high for PC.6->PB3 as output Ddrb.3 = Dirio.6 ' Define direction for PC.6->PB3 Portb.4 = 1 ' Set initial status high for PC.7->PB4 as output Ddrb.4 = Dirio.7 ' Define direction for PC.7->PB4 End Sub ' Get states of the 8 lines of uP connected to port C on CN4 of GMM TST3, ' and returns it in Iod parameter. Sub Get_pc(iod As Byte) Iod.0 = Pind.2 ' Get state of line PC.0->PD2 Iod.1 = Pind.3 ' Get state of line PC.1->PD3 Iod.2 = Pind.4 ' Get state of line PC.2->PD4 Iod.3 = Pind.5 ' Get state of line PC.3->PD5 Iod.4 = Pinc.2 ' Get state of line PC.4->PC2 Iod.5 = Pinc.3 ' Get state of line PC.5->PC3 Iod.6 = Pinb.3 ' Get state of line PC.6->PB3 Iod.7 = Pinb.4 ' Get state of line PC.7->PB4 End Sub '******************* End of subroutines used by program ************************