' ********************************************************************** ' * File gmbiot.bas - Rel. 1.1 con Bascom 8051 DEMO IDE e LIB 2.0.11.0 * ' * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * ' * Scheda: GMB HR168 + GMM AC2 * ' * Tel. +39 051 892052 Fax. +39 051 893661 * ' * http://www.grifo.com http://www.grifo.it * ' * sales@grifo.it tech@grifo.it grifo@grifo.it * ' * by Graziano Gaiba del 24.02.04 * ' ********************************************************************** ' ' 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). ' Qualora la linea scelta sia associata ' all'interrupt del Real Time Clock del Mini Modulo o della GMB HR168, ' la gestione avviene tramite questa periferica. ' ' ' ' !!!!!!!!!!!!!!!!!!!!! ATTENZIONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' Nel menu Options/Compiler/Misc impostare: ' - Byte End(hex) ad almeno A0 ' ' ' 24.02.04 - Rel 1.1 By Graziano Gaiba ' ' Il file compilato non supera i 2048 bytes, quindi puo' essere ' compilato con il demo gratuito di BASCOM 8051. ' ' '****************** Direttive del compilatore ************************** ' $regfile = "89c51ac2.dat" $romstart = &H0 ' indirizzo di partenza del codice ' macchina per FLASH $ramstart = &H0 ' indirizzo di partenza della area ' dati $ramsize = &H100 ' pongo a 256 bytes la area dati $crystal = 14745600 ' frequenza di clock del microcontrollore $baud = 19200 ' velocità di comunicazione RS-232 '$large ' indirizzamento a 16 bit ' solo se si non usa la versione demo $map ' Genera una mappa degli indirizzi ' per ogni linea di codice ' ' '****************** 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 ' ' '****************** Dichiarazione delle variabili ********************** ' ' Uso generico Dim S As Byte , V As Byte , T As Byte Dim S1 As String * 1 Dim S0 As Bit ' ' '****************** Dichiarazione delle procedure ********************** ' Declare Sub Init() ' Inizializzazione Declare Sub Setp1234input() ' Setta in input tutti i port ' ' '************************* Programma main ****************************** ' Main: Call Init() ' Inzializza il modulo Print Chr(clrscr) Print "Demo 1.1 per GMB HR168 ds 110104" Do Print Print "Su CN7 questi pin sono I/O TTL:" Print Print "1) Pin 2" Print "2) Pin 3" Print "3) Pin 4" Print "4) Pin 6" Print Print "Scelta: "; Do V = Inkey() Loop Until V >= "1" And V <= "4" Print Chr(v) S1 = "" If V = "3" Then Print "Il pin 4 e` collegato all'interrupt RTC opzionale, se e' presente puo`:" Print "generare onde quadre a diversi periodi, altrimenti e' un normale I/O TTL." Print "Il LED LD28 della GMB HR168 visualizza la linea." Print "L'RTC opzionale e' presente (S/N)? "; Do S1 = Waitkey() Print S1; S1 = Ucase(s1) Loop Until S1 = "S" Or S1 = "N" End If If V = "3" And S1 = "S" Then Call Setp01234input() ' Setta tutti i port in input Print Print "Premere tasto per uscire" Print "Stato pin 4:" Do Print P2.5 ; Chr(13); Waitms 200 S = Inkey() Loop Until S <> 0 Else Print Print "Input/Output (I/O)? "; Do T = Inkey() ' Attesa sospensiva di un tasto Loop Until T <> 0 Print Chr(t) T = T Or &H20 ' Converte in minuscolo If T = "i" Then Call Setp01234input() ' Setta tutti i port in input Print "Premere tasto per uscire" Print "Stato pin:" Do If V = "1" Then S0 = P2.6 ' Pin 2 di CN7 End If If V = "2" Then S0 = P2.7 ' Pin 3 di CN7 End If If V = "3" Then S0 = P2.5 ' Pin 4 di CN7 End If If V = "4" Then S0 = P1.3 ' Pin 6 di CN7 End If Print S0 ; Chr(13); Waitms 200 S = Inkey Loop Until S <> 0 Else Do Print "Stato pin (0/1,2 esce): "; Do T = Inkey() Loop Until T <> 0 Print Chr(t) T = T - 48 ' Converte da carattere numerico a valore If T = 0 Or T = 1 Then S0 = T.0 If V = "1" Then P2.6 = S0 ' Pin 2 di CN7 End If If V = "2" Then P2.7 = S0 ' Pin 3 di CN7 End If If V = "3" Then P2.5 = S0 ' Pin 4 di CN7 End If If V = "4" Then P1.3 = S0 ' Pin 6 di CN7 End If End If Loop Until T = 2 End If End If Loop End ' '************************ Fine del programma *************************** ' ' '**************************** Procedure ******************************** ' ' ' Inizializza il demo ' Sub Init() Disable Interrupts ' Disabilita gli interrupts Ckcon = &H00 ' Setta X1 clock mode = standard mode Auxr = &H0C ' Seleziona Eram Su Area Dati Esterna Eecon = &H00 ' Disabilita Eeprom Del Micro End Sub ' ' ' Setta in input tutti i port ' Sub Setp01234input() P0 = &HFF ' Setta P10 in input S = P0 Adcf = &H00 ' Setta tutto P1 come I/O P1 = &HFF ' Setta P1 in input S = P1 P2 = &HFF ' Setta P2 in input S = P2 P3 = &HFF ' Setta P3 in input S = P3 P4 = &HFF ' Setta P4 in input S = P4 End Sub