16 串列通訊編程

來源:互聯網
上載者:User

標籤:blog   http   2014   io   for   re   

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軟體模擬結果

模擬結果

以上為邏輯分析結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.