traficlights.m

来自「daqaxis help for national instruments」· M 代码 · 共 42 行

M
42
字号
function ITraficLights
% A program to simulate Trafid Lights on the Bytronic LED's
% Set Switch3 0010 Switch4  1000
% Switch5 R  Switch 6 R Switch 7 R 
% Initialise parallel port
    base = 888;         %base address for LPT1;
	disp('Hello Bytronics')

    % send control word to set ports to correct
	% input and output status
    % Port A,B,CH,CL     1 in  0 out
	PortModeSet(base,1,0, 1, 1);

	% loop around this section of the programme until
	% positive number entered
    x=0;
	while x<1
        PPIOutVal(base,1);  % Green
        inport= PPIInpVal(base);
        green=bitand(inport,7) + 2;  % 1 + 2 + 4 = 7  Switched bits 0,1,2
        red=bitand(inport,56) / 8 + 2;  % 8 + 16 + 32 = 56 Switched bits  3,4,5
        Double=bitand(inport,64) / 64 + 1;  % 1 or 2
        delay(Double*green);
        PPIOutVal(base,2);  % Amber
        delay(1);
        PPIOutVal(base,4);  % Red
        delay(Double*red);
        PPIOutVal(base,6);  % Red & Amber
        inport= PPIInpVal(base);
        if bitand(inport,128) 
			disp('Bit 7 set high - exit routine activated');
            break;    
        end;
        delay(1);
    end;
	





⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?