实现一个或多个8位二进制数的串行发送。要求把PA0作为串行数据输出端,PA1作为时钟脉冲,PB0作为使能端
附件:工程模板
主程序源码:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "sys.h"
- void GPIOconfig(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB,ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; // ????
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; //????50MHz
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //????
- GPIO_Init(GPIOA, &GPIO_InitStructure); //???GPIOA
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // ????
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; //????50MHz
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //????
- GPIO_Init(GPIOB, &GPIO_InitStructure); //???GPIOA
- }
- int main(void)
- {
- u8 data=0x85,i;
- GPIOconfig();
- delay_init();
- PBout(0)=1;
- for(i=0;i<8;i++)
- {
- PAout(1)=0;
- if((data&0x01)==0x01)
- PAout(0)=1;
- else
- PAout(0)=0;
- delay_ms(20);
- PAout(1)=1;
- delay_ms(20);
- data=data>>1;
- }
-
- }
复制代码 下载:
串行通信.rar
(1.06 MB, 下载次数: 18)
|