找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 3182|回復(fù): 1
收起左側(cè)

STM32串行通信源碼工程模板 實(shí)現(xiàn)一個(gè)或多個(gè)8位二進(jìn)制數(shù)的串行發(fā)送

[復(fù)制鏈接]
ID:189548 發(fā)表于 2017-4-14 15:02 | 顯示全部樓層 |閱讀模式
實(shí)現(xiàn)一個(gè)或多個(gè)8位二進(jìn)制數(shù)的串行發(fā)送。要求把PA0作為串行數(shù)據(jù)輸出端,PA1作為時(shí)鐘脈沖,PB0作為使能端
附件:工程模板

0.png

主程序源碼:
  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. }
復(fù)制代碼
下載:
串行通信.rar (1.06 MB, 下載次數(shù): 18)

回復(fù)

使用道具 舉報(bào)

ID:323944 發(fā)表于 2018-5-7 09:53 | 顯示全部樓層
這個(gè)通信是板子與pc位的通信么
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表