Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function keypad (action) %callback function for the GUI
- persistent binaryout;
- switch(action)%switch through each button
- case('Start')
- %define the header lines
- dio=digitalio('mcc', 1);
- %output line
- addline(dio, 0:3,2,'Out');
- %input lines
- addline(dio, 0:2, 0, 'In');
- addline(dio, 4:7, 0, 'In');
- addline(dio, 1, 3, 'In');
- %initialize
- b_Start = findobj('Tag', 'btnStart');
- set(b_Start, 'UserData', 1);
- h_bin_out = findobj('Tag', 'Bin_Data_Out');
- %grab the Binary Data Recieved Box
- t_In = findobj('Tag', 'txtReceived');
- while(get(b_Start, 'UserData') == 1)
- putvalue(dio.Line(1:4), binaryout);
- %see if the dio needs to be reconfigured
- flow = dio.Line(12).Direction;
- if (isequal(binaryout,[0 1 0 1]) && strcmp(flow, 'Out'))
- reconfigure(dio, '0'); %reconfigure for input
- elseif (isequal(binaryout,[1 1 0 0]) && strcmp(flow, 'In'))
- display('here');
- reconfigure(dio, '1'); %reconfigure for output
- end
- %grab the input value
- %in_value1 = getvalue(dio.Line(5:12));
- % if (isequal(binaryout,[0 1 0 1]))
- %convert the vector to string
- % in_value = flip(transpose(dec2hex(in_value1)));
- % else
- %convert the vector to string
- %in_value = transpose(dec2hex(in_value1));
- %end
- %update the output textfield
- %set(t_In, 'String', in_value);
- %update the output textfield
- %set(t_In, 'String', in_value);
- if(isequal(binaryout,[0 1 0 1]))
- received = getvalue(dio.Line(5:12));
- in_value = flip(transpose(dec2hex(received)));
- %binary_rec = dec2bin(binvec2dec(received), 4);
- set(t_In, 'String', in_value);
- elseif (isequal(binaryout,[1 1 0 0]))
- bstr_out = get(h_bin_out, 'String');
- dec_out = bin2dec(bstr_out);
- bv_out = dec2binvec(dec_out, 8);
- putvalue(dio.Line(5:12), (bv_out));
- end
- drawnow;
- end
- case('Stop')
- %set start to zero
- b_Start = findobj('Tag', 'btnStart');
- set(b_Start, 'UserData', 0);
- case('Slide')
- % Find the handles
- h_sld = findobj('Tag','Slidey');
- h_bin_out = findobj('Tag','Bin_Data_Out');
- % Get slider's value
- sld_val = get(h_sld,'Value');
- % Convert to binary, 8 bits
- sld_bin = dec2bin(sld_val,8);
- % Update text box
- set(h_bin_out,'String',sld_bin);
- case('0')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 0;
- binary = '0000';
- binaryout = [0 0 0 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('1')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 1;
- binary = '0001';
- binaryout = [0 0 0 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('2')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 2;
- binary = '0010';
- binaryout = [0 0 1 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('3')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 3;
- binary = '0011';
- binaryout = [0 0 1 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('4')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 4;
- binary = '0100';
- binaryout = [0 1 0 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('5')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 5;
- binary = '0101';
- binaryout = [0 1 0 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('6')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 6;
- binary = '0110';
- binaryout = [0 1 1 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('7')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 7;
- binary = '0111';
- binaryout = [0 1 1 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('8')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 8;
- binary = '1000';
- binaryout = [1 0 0 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('9')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 9;
- binary = '1001';
- binaryout = [1 0 0 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('A')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'A';
- binary = '1010';
- binaryout = [1 0 1 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('B')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'B';
- binary = '1011';
- binaryout = [1 0 1 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('C')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'C';
- binary = '1100';
- binaryout = [1 1 0 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('D')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'D';
- binary = '1101';
- binaryout = [1 1 0 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('E')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'E';
- binary = '1110';
- binaryout = [1 1 1 0];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- case('F')
- %grab the binary textbox and the hex textbox
- t_hex = findobj('Tag', 'txtHex');
- t_binary = findobj('Tag', 'txtBinary');
- %value of hex. value of binary
- hex = 'F';
- binary = '1111';
- binaryout = [1 1 1 1];
- %set the value of hex
- set(t_hex, 'String', hex);
- %set the value for binary
- set(t_binary, 'String', binary);
- end
- return
- %=========================================
- function [] = reconfigure( hw_object, mode )
- %display('here!');
- %putvalue(hw_object.Line(5:12), 0); %put an erroneous address out
- stop (hw_object);
- delete(hw_object.Line(5:12)); %delete the bidirectional bus lines
- if strcmp (mode, '1')%desired mode is output
- addline(hw_object, 0:2, 0, 'Out'); %assign lines
- addline(hw_object, 4:7, 0, 'Out');
- addline(hw_object, 1, 3, 'Out');
- elseif strcmp (mode, '0')
- addline(hw_object, 0:2, 0, 'In'); %assign lines
- addline(hw_object, 4:7, 0, 'In');
- addline(hw_object, 1, 3, 'In');
- end
- start (hw_object);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement