登录后复制
#include "stm32f10x_lib.h"#include <stdio.h>void Delay_MS(u16 dly);#define GPIOA_ODR_A (GPIOA_BASE+0x0C)#define GPIOA_IDR_A (GPIOA_BASE+0x08)#define GPIOB_ODR_A (GPIOB_BASE+0x0C)#define GPIOB_IDR_A (GPIOB_BASE+0x08)#define GPIOC_ODR_A (GPIOC_BASE+0x0C)#define GPIOC_IDR_A (GPIOC_BASE+0x08)#define GPIOD_ODR_A (GPIOD_BASE+0x0C)#define GPIOD_IDR_A (GPIOD_BASE+0x08)#define GPIOE_ODR_A (GPIOE_BASE+0x0C)#define GPIOE_IDR_A (GPIOE_BASE+0x08)#define BitBand(Addr,BitNum) *((volatile unsigned long *)((Addr&0xF0000000)+0x2000000+((Addr&0xfffff)<<5)+(BitNum<<2)))#define PAout(n) BitBand(GPIOA_ODR_A,n)#define PAin(n) BitBand(GPIOA_IDR_A,n)#define PBout(n) BitBand(GPIOB_ODR_A,n)#define PBin(n) BitBand(GPIOB_IDR_A,n)#define PCout(n) BitBand(GPIOC_ODR_A,n)#define PCin(n) BitBand(GPIOC_IDR_A,n)#define PDout(n) BitBand(GPIOD_ODR_A,n)#define PDin(n) BitBand(GPIOD_IDR_A,n)#define PEout(n) BitBand(GPIOE_ODR_A,n)#define PEin(n) BitBand(GPIOE_IDR_A,n)int main(void){ //STM32 -- 74LS164 //PA.0 -- AB //PA.1 -- CLOCK //PB.0 -- clear //目的:74LS164 QA~QH 输出 :1100 0100 u8 data,i; PBout(0) = 1; //高电平有效 data = 0xC4; //1100 0100 //步骤 //1.设置引脚:PA.0 输出,PA.1、PB.0 推挽输出 GPIOA->CRL = 0x33; //GPIOA 0,1 脚设置为推挽输出 GPIOB->CRL = 0x3; //GPIOB 0 脚设置为推挽输出 //2.通信 QA~QH=1100 0100 // 如传递首位0,设置PA.0 = 0 PA.1上升沿, /* 传一位的方法 PAout(1)=0; PAout(0)=0; PAout(1)=1; //上升沿 Delay_MS(1); */ for(i=0;i<8;i++){ PAout(1)=0; Delay_MS(1); if((data&0x01)==0x01) PAout(0) = 1; else PAout(0)= 0; PAout(0)=0; PAout(1)=1; Delay_MS(1); data=data>>1; } return (1);}/******************************************************************************** Function Name : Delay_Ms* Description : delay 1 ms.* Input : dly (ms)* Output : None* Return : None*******************************************************************************/void Delay_MS(u16 dly){ u16 i,j; for(i=0;i<dly;i++) for(j=1000;j>0;j--);}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.
打开Logic Analyzer查看结果:
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删