'' ******************************** '' * Virtual IO object / demo * '' ******************************** '' '' Emulates LEDs and Switches on four 8 pin-groups and shows a (slow) Logic-Scope view. '' With a Switch you can set a pin to output Low or High or as an input (mid position). '' You have a LED on every Pin that lights at a High level. '' Needs PropTerminal.exe on the PC to show the Graphic. Operates per mouse, so '' you can still use the PC_Keyboard object together with TV or VGA for your Application. '' '' Author.... Andy Schenk, Insonix '' Date...... 31 MAY 2007 '' Buttons: '' [n..m] = change pin group '' [start] / [stop] = start or stop the logic scope view '' [single] = wait for a change on a pin, then start logic scope for 1 screen and stop '' [n s/div] = change Timebase '' Switches: [O ] =Low out [ O ] = Input [ O] = High Out CON #0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY 'Standard colors VAR long basepin, srate, dtime long newa, olda, ins, outs, run long ab, dbg long cog long stack[64] OBJ term : "PC_Interface" ' Display & Mouse driver '{------ Demo code (delete the ' to make an object) ------ CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 _stack[200] PUB main 'Demo dira[1..2] := 3 'init I/Os outa[2] := 1 start(0,1) 'basepin, rate (sec/div) repeat !outa[1..2] 'toggling pin 1&2 with 2 Hz waitcnt(clkfreq/2 + cnt) '---------------------------------------------------------} PUB start(pin, rate) : okay '' Starts I/O object '' -- returns true if all parameters okay '' pin is the basepin for the 8 pin I/O-group '' rate ist the scope timebase in sec/div (1..99) basepin := pin srate := rate #> 1 okay := term.start(31,30) 'start display/mouse driver okay &= cog := cognew(do_io, @stack) 'start supervisor cog PUB stop '' Stops object term.stop PUB do_io | i,x '' show 8 pins as LEDs on the display with a scope view '' move switches on mouseclicks '' updates all 1/20 seconds runs in seperate cog ins := !dira outs := outa run := 1 repeat if run term.out(0) show_switches show_grid show_param dtime := cnt repeat x from 57 to 311 step 2 repeat srate newa := ina show_pins(x) olda := newa if term.button(0) editpar dtime := cnt if ab quit if run waitcnt(dtime += clkfreq*2/32) else waitcnt(clkfreq/40 + cnt) if ab ab := 0 quit if run==3 run := 0 show_param if run==2 olda := ina & $3F< olda if term.button(0) quit run := 3 PRI show_grid | i term.setcol(BLUE) repeat i from 56 to 312 step 32 term.plot(i,34) term.drawto(i,170) repeat i from 34 to 170 step 17 term.plot(56,i) term.drawto(312,i) PRI show_param term.setcol(YELLOW) 'title term.locate(56,0) term.str(String("Virtual Switches & LEDs")) term.setcol(WHITE) term.locate(0,17) term.str(String("L z H")) term.clrbox(0,186,314,20) term.locate(160,187) 'Start/Stop button if run term.str(String("Stop")) else term.str(String("Start")) term.locate(96,187) term.str(String("Single")) term.rbox(93,186,54,19) term.rbox(150,186,56,19) term.locate(8,187) term.dec(basepin) term.str(String("..")) 'pin group term.dec(basepin+7) term.rbox(4,186,55,19) term.locate(248,187) term.dec(srate) term.str(String(" s/div")) 'timebase term.rbox(235,186,80,19) term.setcol(CYAN) PRI show_pins(xp) | i,m,y m := |< basepin repeat i from 34 to 160 step 17 if newa <> olda if newa & m == 0 term.setcol(BLUE) term.circle(46,i+8,6) else term.setcol(RED) term.circle(46,i+8,6) term.setcol(YELLOW) term.circle(48,i+6,2) term.setcol(CYAN) if run y := olda&m <> 0 term.plot(xp, y*8+12+i) term.plot(xp+1, y*8+12+i) y := newa&m <> 0 term.drawto(xp+1, y*8+12+i) m <<= 1 ' term.locate(220,0) ' term.dec(dbg) PRI show_switches | i,m m := |< basepin repeat i from 34 to 160 step 17 term.setcol(GRAY) term.box(2,i+2,32,12) term.clrbox(8,i+4,20,8) term.setcol(WHITE) if ins & m term.box(16,i+4,5,8) else if outs & m term.box(22,i+4,5,8) else term.box(9,i+4,5,8) m <<= 1 PRI editpar ab := 1 case term.abs_x 0..56: case term.abs_y 34..160 : edit_switches ab := 0 185..205: term.invbox(4,186,55,19) 'pin group basepin += 8 if basepin > 24 basepin := 0 150..206: term.invbox(150,186,56,19) 'Start/Stop run ^= 1 run &= 1 93..146: term.invbox(93,186,54,19) 'Single run := 2 238..312: term.invbox(235,186,80,19) 'Timebase srate *= 5 if srate > 25 srate := 1 repeat until !term.button(0) show_param PRI edit_switches | ma ma := (term.abs_y-34) / 17 + basepin ma := 1 << ma ins &= !ma case term.abs_x 4..14 : outs &= !ma 15..22: ins |= ma 23..32: outs |= ma ins |= |< 31 dira := !ins outa := outs show_switches