' ********************************************************************** ' ** Program : gmbiote.bas - Version : 1.1 - 03 March 2004 ** ' ** Compiler : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Board : GMB HR168 with GMM AC2 ** ' ** Corporate: 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 ** ' ** sales@grifo.it tech@grifo.it grifo@grifo.it ** ' ** ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' This demo allows to use immediatly TTL I/O digital lines available on CN7. ' 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. ' ' ' ' Rel. 1.1 03.03.04 - By Graziano Gaiba ' ' ' ' !!!!!!!!!!!!!!!!!!!!!!! ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options/Compiler/Misc set: ' - Byte End(hex) at least A0 ' '****************** Compiler directives ************************** ' $regfile = "89c51AC2.dat" $romstart = &H0 ' start address of code for FLASH $ramstart = &H0 ' start address of external RAM $ramsize = &H100 ' 256 bytes of external RAM $crystal = 14745600 ' Microcontroller clock $baud = 19200 ' RS-232 baud rate '$large ' 16 bit addressing for jumps ' (Not for demo version) $map ' Generates address map ' ' '****************** 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 S0 As Bit Dim S1 As String * 1 ' Inputs Dim In As Byte ' Interrupts counters Dim Cntintr1 As Byte , Cntintr2 As Byte , Cntintt0 As Byte ' ' '********************* Procedures declaration ************************** ' Declare Sub Setp01234input() ' Set all ports as input ' '************************** Main program ****************************** ' Main: Disable Interrupts ' Disabiles interrupts Ckcon = &H00 ' Set X1 clock mode = standard mode Auxr = &H0C ' Selects Eram on external data area Eecon = &H00 ' Disables Eeprom of Micro Call Setp01234input() Do Print Chr(clrscr) Print "On CN7 these pin are 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 <> 0 Print Chr(v) If V <> "0" Then S1 = "" If V = "3" Then Print "Pin 4 is connected to optiona Real Time Clock interrupt; if present it can:" Print "generate square waves; activate every enth,second,minute,hour,day" Print "or at a preset time." Print "Otherwise it is a normal I/O TTL, LED LD28 of GMB HR168 shows its status." Print "Is the RTC present (Y/N)? "; Do S1 = Waitkey() Print S1; S1 = Ucase(s1) Loop Until S1 = "Y" Or S1 = "N" End If If V = "3" And S1 = "Y" Then Call Setp01234input() ' Set all port as input Print Print "Press a key to exit." Print "Status of 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() ' Wait for a key Loop Until T <> 0 Print Chr(t) T = T Or &H20 ' Convert to lower case If T = "i" Then Call Setp01234input() ' Set all ports in input Print "Press a key to exit." Print "Pin status :" Do If V = "1" Then S0 = P2.6 ' Pin 2 of CN7 End If If V = "2" Then S0 = P2.7 ' Pin 3 of CN7 End If If V = "3" Then S0 = P2.5 ' Pin 4 of CN7 End If If V = "4" Then S0 = P1.3 ' Pin 6 of CN7 End If Print S0 ; Chr(13); Waitms 200 S = Inkey Loop Until S <> 0 Else Do Print "Pin status (0/1,2 exit): "; Do T = Inkey Loop Until T <> 0 Print Chr(t) T = T - 48 ' Converts from numeric character to a value If T = 0 Or T = 1 Then S0 = T.0 If V = "1" Then P2.6 = S0 ' Pin 8 of CN7 End If If V = "2" Then P2.7 = S0 ' Pin 6 of CN7 End If If V = "3" Then P2.5 = S0 ' Pin 3 of CN7 End If If V = "4" Then P1.3 = S0 ' Pin 2 of CN7 End If End If Loop Until T = 2 End If End If End If Loop End ' '************************ Program end *************************** ' ' '**************************** Procedures ******************************** ' ' ' ' Set all ports as input ' Sub Setp01234input() P0 = &HFF ' Set P0 as input S = P0 Adcf = &H00 ' Set P1 as I/O P1 = &HFF ' Set P1 as input S = P1 P2 = &HFF ' Set P2 as input S = P2 P3 = &HFF ' Set P3 as input S = P3 P4 = &HFF ' Set P4 as input S = P4 End Sub