マイコンの入力ポートが足りないことはありがちです。そんな時によく使われるのがシリアルパラレル変換のロジックIC。入力モジュールと出力モジュールを接続し、入力信号をそのままマイコンを通して出力信号としています。
使用機器は下記のとおり。他、パソコンや電源、PICKIT2も当然ながら必要です。
TTL8点出力モジュール…ZT-74HC595
TTL8点入力モジュール…ZT-74HC165
マイコンボード(PIC16F1947搭載)…ZEATEC co.,ltd. ZT-PIC16F194701(5V仕様)
接続は下記のとおりです。
74HC165用ライブラリ tc74hc165.zip
TC74HC165データシート TC74HC165AP.pdf
TPIC6B165Nデータシート TPIC6B165N.pdf
プロジェクトファイルも含めたサンプル ZT-PIC16F194701_74hc595_74hc165.zip
開発環境:MPLAB_IDE_8_92 + CCS-C PCMコンパイラVer.4.132
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
/******************************************************************************* 74HC165用ライブラリ 2015/4/10作成 □提供元 ZEATEC co.,ltd. □ご利用について 転載・無断使用可です。このライブラリを使用した上での不具合等に関しては、いかなる内容におい ても一切の責任を追わないものとします。 □使用方法 #include "tc74hc165.c"をヘッダーに追加してください。 取得したい変数を用意してtest_val = tc74hc595();というように使います。 *******************************************************************************/ //シリアルパラレル変換 int tc74hc165_8(){ //PIN_E3 QH シリアルデータ //PIN_E4 CK クロック //PIN_E5 S/L データ送信開始指示 int tmp1 = 0; int tmp_ans = 0; //S/L output_bit(PIN_E5,0); output_bit(PIN_E5,1); for(tmp1=0;tmp1<8;tmp1++){ //CK output_bit(PIN_E4,0); if(input(PIN_E3) == 0){ bit_set(tmp_ans,7-tmp1); }else{ bit_clear(tmp_ans,7-tmp1); } //CK output_bit(PIN_E4,1); } return tmp_ans; } long tc74hc165_16(){ //PIN_E3 QH シリアルデータ //PIN_E4 CK クロック //PIN_E5 S/L データ送信開始指示 int tmp1 = 0; long tmp_ans = 0; //S/L output_bit(PIN_E5,0); output_bit(PIN_E5,1); for(tmp1=0;tmp1<16;tmp1++){ //CK output_bit(PIN_E4,0); if(input(PIN_E3) == 0){ bit_set(tmp_ans,15-tmp1); }else{ bit_clear(tmp_ans,15-tmp1); } //CK output_bit(PIN_E4,1); } return tmp_ans; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/***************************************************************************************** 74HC595用ライブラリ 2015/4/1作成 □提供元 ZEATEC co.,ltd. □ご利用について 転載・無断使用可です。このライブラリを使用した上での不具合等に関しては、いかなる内容におい ても一切の責任を追わないものとします。 □使用方法 #include "tc74hc595.c"をヘッダーに追加してください。 出力する値を入れてtc74hc595(0x1234);というように使います。 *****************************************************************************************/ //シリアルパラレル変換 void tc74hc595_8(int setdata){ //PIN_E0 SI or SER シリアルデータ //PIN_E1 SCK クロック //PIN_E2 RCK ラッチ int tmp1 = 0; for(tmp1=0;tmp1<9;tmp1++){ output_bit(PIN_E0,bit_test(setdata,8-tmp1)); output_bit(PIN_E1,1); output_bit(PIN_E1,0); } output_bit(PIN_E2,1); output_bit(PIN_E2,0); } void tc74hc595_16(long setdata){ //PIN_E0 SI or SER シリアルデータ //PIN_E1 SCK クロック //PIN_E2 RCK ラッチ int tmp1 = 0; for(tmp1=0;tmp1<17;tmp1++){ output_bit(PIN_E0,bit_test(setdata,16-tmp1)); output_bit(PIN_E1,1); output_bit(PIN_E1,0); } output_bit(PIN_E2,1); output_bit(PIN_E2,0); } |
©ZEATEC co.,ltd.