' ********************************************************************** ' * File: gmbiot.bas - Rel. 1.1 con Bascom AVR IDE e LIB 1.11.7.4 * ' * Schede: GMB HR168 + GMM AM128 * ' * GRIFO(R) 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 * ' * by Graziano Gaiba del 16.06.05 * ' ********************************************************************** ' ' 16.06.05 - Rel 1.1 By Graziano Gaiba ' Questo Demo permette di utilizzare immediatamente le linee di I/O digitale TTL ' presenti su CN7. Viene presentata la lista delle linee disponibili. ' Una volta selezionata quella d'interesse ' la si puo' gestire in input ' (rappresentando il suo stato sulla console) o in output (settandola alta o ' bassa). ' Una linea e' perennemente collegata all'interrupt del Real Time Clock del ' Mini Modulo o della GMB HR168, quindi la sua gestione avviene tramite ' questa periferica. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' Nel menu Options | Compiler | Chip, impostare: ' ' Chip: M128 ' HW Stack: almeno 64 ' Soft Stack: almeno 32 ' Framesize: almeno 64 ' ' '****************** Direttive del compilatore ************************** ' $regfile = "m128def.dat" $crystal = 7372800 $baud = 19200 ' '****************** Dichiarazione delle costanti *********************** ' Const Cret = 13 ' Codice di ritorno di carrello Const Nl = 10 ' Codice nuova linea Const Clrscr = 12 ' codice di clear screen Const Bell = 7 ' codice di Bell ' Const Ee_timeout = 50000 ' '****************** Dichiarazione delle variabili ********************** ' ' Uso generico Dim R As Byte , C As Byte , V As Byte , T As Byte Dim S As Byte Dim Vbit As Bit ' '****************** Dichiarazione delle procedure ********************** ' Declare Sub Init() ' Inizializzazione Declare Sub Set_relays_out(byval V As Byte) ' Imposta lo stato dei rele' Declare Sub Check_ready() Declare Function Check_ready_2() As Byte ' '************************* Programma main ****************************** ' Main: Call Init() ' Inzializza il modulo Do Call Set_relays_out(0) Print Chr(clrscr); ' Pulisce lo schermo Print "Demo 1.1 per GMM AM128 + GMB HR168" Print Call Check_ready() ' Verifica scheda pronta Print "Su CN7 questi pin sono 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 "SCELTA: "; Do V = Inkey() Loop Until V <> 0 Print Chr(v) Print Do Print "Input/Output (I/O)? " ; R = Waitkey() R.5 = 1 ' Trasforma in minuscolo Loop Until R = "i" Or R = "o" Print Chr(r) If R = "i" Then Ddrd.6 = 0 ' Setta tutti i bit in input Ddrd.5 = 0 Ddrd.4 = 0 Ddrb.5 = 0 Ddrf.0 = 0 If V = "3" Then Print "Questo segnale e' collegato all'uscita open collector di interrupt dell'RTC" Print "a bordo della GMM AM128. Viene visualizzato lo stato di tale uscita." End If Print "Premere tasto per uscire" Print "Stato pin:" Do If V = "1" Then Vbit = Pind.6 ' Pin 2 di CN7 End If If V = "2" Then Vbit = Pind.5 ' Pin 3 di CN7 End If If V = "3" Then Vbit = Pind.4 ' Pin 4 di CN7 End If If V = "4" Then Vbit = Pinb.5 ' Pin 6 di CN7 End If If V = "5" Then Vbit = Pinf.0 ' Pin 8 di CN7 End If Print Vbit ; Chr(13); Waitms 200 S = Inkey() Loop Until S <> 0 Else Ddrd.6 = 1 ' Setta tutti i bit in output Ddrd.5 = 1 Ddrb.5 = 1 Ddrf.0 = 1 If V = "3" Then Print "Questo segnale e' collegato all'uscita open collector di interrupt dell'RTC" Print "a bordo della GMM AM128. Non puo' essere usato come uscita." Print "Premere tasto per uscire" C = Waitkey() Else Do Print "Stato pin (0/1; 2 esce): "; C = Waitkey() Print Chr(c) C = C - "0" ' Converte in numero If C <> 2 Then Vbit = C.0 If V = "1" Then Portd.6 = Vbit ' Pin 2 di CN7 End If If V = "2" Then Portd.5 = Vbit ' Pin 3 di CN7 End If If V = "4" Then Portb.5 = Vbit ' Pin 6 di CN7 End If If V = "5" Then Portf.0 = Vbit ' Pin 8 di CN7 End If End If Loop Until C = 2 End If End If Loop End ' '************************ Fine del programma *************************** ' ' ' '****************************************************************************** '* Procedure di gestione degli I/O della GMB HR168 * '****************************************************************************** ' ' ' ' Inizializza il demo ' Sub Init() ' Inizializza la direzionalita' dei port che pilotano gli ingressi optoisolati ' e le uscite a rele': ' 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 (di default, ovvero con J10 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 ' ' ' Imposta le uscite a rele' ' Se il Bit e' 1 il corrispondente rele' viene chiuso, altrimenti viene aperto ' 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 (di default, ovvero con J10 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 ' '****************************************************************************** '* Procedure di uso generico * '****************************************************************************** ' ' ' Funzione di supporto della Check_ready(). ' Function Check_ready_2() As Byte Local Time_out As Word , I A s Byte Time_out = 0 ' Contatore timeout Do Incr Time_out ' Incrementa contatore Loop Until Twcr.twint = 1 Or Time_out = Ee_timeout I = Twsr I = I And &HF8 Check_ready_2 = I End Function ' ' ' Controlla che la scheda sia pronta ' Sub Check_ready() Local Check As Byte , Test As Byte Do ' Ciclo attesa scheda pronta 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