Presentation is loading. Please wait.

Presentation is loading. Please wait.

SWITCH&7-SEG元件控制 嵌入式作業系統實作 11/17.

Similar presentations


Presentation on theme: "SWITCH&7-SEG元件控制 嵌入式作業系統實作 11/17."— Presentation transcript:

1 SWITCH&7-SEG元件控制 嵌入式作業系統實作 11/17

2 週邊I/O map IO_REG0 0X0C00 7 Segment(七段顯示器) IO_REG1 0X0C02
offset 說明 IO_REG0 0X0C00 7 Segment(七段顯示器) IO_REG1 0X0C02 Switch和Keypad讀入 IO_REG2 0X0C04 LED和Keypad Scan輸出 Ox3F00C06 IO_REG2 2byte = 16bits Ox3F00C04 IO_REG1 2byte = 16bits Ox3F00C02 IO_REG0 2byte = 16bits Ox3F00C00 Ox3F00000

3 各I/O之位元定義 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 IO_REG0 IO_REG1 IO_REG2
15 14 13 12 11 10 9 8 IO_REG0 SEG_H SEG_G SEG_F SEG_E SEG_D SEG_C SEG_B SEG_A COM3 COM2 COM1 COM0 IO_REG1 S1.7 S1.6 S1.5 S1.4 S1.3 S1.2 S1.1 S1.0 SCAN_ I3 I2 I1 I0 IO_REG2 SCAN_O3 SCAN_O2 SCAN_O1 SCAN_O0 D7 D6 D5 D4 D3 D2 D1 D0 bit Reg

4 DIP Switch & 7 Segment DIP SWITCH 7 Segment
Creator提供之switch(S1.0~S1.7),邏輯0代表ON,邏輯1代表OFF 7 Segment Creator提供之7段顯示器的7個LED(SEG_A~SEG_G)以及1個小數點(SEG_H),邏輯0代表亮,邏輯1代表滅

5 7 Segment  IO_REG0 = 0xfe92 (在COM0顯示5) COM0 = 0 則 D5 會亮 若要顯示數字5,則
SEG_A = SEG_F = SEG_G = SEG_C = SEG_D = 0 SEG_B = SEG_E = SEG_H = 1  IO_REG0 = 0xfe92 (在COM0顯示5)

6 7 Segment 數字 0xc0 1 0xf9 2 0xa4 3 0xb0 4 0x99 5 0x92 6 0x82 7 0xd8 8
SEG_H SEG_G SEG_F SEG_E SEG_D SEG_C SEG_B SEG_A 0xc0 1 0xf9 2 0xa4 3 0xb0 4 0x99 5 0x92 6 0x82 7 0xd8 8 0x80 9 0x98

7 使SEG_A~SEG_H不亮 並且關閉COM0~COM3
顯示多個七段顯示器一同顯示 由於IO_REG0只有一組顯示七段顯示器的輸出,而4510的版子卻有4組七段顯示器,如何一起顯示出多個七段顯示器 ? 利用RC充放電非瞬間 可完成 使SEG_A~SEG_H不亮 並且關閉COM0~COM3 重新輸入想要的COM 以及七段顯器 Delay(10) 使其充電達到一定亮度

8 變數定義 (def.h) #define U32 unsigned int #define U16 unsigned short
#define S32 int #define S16 short int #define U8 unsigned char #define S8 char #define UL U32 #define UI U16 #define UC U8 #define C S8 #define I S16 #define L S32 /*** return flag ***/ #define OK #define YES #define ON #define TRUE 1 #define FALSE 0 #define UM #define OFF #define NO #define STRMATCH 0

9 Example UC ch; ch = IO_REG1; Ch為8 bits變數, IO_REG1為16 bits
故 ch = IO_REG1 取 IO_REG1 較低8位元為變數存放值 IO_REG1 S1.7 S1.6 S1.5 S1.4 S1.3 S1.2 S1.1 S1.0 SCAN_ I3 I2 I1 I0

10 範例程式 //number array int number[10] = {0x0fc0, 0x0ff9, 0x0fa4, 0x0fb0, 0x0f99,0x0f92, 0x0f82, 0x0fD8, 0x0f80, 0x0f98}; //segment array int seg[4] = {0x0eff, 0x0dff, 0x0bff, 0x07ff};

11 範例程式 void segment(int com, int value) { //what segment will light
IO_REG0 = seg[com]; //what number will light IO_REG0 &= number[value]; }

12 範例程式(1) int main(void) { unsigned char dip; while(1) {
segment(3,7); //display “7” in COM3 } return 0;

13 範例程式(2) int main(void) { unsigned char dip; while(1) {
IO_REG0 = 0x0fff; //clear all seg & com segment(3,7); Delay(10); segment(2,6); // display “7” in COM3 and “6” in COM2 } return 0;

14 實習 實習一:將範例上的七階顯示器的程式改成顯示為閃爍的〝5684〞
實習二:將範例上的七階顯示器的程式改成以SWITCH的二進位來控制的七 段顯示器(範圍0~255,顯示為10進位) EX:  b  “7”  0007 實習三:實作出一個可即時改變上數下數的記數器,每0.4s跳動一次,並以swtich0做開關控制(範圍0~9999) (swtch0 off = 上數) (swtch0 ON = 下數) (當9999往上數0000) (當0000往下數9999) 作完請找助教檢查


Download ppt "SWITCH&7-SEG元件控制 嵌入式作業系統實作 11/17."

Similar presentations


Ads by Google