' ********************************************************************** ' ** Program: gmbtmpe.BAS - Version : 1.1 - 14 June 2005 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Board : GMB HR168 and GMM AM32 ** ' ** Society: grifo(r) ITALIAN TECHNOLOGY ** ' ** Via Dell' Artigiano 8/6 40016 San Giorgio di Piano (BO) ** ' ** Tel.+39 051 892 052 Fax +39 051 893 661 ** ' ** http://www.grifo.com http://www.grifo.it ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' 14.06.05 - Rel 1.1 By Graziano Gaiba ' This demo allows to use immediatly TTL I/O digital lines available on CN7. ' According to Mini Module used, the list of lines existing is printed. ' After selecting the line to use it can be managed as input (its status is ' shown continuously on console) or as output (setting it high or low). ' Should the line selected be associated to Real Time Clock, this peripheral ' manages it. ' ' Compiled file is smaller than 2048 bytes, so it can becompliled with free ' demo of BASCOM AVR. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options | Compiler | Chip, set: ' ' Chip: M32 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' $regfile = "m32def.dat" $crystal = 7372800 $baud = 19200 ' '****************** Constants declatation *********************** ' Const Cret = 13 ' Carriage return Const Nl = 10 ' New line Const Clrscr = 12 ' Clear screen Const Bell = 7 ' Bell ' '****************** Variables declaration ********************** ' ' Generic use Dim R As Byte , C As Byte , V As Byte , T As Byte Dim S As Byte Dim Vbit As Bit Dim A As Eram Byte At 1023 ' '********************* Procedures declaration ************************** ' Declare Sub Init() ' Initialization Declare Sub Set_relays_out(byval V As Byte) ' Set relays status Declare Sub Check_ready() ' '************************** Main program ****************************** ' Main: Call Init() ' Initialize module Call Set_relays_out(0) Print Chr(clrscr); ' Clears the screen Print "Demo 1.1 for GMM AM32 + GMB HR168" Print Call Check_ready() Do Print "CN4 features follwong I/O TTL:" Print Print "1) Pin 2" Print "2) Pin 6" Print "3) Pin 8" Print Print "Select: "; Do V = Inkey() Loop Until V <> 0 Print Chr(v) Print Do Print "Input/Output (I/O)? " ; R = Waitkey() R.5 = 1 ' Changes in lowercase Loop Until R = "i" Or R = "o" Print Chr(r) If R = "i" Then Ddra.7 = 0 ' Sets all bit as input Ddrd.4 = 0 Ddrd.5 = 0 Print "Press a key to exit" Print "Pin status:" Do If V = "1" Then Vbit = Pind.4 ' Pin 2 of CN7 End If If V = "2" Then Vbit = Pind.5 ' Pin 6 of CN7 End If If V = "3" Then Vbit = Pina.7 ' Pin 8 of CN7 End If Print Vbit ; Chr(13); Waitms 200 S = Inkey() Loop Until S <> 0 Else Ddra.7 = 1 ' Sets all bit as output Ddrd.4 = 1 Ddrd.5 = 1 Do Print "Pin status (0/1; 2 exit): "; C = Waitkey() Print Chr(c) C = C - "0" ' Converts in number If C <> 2 Then Vbit = C.0 If V = "1" Then Portd.4 = Vbit ' Pin 2 of CN7 End If If V = "2" Then Portd.5 = Vbit ' Pin 6 of CN7 End If If V = "3" Then Porta.7 = Vbit ' Pin 8 of CN7 End If End If Loop Until C = 2 End If Loop End ' '************************ Program end *************************** ' ' '****************************************************************************** '* Demo specific procedures * '****************************************************************************** ' ' ' Initializes demo ' Sub Init() ' Initializes directionality of ports that drive optocouped inputs and relay ' outputs: ' IN1-1 - Porta.0 ' IN2-1 - Porta.1 ' IN3-1 - Portd.2 ' IN4-1 - Portd.3 ' IN5-1 - Portb.0 ' IN6-1 - Portb.1 ' IN7-1 - Porta.2 ' IN8-1 - Porta.3 Ddra.0 = 0 Ddra.1 = 0 Ddrd.2 = 0 Ddrd.3 = 0 Ddrb.0 = 0 Ddrb.1 = 0 Ddra.2 = 0 Ddra.3 = 0 ' IN1-2 - Porta.4 ' IN2-2 - Porta.5 ' IN3-2 - Portc.2 ' IN4-2 - Portc.3 ' IN5-2 - Portc.4 ' IN6-2 - Portc.5 ' IN7-2 - Portc.6 ' IN8-2 - Portc.7 Ddra.4 = 0 Ddra.5 = 0 Ddrc.2 = 0 Ddrc.3 = 0 Ddrc.4 = 0 Ddrc.5 = 0 Ddrc.6 = 0 Ddrc.7 = 0 ' OUT A1 - Portd.6 ' OUT A2 - Portb.4 ' OUT B1 - Portb.2 ' OUT B2 - Portb.3 ' OUT C1 - Portb.5 ' OUT C2 - Portb.6 ' OUT D1 - Portb.7 ' OUT D2 - Porta.6 (by default, that is when J10 is connected in 3-4) Ddrd.6 = 1 Ddrb.4 = 1 Ddrb.2 = 1 Ddrb.3 = 1 Ddrb.5 = 1 Ddrb.6 = 1 Ddrb.7 = 1 Ddra.6 = 1 End Sub ' '****************************************************************************** '* Procedures to manage I/O signals of GMB HR168 * '****************************************************************************** ' ' ' . ' ' Set relays outputs ' If Bit value is 1, corresponding relay is closed, otherwise it is open ' V.0 controls RL1 ' V.1 controls RL2 ' V.2 controls RL3 ' V.3 controls RL4 ' V.4 controls RL5 ' V.5 controls RL6 ' V.6 controls RL7 ' V.7 controls RL8 Sub Set_relays_out(byval V As Byte) Portd.6 = Not V.0 Portb.4 = Not V.1 Portb.2 = Not V.2 Portb.3 = Not V.3 Portb.5 = Not V.4 Portb.6 = Not V.5 Portb.7 = Not V.6 Porta.6 = Not V.7 End Sub ' ' ' Check for hardware ready ' Sub Check_ready() Test: If A = &H55 Then Goto L2 Else Goto Test End If L2: End Sub