Detecting VGA monitor connection
ozpropdev
Posts: 2,792
Here's a idea (shamelessly stolen from Tubular! ) to detect if a VGA monitor is connected to the P2 and where its located.
It simply enables pins with a 1k5 pullup and starts the ADC bitstream as well as a smart pin counter mode.
If a monitor is connected a voltage divider scenario is present and the pin reads lower.
The code returns the VGA base pin or the value 99 if no monitor detected.
It simply enables pins with a 1k5 pullup and starts the ADC bitstream as well as a smart pin counter mode.
If a monitor is connected a voltage divider scenario is present and the pin reads lower.
The code returns the VGA base pin or the value 99 if no monitor detected.
con _1k5_pu = %001 << 11 _adc_pinA_1x = %100011 << 15 _inc_ahigh = %01111 << 1 _mode = _adc_pinA_1x | _1k5_pu | _inc_ahigh dat 'Returns vga monitor basepin in pb 'pb = 99 ,no monitor detected. detect mov pb,#%001_000000 loop wrpin ##_mode,pb '1k5 pullup + adc + inc on A high wxpin ##$FFFF,pb '64k samples wypin #0,pb drvh pb 'enable smartpin and drive pin high setse1 pb 'rising edge event rep #2,#2 'do twice waitse1 'wait for smart pin result rdpin val,pb 'get result from smartpin cmp val,##$3500 wcz if_a wrpin #0,pb 'reset pin drive and adc if_a fltl pb 'reset smart pin if_b and pb,#$3f 'adjust result if_b ret add pb,#8 'next pin base cmp pb,#%001_000000 + 56 wz if_ne jmp #loop _ret_ mov pb,#99 'no monitor detected
Comments
https://en.wikipedia.org/wiki/Display_Data_Channel
Actually, with so many P2 I/O pins, wonder if it makes any sense to use the I2C connection on the VGA monitor...
I thought about this for a second and then decided that almost all monitors take 1080p@60Hz these days, so there's not much to be gained...