eaplrdd
Newbie level 3
Hi dear friends,
Thanks for providing the opportunity to interact with you experts!
Here I want to perform parallel to serial data conversion. Therefore I am using 74HC165, 8-bit parallel-in/serial-out shift register.
I need C code to read & store the fault status into Variable( say unsigned char). I tried below C code but its not working.
Basically I have an 8 Window Annunciator product where I want to read the Eight different Fault status. These faults can be either Logic 0 or Logic 1. Now these Eight status shall be collected into a Variable(datatype: unsigned char, as value 0b00000000/ 0b11111111 is possible)
Hardware logic is illustrated as shown in fig(A):
D0 to D7 are eight fault status which can be either Logic 0 or Logic 1.
C Code to read & store the status is as follows:
So kindly suggest the correct C code to read & store the fault status into Variable.
Thanks!
Regards,
Santosh Bhat
Sr. Engg, Bangalore
Thanks for providing the opportunity to interact with you experts!
Here I want to perform parallel to serial data conversion. Therefore I am using 74HC165, 8-bit parallel-in/serial-out shift register.
I need C code to read & store the fault status into Variable( say unsigned char). I tried below C code but its not working.
Basically I have an 8 Window Annunciator product where I want to read the Eight different Fault status. These faults can be either Logic 0 or Logic 1. Now these Eight status shall be collected into a Variable(datatype: unsigned char, as value 0b00000000/ 0b11111111 is possible)
Hardware logic is illustrated as shown in fig(A):
D0 to D7 are eight fault status which can be either Logic 0 or Logic 1.
C Code to read & store the status is as follows:
Code C - [expand] 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 void CHK_FAULT_INPUT(void) { unsigned char a=0, Val=0; PL_ENABLE = 1; SERIAL_CLK = 0; CHIP_ENABLE = 1; PL_ENABLE = 0; // PL asm("nop"); asm("nop"); CHIP_ENABLE = 0; // CE asm("nop"); asm("nop"); SERIAL_CLK = 0; // CP asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); // FAULT_PAT: Q7 if((FAULT_PAT & 0b00000001) == 1) FAULT_InP1 = 0b00000001; else FAULT_InP1 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b00000010) == 1) FAULT_InP2 = 0b00000010; else FAULT_InP2 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b00000100) == 1) FAULT_InP3 = 0b00000100; else FAULT_InP3 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b00001000) == 1) FAULT_InP4 = 0b00001000; else FAULT_InP4 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b00010000) == 1) FAULT_InP5 = 0b00010000; else FAULT_InP5 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b00100000) == 1) FAULT_InP6 = 0b00100000; else FAULT_InP6 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b01000000) == 1) FAULT_InP7 = 0b01000000; else FAULT_InP7 = 0b00000000; asm("nop"); SERIAL_CLK = 0; asm("nop"); asm("nop"); SERIAL_CLK = 1; asm("nop"); asm("nop"); if((FAULT_PAT & 0b10000000) == 1) FAULT_InP8 = 0b10000000; else FAULT_InP8 = 0b00000000; asm("nop"); FAULT_InP = FAULT_InP1 + FAULT_InP2 + FAULT_InP3 + FAULT_InP4 + FAULT_InP5 + FAULT_InP6 + FAULT_InP7 + FAULT_InP8; SERIAL_CLK = 0; CHIP_ENABLE = 1; PL_ENABLE = 1; }
So kindly suggest the correct C code to read & store the fault status into Variable.
Thanks!
Regards,
Santosh Bhat
Sr. Engg, Bangalore
Attachments
Last edited by a moderator: