' ********************************************************************** ' ** Program: gmbiobe.BAS - Version : 1.1 - 14 June 2005 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Board : GMB HR168 and GMM AM32 ** ' ** 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 ** ' ********************************************************************** ' ' 14.06.05 - Rel 1.1 By Graziano Gaiba ' This demo allows to use immediately relays outputs available on CN3 ' and CN4 and buffered inputs available on CN1 and CN2. ' Through the console can be set the status of the four output relays ' or it can visualize the status of the eight NPN/PNP inputs. ' In addition, high level functions available on Mini Module are used: ' outputs driven by periodic automatic signals, inputs that generate ' interrupts, inputs counted by hardware, etc. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options | Compiler | Chip, set: ' ' Chip: M32 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' $regfile = "m32def.dat" $crystal = 7372800 $baud = 19200 On Int0 Risp_int0 Nosave On Int1 Risp_int1 Nosave On Timer0 Risp_int_t0 Nosave ' ' ********************* Constans declarations ************************* ' 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 ' '****************** Variables declaration ********************** ' ' Generic use Dim V As Byte , S As Byte , T As Byte Dim A As Eram Byte At 1023 ' Interrupts counter Dim Cntintr1 As Byte , Cntintr2 As Byte , Cntintt0 As Byte ' '********************** Procedures declaration ************************* ' Declare Sub Init() ' Initialization Declare Sub Set_relays_out(byval V As Byte) ' Set relays status Declare Function Get_opto_in_a() As Byte ' Read inputs Opto A Declare Function Get_opto_in_b() As Byte ' Read inputs Opto B Declare Sub Richiedi_tasto() Declare Function Leggi_attesa() As Byte Declare Sub Check_ready() ' '**************************** Main program ****************************** ' Main: Call Init() ' Initialize module Do Call Set_relays_out(0) Print Chr(clrscr); ' Clears the screen Print "Demo 1.1 for GMM AM32 + GMB HR168" Print Call Check_ready() Do Print Chr(clrscr) Print "Example on how to use inputs on CN6 and outputs on CN1" Print Print "1) Digital inputs" Print "2) Relays outputs" Print Print "SELECT: "; Do V = Inkey() Loop Until V <> 0 Print Chr(v) If V = "1" Then Print "Optocoupled inputs on CN6" Do Call Richiedi_tasto() Print "CN1 CN2" Do T = Get_opto_in_a() Print Hex(t) ; " "; T = Get_opto_in_b() Print Hex(t) ; " "; Printbin Cret S = Leggi_attesa() Loop Until S <> 0 Print Print Print "IN3 is also trigger for int0, IN4 for int1." Print "A transition H-L activates interrupt which increments its counter." Call Richiedi_tasto() Print "INT0 INT1" Mcucr.0 = 0 ' Int0 triggers on falling edge Mcucr.1 = 1 Mcucr.2 = 0 ' Int1 triggers on falling edge Mcucr.3 = 1 Enable Int0 ' Enables int0 Enable Int1 ' Enables int1 Enable Interrupts ' Enables interrupts Cntintr1 = 0 ' Resets interrupt counters Cntintr2 = 0 Do Print Hex(cntintr1) ; " " ; Hex(cntintr2) ; ' Prints interrupt counters Printbin Cret ' Back to line beginning S = Leggi_attesa() Loop Until S <> 0 ' Exits when key pressed Disable Interrupts ' Disables interrupts Disable Int0 ' Disables int0 Disable Int1 ' Disables int1 Loop Until S <> 0 Print Print Print "T0 is configured as counter, IN5 is its trigger" Print "Every overflow generates an interrupt" Call Richiedi_tasto() Cntintt0 = 0 ' ALWAYS stop a timer before changing its parameters Stop Timer0 ' Configure timer 0 as counter, triggered on H->L transitions of pin T0. Config Timer0 = Counter , Edge = Falling Counter0 = &HD0 ' Starting value Enable Timer0 ' Enables interrupt overflow of timer 0 Enable Interrupts ' Enables interrupts Start Timer0 Print "T0 N.INT" Do Print Hex(counter0) ; " " ; Hex(cntintt0); 'Prints counter ' Reading counter0 automatically stops timer0, must be restarted Start Timer0 Printbin Cret ' Back to line beginning S = Leggi_attesa() Loop Until S <> 0 ' Exits when key pressed Disable Interrupts Disable Timer0 Stop Timer0 End If If V = "2" Then Print Chr(clrscr); Print "Demo relays outputs" Print Do Inputhex "Type hex value (00 exits): " , S Print Hex(s) Call Set_relays_out(s) ' Set outputs Loop Until S = 0 End If Loop Loop Risp_int0: Incr Cntintr1 ' Increment interrupt counter Return Risp_int1: Incr Cntintr2 ' Increment interrupt counter Return Risp_int_t0: Incr Cntintt0 ' Increment interrupt counter Return End ' '************************ Program end *************************** ' ' '****************************************************************************** '* 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 ' V.0 controls RL1 ' V.1 controls RL2 ' V.2 controls RL3 ' V.3 controls RL4 ' V.4 controls RL5 ' V.5 controls RL6 ' V.6 controls RL7 ' V.7 controls RL8 Sub Set_relays_out(byval V As Byte) Portd.6 = Not V.0 Portb.4 = Not V.1 Portb.2 = Not V.2 Portb.3 = Not V.3 Portb.5 = Not V.4 Portb.6 = Not V.5 Portb.7 = Not V.6 Porta.6 = Not V.7 End Sub ' ' ' Reads optocoupled inputs of CN2 ' Function Get_opto_in_a() As Byte Local V_in As Byte ' V_in.0 reads IN1A ' V_in.1 reads IN2A ' V_in.2 reads IN3A ' V_in.3 reads IN4A ' V_in.4 reads IN5A ' V_in.5 reads IN6A ' V_in.6 reads IN7A ' V_in.7 reads IN8A V_in.0 = Not Pina.0 V_in.1 = Not Pina.1 V_in.2 = Not Pind.2 V_in.3 = Not Pind.3 V_in.4 = Not Pinb.0 V_in.5 = Not Pinb.1 V_in.6 = Not Pina.2 V_in.7 = Not Pina.3 Get_opto_in_a = V_in End Function ' ' ' Reads optocoupled inputs of CN1 ' Function Get_opto_in_b() As Byte Local V_in As Byte ' V_in.0 reads IN1B ' V_in.1 reads IN2B ' V_in.2 reads IN3B ' V_in.3 reads IN4B ' V_in.4 reads IN5B ' V_in.5 reads IN6B ' V_in.6 reads IN7B ' V_in.7 reads IN8B V_in.0 = Not Pina.4 V_in.1 = Not Pina.5 V_in.2 = Not Pinc.2 V_in.3 = Not Pinc.3 V_in.4 = Not Pinc.4 V_in.5 = Not Pinc.5 V_in.6 = Not Pinc.6 V_in.7 = Not Pinc.7 Get_opto_in_b = V_in End Function ' '****************************************************************************** '* Demo specific procedures * '****************************************************************************** ' ' ' Initializes demo ' Sub Init() ' Initializes directionality of ports that drive optocouped inputs and relay ' outputs: ' IN1-1 - Porta.0 ' IN2-1 - Porta.1 ' IN3-1 - Portd.2 ' IN4-1 - Portd.3 ' IN5-1 - Portb.0 ' IN6-1 - Portb.1 ' IN7-1 - Porta.2 ' IN8-1 - Porta.3 Ddra.0 = 0 Ddra.1 = 0 Ddrd.2 = 0 Ddrd.3 = 0 Ddrb.0 = 0 Ddrb.1 = 0 Ddra.2 = 0 Ddra.3 = 0 ' IN1-2 - Porta.4 ' IN2-2 - Porta.5 ' IN3-2 - Portc.2 ' IN4-2 - Portc.3 ' IN5-2 - Portc.4 ' IN6-2 - Portc.5 ' IN7-2 - Portc.6 ' IN8-2 - Portc.7 Ddra.4 = 0 Ddra.5 = 0 Ddrc.2 = 0 Ddrc.3 = 0 Ddrc.4 = 0 Ddrc.5 = 0 Ddrc.6 = 0 Ddrc.7 = 0 ' OUT A1 - Portd.6 ' OUT A2 - Portb.4 ' OUT B1 - Portb.2 ' OUT B2 - Portb.3 ' OUT C1 - Portb.5 ' OUT C2 - Portb.6 ' OUT D1 - Portb.7 ' OUT D2 - Porta.6 (by default, that is when J10 is connected in 3-4) Ddrd.6 = 1 Ddrb.4 = 1 Ddrb.2 = 1 Ddrb.3 = 1 Ddrb.5 = 1 Ddrb.6 = 1 Ddrb.7 = 1 Ddra.6 = 1 End Sub ' '****************************************************************************** '* Generic procedures * '****************************************************************************** ' ' ' ' Prints "Press a key to exit" ' Sub Richiedi_tasto() Print Print "Press a key to exit" Print End Sub ' ' ' Waits for 200 msec then reads a key and returns it ' Function Leggi_attesa() Waitms 200 Leggi_attesa = Inkey() End Function ' ' ' Check for hardware ready ' Sub Check_ready() Test: If A = &H55 Then Goto L2 Else Goto Test End If L2: End Sub