' ********************************************************************** ' ** Program: gmbiote.BAS - Version : 1.1 - 20 June 2005 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Board : GMB HR168 and GMM AM128 ** ' ** 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 ** ' ********************************************************************** ' ' 20.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. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options | Compiler | Chip, set: ' ' ' Chip: M128 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' $regfile = "m128def.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 ' Const Ee_timeout = 50000 ' '****************** 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 ' '********************* Procedures declaration ************************** ' Declare Sub Init() ' Initialization Declare Sub Set_relays_out(byval V As Byte) ' Set relays status Declare Sub Check_ready() Declare Function Check_ready_2() As Byte ' '************************** Main program ****************************** ' Main: Call Init() ' Initialize module Call Set_relays_out(0) Print Chr(clrscr); ' Clears the screen Print "Demo 1.1 for GMM AM128 + GMB HR168" Print Call Check_ready() Do Print "CN7 features follwong I/O TTL:" Print Print "1) Pin 2" Print "2) Pin 3" Print "3) Pin 4 (interrupt dell'RTC)" Print "4) Pin 6" Print "5) 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 Ddrd.6 = 0 ' Sets all bit as input Ddrd.5 = 0 Ddrd.4 = 0 Ddrb.5 = 0 Ddrf.0 = 0 If V = "3" Then Print "This signal is connected to the open collector output of RTC interrupt" Print "on board of GMM AM128. Status of that output is visualized." End If Print "Press a key to exit" Print "Pin status:" Do If V = "1" Then Vbit = Pind.6 ' Pin 2 of CN7 End If If V = "2" Then Vbit = Pind.5 ' Pin 3 of CN7 End If If V = "3" Then Vbit = Pind.4 ' Pin 4 of CN7 End If If V = "4" Then Vbit = Pinb.5 ' Pin 6 of CN7 End If If V = "5" Then Vbit = Pinf.0 ' Pin 8 of CN7 End If Print Vbit ; Chr(13); Waitms 200 S = Inkey() Loop Until S <> 0 Else Ddrd.6 = 1 ' Sets all bit as output Ddrd.5 = 1 Ddrb.5 = 1 Ddrf.0 = 1 If V = "3" Then Print "This signal is connected to the open collector output of RTC interrupt" Print "on board of GMM AM128. It can't be used as a general purpose output." Print "Press a key to exit." C = Waitkey() Else 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.6 = Vbit ' Pin 2 of CN7 End If If V = "2" Then Portd.5 = Vbit ' Pin 3 of CN7 End If If V = "4" Then Portb.5 = Vbit ' Pin 6 of CN7 End If If V = "5" Then Portf.0 = Vbit ' Pin 8 of CN7 End If End If Loop Until C = 2 End If 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 - Portb.7 ' IN2-1 - Portb.6 ' IN3-1 - Porte.4 ' IN4-1 - Porte.5 ' IN5-1 - Portd.7 ' IN6-1 - Porte.6 ' IN7-1 - Portb.4 ' IN8-1 - Portb.0 Ddrb.7 = 0 Ddrb.6 = 0 Ddre.4 = 0 Ddre.5 = 0 Ddrd.7 = 0 Ddre.6 = 0 Ddrb.4 = 0 Ddrb.0 = 0 ' IN1-2 - Portc.0 ' IN2-2 - Portc.1 ' IN3-2 - Portc.2 ' IN4-2 - Portc.3 ' IN5-2 - Portc.4 ' IN6-2 - Portc.5 ' IN7-2 - Portc.6 ' IN8-2 - Portc.7 Ddrc = 0 ' OUT A1 - Portf.4 ' OUT A2 - Portf.5 ' OUT B1 - Portf.6 ' OUT B2 - Portf.7 ' OUT C1 - Portb.3 ' OUT C2 - Portb.2 ' OUT D1 - Portb.1 ' OUT D2 - Porte.2 (by Default , that is When J10 is connected in 3-4) Ddrf.4 = 1 Ddrf.5 = 1 Ddrf.6 = 1 Ddrf.7 = 1 Ddrb.3 = 1 Ddrb.2 = 1 Ddrb.1 = 1 Ddre.2 = 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 ' OUT A1 - Portf.4 ' OUT A2 - Portf.5 ' OUT B1 - Portf.6 ' OUT B2 - Portf.7 ' OUT C1 - Portb.3 ' OUT C2 - Portb.2 ' OUT D1 - Portb.1 ' OUT D2 - Porte.2 (by Default , that is When J10 is connected in 3-4) ' ' V.0 comanda RL1 OUT A1 ' V.1 comanda RL2 OUT A2 ' V.2 comanda RL3 OUT B1 ' V.3 comanda RL4 OUT B2 ' V.4 comanda RL5 OUT C1 ' V.5 comanda RL6 OUT C2 ' V.6 comanda RL7 OUT D1 ' V.7 comanda RL8 OUT D2 Sub Set_relays_out(byval V As Byte) Portf.4 = Not V.0 Portf.5 = Not V.1 Portf.6 = Not V.2 Portf.7 = Not V.3 Portb.3 = Not V.4 Portb.2 = Not V.5 Portb.1 = Not V.6 Porte.2 = Not V.7 End Sub ' '****************************************************************************** '* Generic procedures * '****************************************************************************** ' ' ' ' Supporting function for Check_ready(). ' Function Check_ready_2() As Byte Local Time_out As Word , I As Byte Time_out = 0 ' Timeout counter Do Incr Time_out ' Increment counter Loop Until Twcr.twint = 1 Or Time_out = Ee_timeout I = Twsr I = I And &HF8 Check_ready_2 = I End Function ' ' ' Check for card ready ' Sub Check_ready() Local Check As Byte , Test As Byte Do ' Loop to check for card ready Twsr = Twsr And &HFC Check = Twdr Or &HF4 Test.4 = Not Check.3 Twbr = 72 Twcr = &HA4 Check = Check_ready_2() Test = Check Or Twcr If Check = &H09 Then Test = &H67 Else Test.1 = Not Test.1 End If Twdr = &HA0 Twcr = &H84 Check = Check_ready_2() Twcr = &H94 Waitms 27 Loop Until Check = &H18 Or Test <> 1 Twcr.twen = 0 End Sub