導航:首頁 > 操作系統 > 單片機的io定義

單片機的io定義

發布時間:2022-05-31 10:14:32

單片機IO口的概述

凌陽單片機IOA,IOB口的一些簡單設置和C語言應用函數 P_IOA_Buffer (讀/寫) (01H)
A口的數據向量單元,用於向數據向量寄存器寫入或從該寄存器讀出數據。當A口處於輸入狀態時,寫入是將A口的數據向量寫入A口的數據寄存器;讀出則是從A口數據寄存器內讀其數值。當A口處於輸出狀態時,寫入輸出數據到A口的數據寄存器。
P_IOA_Dir(讀/寫)(02H)
A口的方向向量單元,用於用來設置A口是輸入還是輸出,該方向控制向量寄存器可以寫入或從該寄存器內讀出方向控制向量。Dir位決定了口位的輸入/輸出方向:即『0』為輸入,『1』為輸出。
P_IOA_Attrib(讀/寫)(03H)
A口的屬性向量單元,用於A口屬性向量的設置。
P_IOA_Latch(讀)(04H)
讀該單元以鎖存A口上的輸入數據,用於進入睡眠狀態前的觸鍵喚醒功能的啟動。 方向向量Dir、屬性向量Attrib和數據向量Data分別代表三個控制口。這三個口中每個對應的位組合在一起,形成一個控制字,來定義相應I/O口位的輸入/輸出狀態和方式。
表3.1具體表示了如何通過對I/O口位的方向向量位Dir、屬性向量位Attrib以及數據向量位Data進行編程,來設定口位的輸入/輸出狀態和方式。
由表3.1可以得出以下一些結論:
Dir位決定了口位的輸入/輸出方向:即『0』為輸入,『1』為輸出。
Attrib位決定了在口位的輸入狀態下是為懸浮式輸入還是非懸浮式輸入:即『0』為帶上拉或下拉電阻式輸入,而『1』則為懸浮式輸入。在口位的輸出狀態下則決定其輸出是反相的還是同相的;『0』為反相輸出,『1』則為同相輸出。
Data位在口位的輸入狀態下被寫入時,與Attrib位組合在一起形成輸入方式的控制字『00』、『01』、『10』、『11』,以決定輸入口是帶喚醒功能的上拉電阻式、下拉電阻式或懸浮式以及不帶喚醒功能的懸浮式輸入。Data位在口位的輸出狀態下被寫入的是輸出數據,不過,數據是經過反相器輸出還是經過同相緩存器輸出要由Attrib位來決定。
例如,假設要把A口的Bit0定義成下拉電阻式的輸入口,則A口_Dir、_Attrib和_Data向量的三個相應的Bit0應組合設為『000』。如果想把A口的Bit1定義成懸浮式並具有喚醒功能的輸入口,只需將Dir、Attrib和Data向量中相應的Bit1組合設置為『010』即可。
A口的IOA0~IOA7作為喚醒源,常用於鍵盤輸入。要激活IOA0~IOA7的喚醒功能,必須讀P_IOA_Latch單元,以此來鎖存IOA0~IOA7管腳上的鍵狀態。隨後,系統才可通過指令進入低功耗的睡眠狀態。當有鍵按下時,IOA0~IOA7的輸入狀態將不同於其在進入睡眠前被鎖存時的狀態,從而引起系統的喚醒。
表3.1 Direction Attribution Data 功能 是否帶喚喚醒功能 功能描述 0 0 0 下拉 是 帶下拉電阻的輸入管腳 0 0 1 上拉 是 帶上拉電阻的輸入管腳 0 1 0 懸浮 是 懸浮式輸入管腳 0 1 1 懸浮 否 懸浮式輸入管腳 1 0 0 高電平輸出
(帶數據反相器) 否 帶數據反相器的高電平輸出
(當向數據位寫入「0」 時輸出「1」) 1 0 1 低電平輸出
(帶數據反相器) 否 帶數據反相器的低電平輸出
(當向數據位寫入「1」時輸出「0」) 1 1 0 低電平輸出 否 帶數據緩存器的低電平輸出
(無數據反相功能) 1 1 1 高電平輸出 否 帶數據緩存器的高電平輸出
(無數據反相功能) P_IOB_Data(讀/寫)(05H)
B口的數據單元,用於向B口寫入或從B口讀出數據。當B口處於輸入狀態時,讀出是讀B口管腳電平狀態; 寫入是將數據寫入B口的數據寄存器。當B口處於輸出狀態時,寫入輸出數據到B口的數據寄存器。
P_IOB_Buffer(讀/寫)(06H)
B口的數據向量單元,用於向數據寄存器寫入或從該寄存器內讀出數據。當B口處於輸入狀態時,寫入是將數據寫入B口的數據寄存器;讀出則是從B口數據寄存器里讀其數值。當B口處於輸出狀態時,寫入數據到B口的數據寄存器。
P_IOB_Dir(讀/寫)(07H)
B口的方向向量單元,用於設置IOB口的狀態。『0』為輸入,『1』為輸出。
P_IOB_Attrib(讀/寫)(08H)
B口的屬性向量單元,用於設置IOB口的屬性。 B口除了具有常規的輸入/輸出埠功能外,還有一些特殊的功能,如下表3.2所示: 口位 特殊功能 功能描述 備注 IOB0 SCK 串列介面SIO的時鍾信號 IOB1 SDA 串列介面SIO的數據傳送信號 IOB2 1,EXT1
2, Feedback_Output1 1,外部中斷源(下降沿觸發)
2,與IOB4組成一個RC反饋電路,以獲得振盪信號,作為外部中斷源EXT1 1,IOB2 設為輸入狀態
2,設置IOB2為反相輸出方式 IOB3 1,EXT2
2,Feedback_Output2 1,外部中斷源(下降沿觸發)
2,與IOB5組成一個RC反饋電路,以獲得一個振盪信號,作為外部中斷源EXT2 1,IOB3 設為輸入狀態
2,設置IOB3為反相輸出方式 IOB4 Feedback_Input1 IOB5 Feedback_Input2 IOB6 --- IOB7 Rx 通用非同步串列數據接收埠 IOB8 APWMO TimerA脈寬調制輸出 IOB9 BPWMO TimerB脈寬調制輸出 IOB10 Tx 通用非同步串列數據發送埠 IO埠設置的C庫函5
SPCE061.lib中提供了相應的API函數如下所示:
1, 函數原型
void Set_IOA_Dir(unsigned int);
void Set_IOB_Dir(unsigned int);
功能說明 設置IO Dircetion信息
用法 Set_IOA_Dir(Direction_A);
Set_IOB_Dir(Direction_B);
參數 1代表輸出,0代表輸入
返回值 無
2,函數原型
unsigned int Get_IOA_Dir(void);
unsigned int Get_IOB_Dir(void);
功能說明 獲取IO Dircetion信息
用法 Direction_A =Get_IOA_Dir();
Direction_B =Get_IOB_Dir();
返回值 1代表輸出,0代表輸入
3.函數原型
void Set_IOA_Data(unsigned int);
void Set_IOB_Data(unsigned int);
功能說明 設置IO Data信息
用法 Set_IOA_Data(Data_A);
Set_IOB_Data(Data_B);
參數 1代表高電平,0代表低電平
返回值 無
4,函數原型
unsigned int Get_IOA_Data(void);
unsigned int Get_IOB_Data(void);
功能說明 獲取IO Data信息
用法 Data_A =Set_IOA_Data();
Data_B =Set_IOB_Data();
參數 無
返回值 1代表高電平,0代表低電平
5,函數原型
void Set_IOA_Buffer(unsigned int);
void Set_IOB_Buffer(unsigned int);
功能說明 設置IO Buffer信息
用法 Set_IOA_Buffer(Buffer_A);
Set_IOB_Buffer(Buffer_B);
參數 1代表高電平,0代表低電平
返回值 無
6.函數原型
unsigned int Get_IOA_Buffer(void);
unsigned int Get_IOB_Buffer(void);
功能說明 獲取IO Buffer信息
用法 Buffer_A =Set_IOA_Buffer();
Buffer_B =Set_IOB_Buffer();
參數 無
返回值 1代表高電平,0代表低電平
7.函數原型
void Get_IOA_Latch(void);
功能說明 讀P_IOA_Latch單元,以此來鎖存IOA0~IOA7管腳上的鍵狀態
用法 Get_IOA_Latch();
參數 無
返回值 無
另外還有:
sp_lib.asm中定義了兩個很有用的IO API,在C中可以調用。它們是SP_Init_IOA(),SP_Init_IOB()。
函數原型
void SP_Init_IOA(unsigned int, unsigned int, unsigned int);
void SP_Init_IOB(unsigned int, unsigned int, unsigned int);
功能說明 同時設置IO Dircetion、Attribution和Data信息
用法 SP_Init_IOA(Direction_A, Data_A, Attribution_A);
SP_Init_IOB(Direction_B, Data_B, Attribution_B);
參數
返回值 無

Ⅱ 51單片機:如何定義一個指向I/O口的指針

你定義的color是指針變數,而你把它當位變數用了。如果color是指針,就只能傳遞地址,不能傳遞數值。而P1^1P和1^2里是數值(位值);
把這句:
bit *Color; //指向這兩個IO口的指針
改成:
bit Color;
試一試。
如果要用指針,可以這樣:
sbit Red = P1^1; //P1-1口控制紅燈
sbit Green = P1^2; //P1-2口控制綠燈
bit *Color; //指向這兩個IO口的指針
if (按鍵值 == 1)
*Color = Red; //如果按1號鍵,Color指向P1-1
else if (按鍵值 == 2)
*Color = Green; //如果按2號鍵,Color指向P1-2

*Color = !Color;//對應的燈閃


*color表示color所指向地址的內容。

Ⅲ 救急!請問單片機C語言IO口如何定義啊

首先要有這個頭文件: #include <AT89X52.H> //根據你用的單片機類型而定
這個頭文件已經有了埠的定義,不過用的時候不能寫 P1.1,而應該是P1_1(注意:P要大寫)

如果要自己重新定義的話:打開這個頭文件,修改就行了(裡面的內容很簡單的,一看就可以明白它是怎樣定義的)

也可以調用頭文件後在程序里重新給它命名,但沒有什麼必要。

(對了,我用的軟體是keil)

Ⅳ 關於單片機IO口重新定義的問題

sbit 是屬於定義、聲明,並不會產生實際的代碼,用在if後面是不行的。
一個可行的方法是使用條件預處理,像這樣
#if flag
sbit HX711_DOUT=P1^4;
#else
sbit HX711_DOUT=P1^2;
#endif
注意,這里的flag,只能是預定義的符號,不可以是變數。

Ⅳ 單片機里的IO口是什麼意思啊

原來是是指可以作輸入和輸出的引腳就叫IO
後來就成為習慣說法了
只要是有輸入或者輸出功能的叫稱為IO
工程師之間談話的時候會弄明白其中意義的,沒必要深究什麼

Ⅵ 在單片機編程的時候,應該怎樣去定義單片機I/O埠的輸入端和輸出端

不知你這說的什麼鎖存器了,一般74x73系列才有八個輸入埠,它是在有外匯流排的單片機中做地址低位鎖存用,如我沒猜錯,那你就把它這八個埠和p0口一一相聯,再把g腳和ale/prog相聯,電源接電源其它的全接地就ok!輸出這時就是相應的地址a0~a7。

Ⅶ 單片機中的p口和IO口的區別

P口指的是「並行口」
IO口指的是「輸入輸出口」
P口當然可以作為IO口來用,但是通常P3口會用於他的第二功能,而P2口、P0口則經常被用作地址匯流排和數據匯流排。只有P1口,常被用於IO口。
舉個簡單的例子來說明他們之間的關系,P3口像航母,P1口像小漁船,你當然可以開著航母去釣魚,但是通常沒人願意這么做,因為用小漁船捕魚就足夠了。

Ⅷ 單片機IO口定義

SPCE061A的I/O埠,對某一位的設定包括以下3個基本項:數據向量Data、屬性向量Attribution和方向控制向量Direction。3個埠內每個對應的位組合在一起,形成一個控制字,用來定義相應I/O口位的輸入輸出狀態和方式。例如,假設需要IOA0是下拉輸入管腳,則相應的Data、Attribution和Direction的值均被置為「0」。如果需要IOA1是帶喚醒功能的懸浮式輸入管腳,則Data、Attribution和Direction的值被置為「010」。A口和B口的Data、Attribution和Direction的設定值均在不同的寄存器里,用戶在進行I/O口設置時要特別注意這一點。

Ⅸ 救急!請問單片機C語言IO口如何定義

/**-------------------------------------------------------------------------------
〖說明〗配置文件
〖文件〗d:\user\BCB\C51BBS 模擬器\編程器\config.h @2002.07.05
〖作者〗新太科技 開發八部 張曉龍 E-mail: [email protected]
〖修改〗 改為PICC用 葉存樹 E-mail: [email protected]
〖版本〗V1.00A Build 0705
---------------------------------------------------------------------------------*/
typedef unsigned char BYTE; //注意:有分號
typedef unsigned int WORD;
typedef unsigned long DWORD;

#define Byte unsigned char //注意:無分號
#define Word unsigned int
#define DWord unsigned long

#define bool bit
#define true 1
#define false 0
/**********************
sbit P0_0 = P0^0;
sbit P0_1 = P0^1;
sbit P0_2 = P0^2;
sbit P0_3 = P0^3;
sbit P0_4 = P0^4;
sbit P0_5 = P0^5;
sbit P0_6 = P0^6;
sbit P0_7 = P0^7;

sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P1_2 = P1^2;
sbit P1_3 = P1^3;
sbit P1_4 = P1^4;
sbit P1_5 = P1^5;
sbit P1_6 = P1^6;
sbit P1_7 = P1^7;

sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit P2_4 = P2^4;
sbit P2_5 = P2^5;
sbit P2_6 = P2^6;
sbit P2_7 = P2^7;

sbit P3_0 = P3^0;
sbit P3_1 = P3^1;
sbit P3_2 = P3^2;
sbit P3_3 = P3^3;
sbit P3_4 = P3^4;
sbit P3_5 = P3^5;
sbit P3_6 = P3^6;
sbit P3_7 = P3^7;
********************************/
//以下是二進制輸入宏
#define B0000_0000 0x00
#define B0000_0001 0x01
#define B0000_0010 0x02
#define B0000_0011 0x03
#define B0000_0100 0x04
#define B0000_0101 0x05
#define B0000_0110 0x06
#define B0000_0111 0x07
#define B0000_1000 0x08
#define B0000_1001 0x09
#define B0000_1010 0x0A
#define B0000_1011 0x0B
#define B0000_1100 0x0C
#define B0000_1101 0x0D
#define B0000_1110 0x0E
#define B0000_1111 0x0F

#define B0001_0000 0x10
#define B0001_0001 0x11
#define B0001_0010 0x12
#define B0001_0011 0x13
#define B0001_0100 0x14
#define B0001_0101 0x15
#define B0001_0110 0x16
#define B0001_0111 0x17
#define B0001_1000 0x18
#define B0001_1001 0x19
#define B0001_1010 0x1A
#define B0001_1011 0x1B
#define B0001_1100 0x1C
#define B0001_1101 0x1D
#define B0001_1110 0x1E
#define B0001_1111 0x1F

#define B0010_0000 0x20
#define B0010_0001 0x21
#define B0010_0010 0x22
#define B0010_0011 0x23
#define B0010_0100 0x24
#define B0010_0101 0x25
#define B0010_0110 0x26
#define B0010_0111 0x27
#define B0010_1000 0x28
#define B0010_1001 0x29
#define B0010_1010 0x2A
#define B0010_1011 0x2B
#define B0010_1100 0x2C
#define B0010_1101 0x2D
#define B0010_1110 0x2E
#define B0010_1111 0x2F

#define B0011_0000 0x30
#define B0011_0001 0x31
#define B0011_0010 0x32
#define B0011_0011 0x33
#define B0011_0100 0x34
#define B0011_0101 0x35
#define B0011_0110 0x36
#define B0011_0111 0x37
#define B0011_1000 0x38
#define B0011_1001 0x39
#define B0011_1010 0x3A
#define B0011_1011 0x3B
#define B0011_1100 0x3C
#define B0011_1101 0x3D
#define B0011_1110 0x3E
#define B0011_1111 0x3F

#define B0100_0000 0x40
#define B0100_0001 0x41
#define B0100_0010 0x42
#define B0100_0011 0x43
#define B0100_0100 0x44
#define B0100_0101 0x45
#define B0100_0110 0x46
#define B0100_0111 0x47
#define B0100_1000 0x48
#define B0100_1001 0x49
#define B0100_1010 0x4A
#define B0100_1011 0x4B
#define B0100_1100 0x4C
#define B0100_1101 0x4D
#define B0100_1110 0x4E
#define B0100_1111 0x4F

#define B0101_0000 0x50
#define B0101_0001 0x51
#define B0101_0010 0x52
#define B0101_0011 0x53
#define B0101_0100 0x54
#define B0101_0101 0x55
#define B0101_0110 0x56
#define B0101_0111 0x57
#define B0101_1000 0x58
#define B0101_1001 0x59
#define B0101_1010 0x5A
#define B0101_1011 0x5B
#define B0101_1100 0x5C
#define B0101_1101 0x5D
#define B0101_1110 0x5E
#define B0101_1111 0x5F

#define B0110_0000 0x60
#define B0110_0001 0x61
#define B0110_0010 0x62
#define B0110_0011 0x63
#define B0110_0100 0x64
#define B0110_0101 0x65
#define B0110_0110 0x66
#define B0110_0111 0x67
#define B0110_1000 0x68
#define B0110_1001 0x69
#define B0110_1010 0x6A
#define B0110_1011 0x6B
#define B0110_1100 0x6C
#define B0110_1101 0x6D
#define B0110_1110 0x6E
#define B0110_1111 0x6F

#define B0111_0000 0x70
#define B0111_0001 0x71
#define B0111_0010 0x72
#define B0111_0011 0x73
#define B0111_0100 0x74
#define B0111_0101 0x75
#define B0111_0110 0x76
#define B0111_0111 0x77
#define B0111_1000 0x78
#define B0111_1001 0x79
#define B0111_1010 0x7A
#define B0111_1011 0x7B
#define B0111_1100 0x7C
#define B0111_1101 0x7D
#define B0111_1110 0x7E
#define B0111_1111 0x7F

#define B1000_0000 0x80
#define B1000_0001 0x81
#define B1000_0010 0x82
#define B1000_0011 0x83
#define B1000_0100 0x84
#define B1000_0101 0x85
#define B1000_0110 0x86
#define B1000_0111 0x87
#define B1000_1000 0x88
#define B1000_1001 0x89
#define B1000_1010 0x8A
#define B1000_1011 0x8B
#define B1000_1100 0x8C
#define B1000_1101 0x8D
#define B1000_1110 0x8E
#define B1000_1111 0x8F

#define B1001_0000 0x90
#define B1001_0001 0x91
#define B1001_0010 0x92
#define B1001_0011 0x93
#define B1001_0100 0x94
#define B1001_0101 0x95
#define B1001_0110 0x96
#define B1001_0111 0x97
#define B1001_1000 0x98
#define B1001_1001 0x99
#define B1001_1010 0x9A
#define B1001_1011 0x9B
#define B1001_1100 0x9C
#define B1001_1101 0x9D
#define B1001_1110 0x9E
#define B1001_1111 0x9F

#define B1010_0000 0xA0
#define B1010_0001 0xA1
#define B1010_0010 0xA2
#define B1010_0011 0xA3
#define B1010_0100 0xA4
#define B1010_0101 0xA5
#define B1010_0110 0xA6
#define B1010_0111 0xA7
#define B1010_1000 0xA8
#define B1010_1001 0xA9
#define B1010_1010 0xAA
#define B1010_1011 0xAB
#define B1010_1100 0xAC
#define B1010_1101 0xAD
#define B1010_1110 0xAE
#define B1010_1111 0xAF

#define B1011_0000 0xB0
#define B1011_0001 0xB1
#define B1011_0010 0xB2
#define B1011_0011 0xB3
#define B1011_0100 0xB4
#define B1011_0101 0xB5
#define B1011_0110 0xB6
#define B1011_0111 0xB7
#define B1011_1000 0xB8
#define B1011_1001 0xB9
#define B1011_1010 0xBA
#define B1011_1011 0xBB
#define B1011_1100 0xBC
#define B1011_1101 0xBD
#define B1011_1110 0xBE
#define B1011_1111 0xBF

#define B1100_0000 0xC0
#define B1100_0001 0xC1
#define B1100_0010 0xC2
#define B1100_0011 0xC3
#define B1100_0100 0xC4
#define B1100_0101 0xC5
#define B1100_0110 0xC6
#define B1100_0111 0xC7
#define B1100_1000 0xC8
#define B1100_1001 0xC9
#define B1100_1010 0xCA
#define B1100_1011 0xCB
#define B1100_1100 0xCC
#define B1100_1101 0xCD
#define B1100_1110 0xCE
#define B1100_1111 0xCF

#define B1101_0000 0xD0
#define B1101_0001 0xD1
#define B1101_0010 0xD2
#define B1101_0011 0xD3
#define B1101_0100 0xD4
#define B1101_0101 0xD5
#define B1101_0110 0xD6
#define B1101_0111 0xD7
#define B1101_1000 0xD8
#define B1101_1001 0xD9
#define B1101_1010 0xDA
#define B1101_1011 0xDB
#define B1101_1100 0xDC
#define B1101_1101 0xDD
#define B1101_1110 0xDE
#define B1101_1111 0xDF

#define B1110_0000 0xE0
#define B1110_0001 0xE1
#define B1110_0010 0xE2
#define B1110_0011 0xE3
#define B1110_0100 0xE4
#define B1110_0101 0xE5
#define B1110_0110 0xE6
#define B1110_0111 0xE7
#define B1110_1000 0xE8
#define B1110_1001 0xE9
#define B1110_1010 0xEA
#define B1110_1011 0xEB
#define B1110_1100 0xEC
#define B1110_1101 0xED
#define B1110_1110 0xEE
#define B1110_1111 0xEF

#define B1111_0000 0xF0
#define B1111_0001 0xF1
#define B1111_0010 0xF2
#define B1111_0011 0xF3
#define B1111_0100 0xF4
#define B1111_0101 0xF5
#define B1111_0110 0xF6
#define B1111_0111 0xF7
#define B1111_1000 0xF8
#define B1111_1001 0xF9
#define B1111_1010 0xFA
#define B1111_1011 0xFB
#define B1111_1100 0xFC
#define B1111_1101 0xFD
#define B1111_1110 0xFE
#define B1111_1111 0xFF

Ⅹ 單片機IO定義

都#define Y P0還能給Y賦值 0x01?
P0就是P0,位定義IO沒有偷懶的辦法,只有一個一個sbit過來的

閱讀全文

與單片機的io定義相關的資料

熱點內容
自己購買雲主伺服器推薦 瀏覽:419
個人所得稅java 瀏覽:761
多餘的伺服器滑道還有什麼用 瀏覽:189
pdf劈開合並 瀏覽:27
不能修改的pdf 瀏覽:751
同城公眾源碼 瀏覽:488
一個伺服器2個埠怎麼映射 瀏覽:297
java字元串ascii碼 瀏覽:78
台灣雲伺服器怎麼租伺服器 瀏覽:475
旅遊手機網站源碼 瀏覽:332
android關聯表 瀏覽:945
安卓導航無聲音怎麼維修 瀏覽:332
app怎麼裝視頻 瀏覽:430
安卓系統下的軟體怎麼移到桌面 瀏覽:96
windows拷貝到linux 瀏覽:772
mdr軟體解壓和別人不一樣 瀏覽:904
單片機串列通信有什麼好處 瀏覽:340
游戲開發程序員書籍 瀏覽:860
pdf中圖片修改 瀏覽:288
匯編編譯後 瀏覽:491