2017-12-25 05:08 AM
2017-12-26 04:51 AM
I use an STM32F103C8 development board and has onboard xtal, voltage regulator and works on a pc usb output voltage, I've managed to program the 74hc595 with this board. However, programming the counterpart parallel in, serial out (HC165) is quite hard for me. Could you or anyone tell me how I can read the bit from QH from the register?
I've tried another code from a chinese source:
//
--------------------------------------------------------------------------
//
��:
https://community.st.com/external-link.jspa?url=http%3A%2F%2Fhi.baidu.com%2Fmculove%2Fhome
//
程åº�å��称: ç�?¨74HC165读8个按é�?®çŠ¶æ€�
//
晶振: 11.0592MHz;
//
MCU型�: STC89C52RC;
//
ç�?µè·¯æ�¿åž‹å�·: EBV-MV(51实验æ�¿);
//
--------------------------------------------------------------------------
//
--------------------------------------------------------------------------
//
硬件连接:
//
EBVn-[VCC] -> MVn-[--VCC--]
//
EBVn-[GND] -> MVn-[
//
GND
//
]
//
MVn-{EX3}-[Y0] -> MVn-{EX2}-[L1]
//
MVn-{EX3}-[Y1] -> MVn-{EX2}-[L2]
//
MVn-{EX3}-[Y2] -> MVn-{EX2}-[L3]
//
MVn-{EX3}-[Y3] -> MVn-{EX2}-[L4]
//
MVn-{EX3}-[Y4] -> MVn-{EX2}-[L5]
//
MVn-{EX3}-[Y5] -> MVn-{EX2}-[L6]
//
MVn-{EX3}-[Y6] -> MVn-{EX2}-[L7]
//
MVn-{EX3}-[Y7] -> MVn-{EX2}-[L8]
//
-> MVn-{EX2}-(VCC)
//
-> MVn-{EX3}-(VCC)
//
EBVn-[P10] -> MVn-{EX3}-[A]
//
EBVn-[P11] -> MVn-{EX3}-[B]
//
EBVn-[P12] -> MVn-{EX3}-[C]
//
EBVn-[P13] -> MVn-{EX3}-[G1]
//
--------------------------------------------------------------------------
//
--------------------------------------------------------------------------
//
实验结果:
//
控制74HC138的[A,B,C,G1]端�,使[Y0,Y1..Y7]输出预期的值,LED实现了�水�显示
//
--------------------------------------------------------------------------
//
------------------------------------------------------
//
头文件;
#include <AT89X52.H>#define
HC165_nPL P3_5#define
HC165_CK P3_6#define
HC165_OUT P3_7//
------------------------------------------------------
void
delay(void
) { unsigned
char
i,j;
for
(i =250
;i >0
;i--)
for
(j =200
;j >0
;j--); } unsigned
char
HC165(void
) { unsigned
char
i; unsigned
char
Temp; HC165_CK
=1
; HC165_nPL
=0
;//
HC165读按é�?®
HC165_nPL =1
;//
æš‚å�œHC165读按é�?®
Temp =0
;
if
(HC165_OUT ==1
) Temp |=0x01
;
for
(i =0
;i <7
;i++) { HC165_CK
=0
; HC165_CK
=1
; Temp
<<=1
;
if
(HC165_OUT ==1
) { Temp
|=0x01
; } } HC165_CK
=0
;
return
(Temp); }
//
------------------------------------------------------
//
程�入�;
void
main(void
) {
while
(1
) { P1
=HC165(); delay(); } }
However the while function 'P1 = HC165();' can't be accepted since I use GPIO with help of the STMCubeMX. Instead of that, I write ' HAL_GPIO_WritePin(GPIOB, HC165(), GPIO_PIN_SET);'. However, after uploading the program there is no output. I use GPIOB, GPIO_PIN_0 till GPIO_PIN_7. I have a HIGH signal at QA so shouldn't it be alteast 1 led turned on?
2018-01-02 09:37 AM
Duplicate: