;***************************************************** ; Listing 1 -- PC-controlled light dimmer ; "PC controls light dimmer," EDN, ; August 19, 1999, pg 140 ;***************************************************** Program proj1; uses CRT,Strings; procedure writedata(dword : longint); var wraddr,readdr,strbaddr : word; pPrintPort : ^word; rdta,ibte,bit,n : byte; to20,to28,num,data : longint; begin pPrintPort := Ptr($40,$08); wraddr := pPrintPort^; to20:=$100000; to28:=$10000000; num:=to20*$40 + dword; writeln('data= ',num); PORT[wraddr]:=$97; {initialize to cs=0, sclk=0, sdin=1} for n:= 1 to 32 do begin ibte:=PORT[wraddr]; PORT[wraddr]:= ibte OR 64; {set sclk=1} num:=num*2; bit:=0; if num >= to28 then begin bit:=1; num:=num-to28; end; ibte:=PORT[wraddr]; if bit = 0 then PORT[wraddr]:= ibte AND 239 {set sdin=0} else PORT[wraddr]:= ibte OR 16; {set sdin=1} ibte:=PORT[wraddr]; PORT[wraddr]:= ibte AND 191; {set sclk=0} end; end; {***********************main********************} var inpkey : char; num,num1 : longint; label start; begin num := 0; start: inpkey := readkey; if inpkey = 'q' then begin if (num+$1000)>$7fff0 then num:=$7fff0 else num:=num+$1000; end; if inpkey = 'w' then begin if (num-$1000)<-$7fff0 then num:=-$7fff0 else num:=num-$1000; end; if inpkey = 'x' then exit; if num<0 then num1:=$fffff+num else num1:=num; writedata(num1); goto start end.