This uses a GPIO to detect high or low on the pin, and using weak pull up/down to detect floating lines. And with a normal weak pullup to detect falling edge transitions to show pulsing signals.
Here is the program--
Code: Select all
' Test TIMER0 interrupt
' TIMER0 will interrupt every 2 seconds and print a dot
#if defined LPC1756 || defined LPC1751 || defined LPC1758 || defined LPC4078
#include "LPC17xx.bas"
#elif defined LPC1114
#include "LPC11xx.bas"
#elif defined LPC11U37
#include "LPC11U3x.bas"
#elif defined LPC54102
#include "LPC54102.bas"
#elif defined LPC812
#error -- use SCTIMER.bas for LPC812
#elif defined LPC2103 || defined LPC2138
#include "LPC21xx.bas"
#else
#error -- your CPU does not support thpinIS feature
#endif
#if defined LPC1751 || defined LPC1756 || defined LPC1758 || defined LPC4078
#define LED_PIN 74
#elif defined LPC1114
#define LED_PIN 1
#elif defined LPC11U68
#define LED_PIN 1
#elif defined LPC2138
#define LED_PIN 15
#elif defined LPC54102
#define LED_PIN 31
#elif defined LPC54005
#define LED_PIN 4
#elif defined LPC2103
#define LED_PIN 15
#elif defined SAMD21
#define LED_PIN 13
#elif defined MK20DX128 || defined MK20DX256
#define LED_PIN 13
#elif defined LPC4330
#define LED_PIN 7
#elif defined LPC11U37 || defined LPC1137 || defined LPC11U67
#define LED_PIN 1
#elif defined LPC1768
#error need to define an LED pin for thpinIS board
#elif defined LPC2106
#error thpinIS code has not been ported to the LPC2106
#else
#error undefined CPU type
#endif
dim pinISfloating as integer
dim pinIShigh as integer
dim pinIStoggle as integer
INTERRUPT SUB PINT0_IRQ
pinIStoggle += 1
GPIO_PIN_IST = 1
ENDSUB
dim TMRintCount ' this provides 1/4 duty cycle for floating indication and timing to sample
INTERRUPT SUB TIMER0IRQ
T0_IR = 1 ' Clear interrupt
#if defined LPC2103 || defined LPC2138
VICVectAddr = 0 ' Acknowledge Interrupt
#endif
TMRintCount += 1
if pinIStoggle then
OUT(LED_PIN) = TMRintCount AND &H40
pinIStoggle = 0
elseif pinISfloating then
OUT(LED_PIN) = ((TMRintCount AND 3)<>0)
elseif pinIShigh then
OUT(LED_PIN) = 0
else
OUT(LED_PIN) = 1
endif
if TMRintCount =&H80 then TMRintCount = 0
ENDSUB
SUB ON_TIMER ( msec, dothpinIS )
#if defined LPC1756 || defined LPC1751
TIMER0_ISR = dothpinIS + 1 'set function of VIC -- need the +1 for Thumb operation
T0_PR = 24999 '1 ms prescale
VICIntEnable or= (1<<2) 'Enable interrupt
#elif defined LPC11U37
TIMER0_ISR = dothpinIS + 1 'set function of VIC -- need the +1 for Thumb operation
SYSCON_SYSAHBCLKCTRL OR= (1<<9) ' enable TIMER0
T0_PR = 24999 '1 ms prescale
VICIntEnable OR= (1<<TIMER0_IRQn) 'Enable interrupt
#elif defined LPC1114
TIMER0_ISR = dothpinIS + 1 'set function of VIC -- need the +1 for Thumb operation
T0_PR = 49999 '1 ms prescale
VICIntEnable or= (1<<19) 'Enable interrupt REMEMBER for LPC11xx we swapped 0/1 with 2/3
#elif defined LPC2103 || defined LPC2138
VICVectAddr7 = dothpinIS ' set function of VIC 7
VICVectCntl7 = $25 ' use it for TIMER0 Interrupt:
VICIntEnable = $20 ' Enable TIMER0 Interrupt
#elif defined LPC54102
TIMER0_ISR = dothpinIS + 1 'set function of VIC -- need the +1 for Thumb operation
ASYNCAPBCLKCTRLSET = SYSCON_CLOCK_TIMER0 ' enable TIMER0
T0_PR = 12499 '1 ms prescale
VICIntEnSet0 = (1<<TIMER0_IRQn) 'Enable interrupt
#else
#endif
T0_MR0 = msec-1 ' set up match number of ms
T0_MCR = 3 ' Interrupt and Reset on MR0
T0_IR = 1 ' clear interrupt
T0_TC = 0 ' clear timer counter
T0_TCR = 1 ' TIMER0 Enable
#if defined LPC2103 || defined LPC2138
VICVectAddr = 0 ' Acknowledge Interrupt
#endif
ENDSUB
#ifndef LPC11U37
#error -- this code has not been ported to other devices yet
#endif
#define TEST_INPUT 61
#define TEST_INT 53 ' which interrupt pin
#define TEST_IOCON IOCON_PIO1_29
#define TEST_PULLDOWN &H28 ' and hystersis
#define TEST_PULLUP &H30
#define TEST_PULL_MASK &Hffffffe7
dim wasHIGH
main:
IO(LED_PIN) = 0 ' make it an output
ON_TIMER(2 , ADDRESSOF TIMER0IRQ) ' used to modulate the LED
' TXD(0)=">"
SYSCON_PINTSEL(0) = TEST_INT ' interrupt on GPIO1.19
SYSCON_SYSAHBCLKCTRL OR= ((1<<19) OR (1<<6)) ' enable GPIO interrupts
FLEX_INT0_ISR = (ADDRESSOF PINT0_IRQ) + 1 'set function of VIC -- need the +1 for Thumb operation
GPIO_PIN_SIENF = 1 ' interrupt on falling edges
VICIntEnable OR= (1<<FLEX_INT0_IRQn) 'Enable interrupt
TEST_IOCON = (TEST_IOCON AND TEST_PULL_MASK) OR TEST_PULLUP ' leave it pulled up
WHILE (1)
if (TMRintCount = 0) then
wasHIGH = IN(TEST_INPUT)
if pinIStoggle then
pinISfloating = 0
' TXD(0)="T"
' print pinIStoggle
elseif wasHIGH then
TEST_IOCON = (TEST_IOCON AND TEST_PULL_MASK) OR TEST_PULLDOWN ' pin is high, try to pull it weakly low
if IN(TEST_INPUT) <> wasHIGH then
pinISfloating = 1
' TXD(0)="F"
else
pinISfloating = 0
pinIShigh = 1
' TXD(0)="H"
endif
TEST_IOCON = (TEST_IOCON AND TEST_PULL_MASK) OR TEST_PULLUP ' leave it pulled up
else
pinISfloating = 0
pinIShigh = 0
' TXD(0)="L"
endif
pinIStoggle = 0
endif
LOOP