RootOfTheNull

Untitled

Mar 23rd, 2016
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function keypad (action) %callback function for the GUI
  2. persistent binaryout;
  3. switch(action)%switch through each button
  4. case('Start')
  5. %define the header lines
  6. dio=digitalio('mcc', 1);
  7. %output line
  8. addline(dio, 0:3,2,'Out');
  9. %input lines
  10. addline(dio, 0:2, 0, 'In');
  11. addline(dio, 4:7, 0, 'In');
  12. addline(dio, 1, 3, 'In');
  13. %initialize
  14. b_Start = findobj('Tag', 'btnStart');
  15. set(b_Start, 'UserData', 1);
  16. h_bin_out = findobj('Tag', 'Bin_Data_Out');
  17. %grab the Binary Data Recieved Box
  18. t_In = findobj('Tag', 'txtReceived');
  19.  
  20.  
  21.  
  22.  
  23. while(get(b_Start, 'UserData') == 1)
  24. putvalue(dio.Line(1:4), binaryout);
  25.  
  26. %see if the dio needs to be reconfigured
  27. flow = dio.Line(12).Direction;
  28. if (isequal(binaryout,[0 1 0 1]) && strcmp(flow, 'Out'))
  29. reconfigure(dio, '0'); %reconfigure for input
  30. elseif (isequal(binaryout,[1 1 0 0]) && strcmp(flow, 'In'))
  31. display('here');
  32. reconfigure(dio, '1'); %reconfigure for output
  33. end
  34. %grab the input value
  35. %in_value1 = getvalue(dio.Line(5:12));
  36. % if (isequal(binaryout,[0 1 0 1]))
  37. %convert the vector to string
  38. % in_value = flip(transpose(dec2hex(in_value1)));
  39. % else
  40. %convert the vector to string
  41. %in_value = transpose(dec2hex(in_value1));
  42. %end
  43. %update the output textfield
  44. %set(t_In, 'String', in_value);
  45. %update the output textfield
  46. %set(t_In, 'String', in_value);
  47. if(isequal(binaryout,[0 1 0 1]))
  48. received = getvalue(dio.Line(5:12));
  49. in_value = flip(transpose(dec2hex(received)));
  50. %binary_rec = dec2bin(binvec2dec(received), 4);
  51. set(t_In, 'String', in_value);
  52. elseif (isequal(binaryout,[1 1 0 0]))
  53. bstr_out = get(h_bin_out, 'String');
  54. dec_out = bin2dec(bstr_out);
  55. bv_out = dec2binvec(dec_out, 8);
  56. putvalue(dio.Line(5:12), (bv_out));
  57. end
  58. drawnow;
  59. end
  60. case('Stop')
  61. %set start to zero
  62. b_Start = findobj('Tag', 'btnStart');
  63. set(b_Start, 'UserData', 0);
  64. case('Slide')
  65. % Find the handles
  66. h_sld = findobj('Tag','Slidey');
  67. h_bin_out = findobj('Tag','Bin_Data_Out');
  68. % Get slider's value
  69. sld_val = get(h_sld,'Value');
  70. % Convert to binary, 8 bits
  71. sld_bin = dec2bin(sld_val,8);
  72. % Update text box
  73. set(h_bin_out,'String',sld_bin);
  74. case('0')
  75. %grab the binary textbox and the hex textbox
  76. t_hex = findobj('Tag', 'txtHex');
  77. t_binary = findobj('Tag', 'txtBinary');
  78. %value of hex. value of binary
  79. hex = 0;
  80. binary = '0000';
  81. binaryout = [0 0 0 0];
  82. %set the value of hex
  83. set(t_hex, 'String', hex);
  84. %set the value for binary
  85. set(t_binary, 'String', binary);
  86. case('1')
  87. %grab the binary textbox and the hex textbox
  88. t_hex = findobj('Tag', 'txtHex');
  89. t_binary = findobj('Tag', 'txtBinary');
  90. %value of hex. value of binary
  91. hex = 1;
  92. binary = '0001';
  93. binaryout = [0 0 0 1];
  94. %set the value of hex
  95. set(t_hex, 'String', hex);
  96. %set the value for binary
  97. set(t_binary, 'String', binary);
  98. case('2')
  99. %grab the binary textbox and the hex textbox
  100. t_hex = findobj('Tag', 'txtHex');
  101. t_binary = findobj('Tag', 'txtBinary');
  102. %value of hex. value of binary
  103. hex = 2;
  104. binary = '0010';
  105. binaryout = [0 0 1 0];
  106. %set the value of hex
  107. set(t_hex, 'String', hex);
  108. %set the value for binary
  109. set(t_binary, 'String', binary);
  110. case('3')
  111. %grab the binary textbox and the hex textbox
  112. t_hex = findobj('Tag', 'txtHex');
  113. t_binary = findobj('Tag', 'txtBinary');
  114. %value of hex. value of binary
  115. hex = 3;
  116. binary = '0011';
  117. binaryout = [0 0 1 1];
  118. %set the value of hex
  119. set(t_hex, 'String', hex);
  120. %set the value for binary
  121. set(t_binary, 'String', binary);
  122. case('4')
  123. %grab the binary textbox and the hex textbox
  124. t_hex = findobj('Tag', 'txtHex');
  125. t_binary = findobj('Tag', 'txtBinary');
  126. %value of hex. value of binary
  127. hex = 4;
  128. binary = '0100';
  129. binaryout = [0 1 0 0];
  130. %set the value of hex
  131. set(t_hex, 'String', hex);
  132. %set the value for binary
  133. set(t_binary, 'String', binary);
  134. case('5')
  135. %grab the binary textbox and the hex textbox
  136. t_hex = findobj('Tag', 'txtHex');
  137. t_binary = findobj('Tag', 'txtBinary');
  138. %value of hex. value of binary
  139. hex = 5;
  140. binary = '0101';
  141. binaryout = [0 1 0 1];
  142. %set the value of hex
  143. set(t_hex, 'String', hex);
  144. %set the value for binary
  145. set(t_binary, 'String', binary);
  146. case('6')
  147. %grab the binary textbox and the hex textbox
  148. t_hex = findobj('Tag', 'txtHex');
  149. t_binary = findobj('Tag', 'txtBinary');
  150. %value of hex. value of binary
  151. hex = 6;
  152. binary = '0110';
  153. binaryout = [0 1 1 0];
  154. %set the value of hex
  155. set(t_hex, 'String', hex);
  156. %set the value for binary
  157. set(t_binary, 'String', binary);
  158. case('7')
  159. %grab the binary textbox and the hex textbox
  160. t_hex = findobj('Tag', 'txtHex');
  161. t_binary = findobj('Tag', 'txtBinary');
  162. %value of hex. value of binary
  163. hex = 7;
  164. binary = '0111';
  165. binaryout = [0 1 1 1];
  166. %set the value of hex
  167. set(t_hex, 'String', hex);
  168. %set the value for binary
  169. set(t_binary, 'String', binary);
  170. case('8')
  171. %grab the binary textbox and the hex textbox
  172. t_hex = findobj('Tag', 'txtHex');
  173. t_binary = findobj('Tag', 'txtBinary');
  174. %value of hex. value of binary
  175. hex = 8;
  176. binary = '1000';
  177. binaryout = [1 0 0 0];
  178. %set the value of hex
  179. set(t_hex, 'String', hex);
  180. %set the value for binary
  181. set(t_binary, 'String', binary);
  182. case('9')
  183. %grab the binary textbox and the hex textbox
  184. t_hex = findobj('Tag', 'txtHex');
  185. t_binary = findobj('Tag', 'txtBinary');
  186. %value of hex. value of binary
  187. hex = 9;
  188. binary = '1001';
  189. binaryout = [1 0 0 1];
  190. %set the value of hex
  191. set(t_hex, 'String', hex);
  192. %set the value for binary
  193. set(t_binary, 'String', binary);
  194. case('A')
  195. %grab the binary textbox and the hex textbox
  196. t_hex = findobj('Tag', 'txtHex');
  197. t_binary = findobj('Tag', 'txtBinary');
  198. %value of hex. value of binary
  199. hex = 'A';
  200. binary = '1010';
  201. binaryout = [1 0 1 0];
  202. %set the value of hex
  203. set(t_hex, 'String', hex);
  204. %set the value for binary
  205. set(t_binary, 'String', binary);
  206. case('B')
  207. %grab the binary textbox and the hex textbox
  208. t_hex = findobj('Tag', 'txtHex');
  209. t_binary = findobj('Tag', 'txtBinary');
  210. %value of hex. value of binary
  211. hex = 'B';
  212. binary = '1011';
  213. binaryout = [1 0 1 1];
  214. %set the value of hex
  215. set(t_hex, 'String', hex);
  216. %set the value for binary
  217. set(t_binary, 'String', binary);
  218. case('C')
  219. %grab the binary textbox and the hex textbox
  220. t_hex = findobj('Tag', 'txtHex');
  221. t_binary = findobj('Tag', 'txtBinary');
  222. %value of hex. value of binary
  223. hex = 'C';
  224. binary = '1100';
  225. binaryout = [1 1 0 0];
  226. %set the value of hex
  227. set(t_hex, 'String', hex);
  228. %set the value for binary
  229. set(t_binary, 'String', binary);
  230. case('D')
  231. %grab the binary textbox and the hex textbox
  232. t_hex = findobj('Tag', 'txtHex');
  233. t_binary = findobj('Tag', 'txtBinary');
  234. %value of hex. value of binary
  235. hex = 'D';
  236. binary = '1101';
  237. binaryout = [1 1 0 1];
  238. %set the value of hex
  239. set(t_hex, 'String', hex);
  240. %set the value for binary
  241. set(t_binary, 'String', binary);
  242. case('E')
  243. %grab the binary textbox and the hex textbox
  244. t_hex = findobj('Tag', 'txtHex');
  245. t_binary = findobj('Tag', 'txtBinary');
  246. %value of hex. value of binary
  247. hex = 'E';
  248. binary = '1110';
  249. binaryout = [1 1 1 0];
  250. %set the value of hex
  251. set(t_hex, 'String', hex);
  252. %set the value for binary
  253. set(t_binary, 'String', binary);
  254. case('F')
  255. %grab the binary textbox and the hex textbox
  256. t_hex = findobj('Tag', 'txtHex');
  257. t_binary = findobj('Tag', 'txtBinary');
  258. %value of hex. value of binary
  259. hex = 'F';
  260. binary = '1111';
  261. binaryout = [1 1 1 1];
  262. %set the value of hex
  263. set(t_hex, 'String', hex);
  264. %set the value for binary
  265. set(t_binary, 'String', binary);
  266. end
  267. return
  268.  
  269.  
  270.  
  271. %=========================================
  272.  
  273. function [] = reconfigure( hw_object, mode )
  274. %display('here!');
  275. %putvalue(hw_object.Line(5:12), 0); %put an erroneous address out
  276. stop (hw_object);
  277. delete(hw_object.Line(5:12)); %delete the bidirectional bus lines
  278. if strcmp (mode, '1')%desired mode is output
  279. addline(hw_object, 0:2, 0, 'Out'); %assign lines
  280. addline(hw_object, 4:7, 0, 'Out');
  281. addline(hw_object, 1, 3, 'Out');
  282. elseif strcmp (mode, '0')
  283. addline(hw_object, 0:2, 0, 'In'); %assign lines
  284. addline(hw_object, 4:7, 0, 'In');
  285. addline(hw_object, 1, 3, 'In');
  286. end
  287. start (hw_object);
  288. end
RAW Paste Data