1 虚构一个电路
以上为STM32和外设链接方式
#include "stm32f10x.h"
#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 BitBand(Addr,BitNum) ((Addr&0xF0000000)+0X2000000 +((Addr&0xfffff)*32) + (BitNum*4))
//#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)
void Delay(__IO u32 nCount) //简单的延时函数
{
for(; nCount != 0; nCount--);
}
/*
* 函数名:main
* 描述 : 主函数
* 输入 :无
* 输出 : 无
*/
int main(void)
{
//PA.0 链接AB PA.1链接clock PB0链接clear
//使164芯片的Qa- Qh输出11000100
u8 data,i;
data = 0xC4;
PBout(0) = 1;
//设置引脚的工作状态PA.0 PA.1 PB.0都是作为输出,推揽输出
GPIOA->CRL = 0X33;
GPIOB->CRL = 0X03;
//进行通信
for(i = 0; i < 8; i++)
{
PAout(1) = 0;
if((data & 0x01) == 0x01)
{
PAout(0) = 1;
}else
{
PAout(0) = 0;
}
Delay(300);
PAout(1) = 1;
data = data >> 1;
Delay(300);
}
while(1);
}
/******************* (C) COPYRIGHT 2012 WildFire Team *****END OF FILE************/
keil软件仿真结果
仿真结果
以上为逻辑分析结果