找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2559|回复: 1
打印 上一主题 下一主题
收起左侧

STM32串行通信源码工程模板 实现一个或多个8位二进制数的串行发送

[复制链接]
跳转到指定楼层
楼主
实现一个或多个8位二进制数的串行发送。要求把PA0作为串行数据输出端,PA1作为时钟脉冲,PB0作为使能端
附件:工程模板



主程序源码:
  1. #include "stm32f10x.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. void GPIOconfig(void)
  5. {
  6.         GPIO_InitTypeDef  GPIO_InitStructure;
  7.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB,ENABLE);
  8.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;   // ????
  9.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;                 //????50MHz
  10.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //????
  11.         GPIO_Init(GPIOA, &GPIO_InitStructure);                //???GPIOA       
  12.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;   // ????
  13.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;                 //????50MHz
  14.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //????
  15.         GPIO_Init(GPIOB, &GPIO_InitStructure);                //???GPIOA       
  16. }
  17. int main(void)
  18. {
  19.         u8 data=0x85,i;
  20.         GPIOconfig();
  21.         delay_init();
  22.         PBout(0)=1;
  23.         for(i=0;i<8;i++)
  24.         {
  25.                 PAout(1)=0;
  26.                 if((data&0x01)==0x01)
  27.                         PAout(0)=1;
  28.                 else
  29.                         PAout(0)=0;
  30.                 delay_ms(20);
  31.                 PAout(1)=1;
  32.                 delay_ms(20);
  33.                 data=data>>1;
  34.         }
  35.        
  36. }
复制代码
下载:
串行通信.rar (1.06 MB, 下载次数: 18)

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:323944 发表于 2018-5-7 09:53 | 只看该作者
这个通信是板子与pc位的通信么
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表