Switch 7 seg
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

SWITCH&7-SEG 元件控制 PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on
  • Presentation posted in: General

SWITCH&7-SEG 元件控制. 嵌入式作業系統實作 11/17. 週邊 I/O map. Ox3F00C06. 2byte = 16bits. IO_REG2. Ox3F0 0C04. IO_REG1. 2byte = 16bits. Ox3F0 0C02. IO_REG0. 2byte = 16bits. Ox3F0 0C00. Ox3F00000. 各 I/O 之位元定義. bit. Reg. DIP Switch & 7 Segment. DIP SWITCH

Download Presentation

SWITCH&7-SEG 元件控制

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Switch 7 seg

SWITCH&7-SEG元件控制

嵌入式作業系統實作

11/17


I o map

週邊I/O map

Ox3F00C06

2byte = 16bits

IO_REG2

Ox3F00C04

IO_REG1

2byte = 16bits

Ox3F00C02

IO_REG0

2byte = 16bits

Ox3F00C00

Ox3F00000


Switch 7 seg

各I/O之位元定義

bit

Reg


Dip switch 7 segment

DIP Switch & 7 Segment

  • DIP SWITCH

    • 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代表滅


7 segment

7 Segment

  • 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)


7 segment1

7 Segment


Switch 7 seg

顯示多個七段顯示器一同顯示

  • 由於IO_REG0只有一組顯示七段顯示器的輸出,而4510的版子卻有4組七段顯示器,如何一起顯示出多個七段顯示器 ?

  • 利用RC充放電非瞬間可完成

使SEG_A~SEG_H不亮並且關閉COM0~COM3

重新輸入想要的COM 以及七段顯器

Delay(10) 使其充電達到一定亮度


Def h

變數定義 (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 ULU32

#define UIU16

#define UCU8

#define CS8

#define IS16

#define LS32

/*** return flag ***/

#define OK 1

#define YES 1

#define ON 1

#define TRUE 1

#define FALSE 0

#define UM 0

#define OFF 0

#define NO 0

#define STRMATCH 0


Example

Example

UC ch;

ch = IO_REG1;

Ch為8 bits變數, IO_REG1為16 bits

故 ch = IO_REG1 取 IO_REG1 較低8位元為變數存放值

7 6 5 4 3 2 1 0

15 14 13 12 11 10 9 8


Switch 7 seg

範例程式

  • //number array

    int number[10] = {0x0fc0, 0x0ff9, 0x0fa4, 0x0fb0, 0x0f99,0x0f92, 0x0f82, 0x0fD8, 0x0f80, 0x0f98};

  • //segment array

    int seg[4] = {0x0eff, 0x0dff, 0x0bff, 0x07ff};


Switch 7 seg

範例程式

  • void segment(int com, int value)

    {

    //what segment will light

    IO_REG0 = seg[com];

    //what number will light

    IO_REG0 &= number[value];

    }


Switch 7 seg

範例程式(1)

  • int main(void){

    unsigned char dip;

    while(1){

    segment(3,7); //display “7” in COM3

    }

    return 0;

    }


Switch 7 seg

範例程式(2)

  • int main(void) {

    unsigned char dip;

    while(1) {

    IO_REG0 = 0x0fff; //clear all seg & com

    segment(3,7);

    Delay(10);

    IO_REG0 = 0x0fff; //clear all seg & com

    segment(2,6);

    Delay(10);

    // display “7” in COM3 and “6” in COM2

    }

    return 0;

    }


Switch 7 seg

實習

實習一:將範例上的七階顯示器的程式改成顯示為閃爍的〝5684〞

實習二:將範例上的七階顯示器的程式改成以SWITCH的二進位來控制的七 段顯示器(範圍0~255,顯示為10進位)

EX:  00000111b  “7”  0007

實習三:實作出一個可即時改變上數下數的記數器,每0.4s跳動一次,並以swtich0做開關控制(範圍0~9999)(swtch0 off = 上數) (swtch0 ON = 下數)

(當9999往上數0000) (當0000往下數9999)

作完請找助教檢查


  • Login