' ********************************************************************** ' ** Program : gmbiote.bas - Version : 1.2 - 19 November 2004 ** ' ** Compiler : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Board : GMB HR84 with GMM 935 ** ' ** 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 ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' This demo allows to use immediatly TTL I/O digital lines available on CN4. ' 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. ' ' 24.06.03 - Rel 1.1 By Graziano Gaiba ' ' 19.11.04 - Rel 1.2 By Graziano Gaiba ' Modified to run on a GMM 932 ' '****************** Compiler directives ************************** 'N.B. In Options | Compiler | Misc perform these settings: ' Register File = 89LPC932.DAT ' Byte End(Hex) = A0 ' Size warining = 7167 $regfile = "89lpc932.dat" $romstart = &H0 ' start address of code for FLASH $ramstart = &H0 ' start address of external RAM $ramsize = &H200 ' 256 bytes of external RAM $crystal = 11059200 ' Maximun 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 Const Rcint = 7372800 ' Internal RC clock frequency Const Qz11m = 11059200 ' External clock frequency ' '****************** Variables declaration ********************** ' General purpose variables Dim I As Byte , V As Byte , S As Byte , T As Byte Dim S0 As Bit Dim Hlpb As Byte , M As Byte ' General purpose Byte Dim Hlpw As Word , Ind As Word ' General purpose Word Dim Hlpl As Long ' General purpose Long Dim Choice As String * 1 ' One char string ' Variables for serial communication Dim St As Byte ' Stop bit number Dim Br As Long ' Serial Buad Rate ' Variables for clock and delays management Dim Cclk As Long ' CPU clock requency Dim D As Word , Del1ms As Word , Del As Word ' Delays management ' Variables for digital I/O ports management Dim M1 As Byte , M2 As Byte , Dir As Byte ' '********************* Procedures declaration ************************** ' Declare Sub Get_clk ' Acquires clock frequency Declare Sub Init ' General initialization Declare Sub Ritardo(del As Word) ' Calibrated delay Declare Sub Iniser(br As Long , St As Byte) ' Serial initialization Declare Sub Check ' Verifies peripherals ' Declare Sub Inidir(dir As Byte) ' Signals direction for CN4 ' '************************** Main program ****************************** ' Main: Call Init ' Initializes the module Call Get_clk ' Acquires CPU clock frequency Call Iniser(19200 , 1) ' Initializes serial for console ' Performs a delay of about 2 seconds to allows the presence of emulation ' terminal program for console (i.e. HYPERTERMINAL) and contemporaneosly blinks ' the activity LED DL1 of the card. ' Uses general purpose variable i P0m1 = P0m1 Or &H40 ' Sets P0.6 in mode 3=OpenDrain P0m2 = P0m2 Or &H40 For I = 1 To 16 ' 16 cycles of 125 msec=2 sec P0.6 = Not P0.6 ' Complements activity LED Call Ritardo(125) ' Delays about 125 msec Next I Print Chr(clrscr); ' Clear screen Print "Demo 1.2 for GMM932 ds300803 + GMBHR84 ds220503" Call Check ' Internal check Print Do Print Print "1) Pin 8 (pull down of 4,7 Kohm always present)" Print "2) Pin 6" Print "3) Pin 2" Print "4) Pin 3" Print "5) Pin 5" Print Print "Choice: "; Do V = Inkey Loop Until V <> 0 Print Chr(v) 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 ' Sets all signals of CN4 in quasi-bidirectional Call Inidir(0) Print "Press a key to exit" Print "Signal status:" Do If V = "1" Then S0 = P2.4 ' Pin 8 of CN4 End If If V = "2" Then S0 = P2.6 ' Pin 6 of CN4 End If If V = "3" Then S0 = P2.5 ' Pin 2 of CN4 End If If V = "4" Then S0 = P2.2 ' Pin 3 of CN4 End If If V = "5" Then S0 = P2.3 ' Pin 5 of CN4 End If Print S0 ; Chr(13); Waitms 200 S = Inkey Loop Until S <> 0 Else ' Sets all signals of CN4 in push pull Call Inidir(1) Do Print "Set signal (0/1,2 to exit): "; Do T = Inkey Loop Until T <> 0 Print Chr(t) T = T - 48 ' Converts from char to its numeric value If T = 0 Or T = 1 Then S0 = T.0 If V = "1" Then P2.4 = S0 ' Pin 8 of CN4 End If If V = "2" Then P2.6 = S0 ' Pin 6 of CN4 End If If V = "3" Then P2.5 = S0 ' Pin 2 of CN4 End If If V = "4" Then P2.2 = S0 ' Pin 3 of CN4 End If If V = "5" Then P2.3 = S0 ' Pin 5 of CN4 End If End If Loop Until T = 2 End If Loop End ' '************************ Program end *************************** ' ' '**************************** Procedures ******************************** ' ' ' '*********************** Procedure gestione Port I/O *************************** ' Inizializes all 8 signals of CPU connected to pins of CN4 on GMB HR84: ' pin 2 -> P2.5 pin 3 -> P2.2 pin 5 -> P2.3 pin 6 -> P2.6 pin 8 -> P2.4 ' I/O mode passed in parameter dir(0..3) is set, leaving untoched the status of ' all other signals. ' Possible values for dir are: ' 0 : Set all signals as Quasi-bidirectional output ' 1 : Set all signals as Push Pull ' 2 : Set all signals as Input only (high impedance) ' 3 : Set all signals as Open Drain Sub Inidir(dir As Byte) M1 = P2m1 M2 = P2m2 Select Case Dir Case 0 : ' Quasi-bidirectional output M1 = M1 And &H83 M2 = M2 And &H83 Case 1 : M1 = M1 And &H83 ' Push Pull M2 = M2 Or &H7C Case 2 : M1 = M1 Or &H7C ' Input only (high impedance) M2 = M2 And &H83 Case 3 : M1 = M1 Or &H7C ' Open Drain M2 = M2 Or &H7C End Select P2m1 = M1 P2m2 = M2 End Sub ' ' '********************** General purpose subroutines **************************** ' Reads the configuration byte UCFG1 on FLASH thanks to IAP procedures of ' P89LPC932 Boot Rom. Returns the global variable cclk set with the CPU clock ' frequency, with no control of the possible errors. Sub Get_clk mov A,#&H03 ' Uses command Misc. Read mov R7,#&H00 ' Reads register UCFG1 lcall &HFF00 ' Calls IAP proc. at PGM_MTP addr. mov A,R7 ' Saves result anl A,#&H07 ' Masks bits with CPU clock Select Case Acc Case &H00 : Cclk = Qz11m ' Ext. crystal clock frequency Case &H03 : Cclk = Rcint ' Internal RC clock frequency End Select End Sub ' ' ' Inizializza risorse, variabili e periferiche in modo da poter eseguire ' correttamente tutto il programma demo. Sub Init Disable Interrupts ' Disabilita gli interrupts P1m1 = 0 ' Necessario per la seriale RS232 ' IN1 <- P0.0 ' IN2 <- P0.1 ' IN3 <- P0.2 ' IN4 <- P1.4 ' IN5 <- P0.3 ' IN6 <- P0.4 ' IN7 <- P0.5 ' IN8 <- P0.7 ' ' OUT A1 -> P1.6 ' OUT A2 -> P1.7 ' OUT B1 -> P2.1 ' OUT B2 -> P2.7 Pt0ad = 0 ' Set P0.1-5 come as digital I/O. M1 = P0m1 ' Set P0.0-5 and P0.7 as input only. M2 = P0m2 M1 = M1 Or &HDF M2 = M2 And &H40 P0m1 = M1 P0m2 = M2 ' M1 = P1m1 ' Set P1.4 as input only and M2 = P1m2 ' P1.6 and P1.7 as open drain output M1 = M1 Or &HD0 M2 = M2 Or &HC0 M2 = M2 And &HEF P1m1 = M1 P1m2 = M2 ' M1 = P2m1 ' Set P2.1 and P2.7 as M2 = P2m2 ' open drain output M1 = M1 Or &H82 M2 = M2 Or &H82 P2m1 = M1 P2m2 = M2 End Sub ' ' ' Checks right functionality of internal devices with possible remakes. ' Uses general purpose variable st,t,m,ind,hlpw Sub Check Deecon = &H01 T = Peek(&Hff) Deeadr = &HFF T = 1 Ind = &HF7 Do M = Peek(&H07) If M.7 = 1 Then M = M And &H03 Ind = M + &HF8 T = Peek(ind) Else T = 0 End If St = Deecon St = St And &H80 Loop Until St <> 0 T = St St = Deedat Do M = Peek(ind) Incr Ind If Ind = &HFF Then Ind = &HF9 Hlpw = 0 Do Incr Hlpw M = Peek(ind) Loop Until St.0 = 0 Or Hlpw >= 1000 T = T + M Hlpw = Ind + T M = Peek(t) If St = 0 Then Incr T Else Call Ritardo(1) ' 1 msec pause End If Loop Until St = 0 End Sub ' ' ' Performs a calibrated delay long as many milliseconds as specified in the ' passed parameter del, according with the clock frequency saved in cclk ' variable, with no use of BASCOM instructions that use a fixed and preset ' value of clock. Sub Ritardo(del As Word) If Cclk = Rcint Then Del1ms = 73 ' Value for 1 msec at 7 MHz Else Del1ms = 110 ' Value for 1 msec at 11 MHz End If Do For D = 0 To Del1ms ' Cycle for 1 msec delay Next D Del = Del - 1 Loop Until Del = 0 End Sub ' ' '*********************** Serial management subroutines ************************* ' Initializes the serial line with: ' Bit x chr = 8 ' Stop bit = 1 or 2 according with ST parameter ' Parity = None ' Baud rate = value of BR parameter ' by using the proper baud rate generator of microcontroller and his clock ' frequency saved on global variable cclk. ' Uses general purpose variables hlpw,hlpl Sub Iniser(br As Long , St As Byte) Pcon = Pcon And &HBF ' Resets bit SMOD0 to set mode If St = 1 Then Scon = &H52 ' Mode 1 (1 stop),No multiproc,Rx enable Else Scon = &HDA ' Mode 3 (2 stop),No multiproc,Rx enable End If Brgcon = &H02 ' Sets passed baud rate Hlpl = Br * 16 ' Calculates divisor for baud Hlpl = Cclk - Hlpl Hlpl = Hlpl / Br Hlpw = Loww(hlpl) Brgr0 = Low(hlpw) Brgr1 = High(hlpw) Brgcon = &H03 End Sub