Peripheral myIO As IOExtenderA @ 0 'Set module number to 0 Dim PinLevel As Byte 'Store pin status Dim CountStop As Byte 'Store counter - Stop the status Dim ChValue As Word 'Store the analog to digital converted value Dim TimeUp As Byte 'Store the status when time is up Sub Main() myIO.High(0) 'Output a high voltage on Pin 0 myIO.Low(1) 'Output a low voltage on Pin 1 myIO.In(2, PinLevel) 'Get the input voltage on Pin 2 myIO.PulseOut(3, 1, 2) 'Output 2ms high voltage waveform on Pin 3 myIO.Toggle(0) 'Invert the output voltage on Pin 0 (from original high voltage into low voltage) myIO.SetDirPort1(0) 'Set all the pins of Port 1 to be used as outputs myIO.EnablePinLowEvent1(16, 0) 'Detect a low going transition on Pin 16 myIO.DisablePinLowEvent1() 'Disable the low voltage detection myIO.SetPFD(1000) 'Set PFD to output 1k Hz waveform myIO.PFDOn() 'Enable PFD output myIO.PFDOff() 'Disable PFD output CountStop=0 myIO.CounterOn(0, 2000, 1) 'Count the number of positive edges on the Counter Pin within 2 seconds ' The following loop will be exited only when the counter stops Do Loop Until CountStop>0 myIO.CounterOff() 'Disable the counter myIO.SetPWM1(4, 128) 'Output a PWM waveform on Pin 4 with a Duty Cycle of 0.5 (128/256) myIO.PWM1On() 'Enable the PWM1 output myIO.PWM1Off() 'Disable the PWM1 output myIO.SetADC (1) 'Enable PA0 as the input for ADC conversion myIO.GetADC (0, ChValue) 'Get the converted digital value from the analog input on CH0 and store in ChValue myIO.SetTimer(0, 1000) 'Set the timer to count down for 1 second TimeUp=0 myIO.TimerOn() 'Activate the timer ' The following loop will be exited only when the timer is up Do Loop Until TimeUp>0 myIO.TimerOff() 'Disable the timer End Sub Event MyIO.PinLowEvent1() Debug "Appear when the Low voltage is detected!", CR End Event Event MyIO.CounterStopEvent() Debug "Counter stops!", CR CountStop=1 End Event Event MyIO.TimerOverflowEvent() Debug "Timer is up!", CR TimeUp=1 End Event