46
1 微微微微 微微微微微微微微微 2007 2007 8 8 7 7

1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

  • View
    238

  • Download
    1

Embed Size (px)

Citation preview

Page 1: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

1

微控制器應用產品開發與實務

20072007 年年 88 月月 77 日日

Page 2: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

2Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

目錄目錄為何需要為何需要 MCUMCU ??可供開發使用的元件?可供開發使用的元件?如何撰寫如何撰寫 MCUMCU 程式?程式?範例說明。範例說明。結論。結論。

Page 3: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

3Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

為何需要為何需要 MCUMCU7:00 起床 / 刷牙 / 刮鬍子 [Alarm Clock, Elec. Brusher & Shaver] 7:15 煮咖啡 / 烤吐司 [Coffee Maker & Toaster]7:30 看電視 Morning News [TV Remote ]8:00 Drive to Office [Keyless Car Entry & Remote] 8:30 Turn on Computer [Mouse & Keyboard]9:30 Make Phone Calls/ Print Papers [Phone System & MFP]12:00 Heat Lunch [Microwave Oven]13:00 Exercise [ Jogging Machine & Pedometer]14:00 Soft Drink [Slot Machine]18:00 Turn on Air-conditioner [Remote Control]19:00 Make Dinner [ Rice Cooker & Induction Cooker & Refrigerator ]20:00 Listen to the music [ Remote Control ] Play with your Child [ Interaction Toys/ Learning Aids ] 21:30 Take a bath [ Instant Water Heater & Hair Dryer & Weight Scale] 22:00 Laundering [Washing Machine/ Dryer/ Steam Iron]22:30 Go to bed & have a good sleeping Of course : Don’t forget to charge you battery and get your home security system alarmed

Page 4: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

4

C/R-F Type MCU

HT45R36HT45R38

Page 5: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

5Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

User can add C

User can add R

Frequency

Changed

After Adding R or C10p

R1

R2

C1

10p C2

OscillationCircuits

Ex. f = 130kHz

10pInitial

R1

C1

OscillationCircuits

Ex. f = 100kHz

何謂何謂 C/R-FC/R-F

Page 6: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

6Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Part No. ROM RAM I/O

Timer InterruptC/R-F

Channel

LEDDriverOutput

A/D PWM OPA Stack Package

8-bit 16-bit Ext. Int.

HT45R36 2Kx14 120x8 9 1 1 2 5 16 8x8 --- --- --- 444QFP,52QFP

HT45R38 4kx15 192x8 13 2 1 2 5 12 8x8 12-bitx5 8-bitx2 1 6 52QFP

家族成員家族成員

Page 7: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

7Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Holtek8-Bit MCUCore

8-BitPWM

AnalogSignals

5 channel

OPA

Timer

2 channelPWM

Signals

1 channelCurrentSensing

OSCCircuit

R Sensor

C Sensor

LED Driver(High Current

Drive Port)8x8 LEDs

OscillatorExternal RC

HT45R38 only

VDD

Control I/O Key Inputs

12-BitADC

系統方塊圖系統方塊圖

Page 8: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

8Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

HT45R3644 QFP-A

HT45R3652 QFP-A

HT45R36HT45R36 接腳圖接腳圖

Page 9: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

9Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

HT45R3852 QFP-A

HT45R38HT45R38 接腳圖接腳圖

Page 10: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

10Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Symbol Parameter Test Conditions

Min. Typ. Max. UnitVDD Conditions

IOL1

PA, PB, PD0, RREF and CREF Sink Current

3VVOL=0.1VDD

4 8 --- mA

5V 10 20 --- mA

IOH1

PA, PC, PD0, RREF and CREF Source Current

3VVOH=0.9VDD

-2 -4 --- mA

5V -5 -10 --- mA

IOL2

PC Sink Current

(For LED Driver)

3VVOL=0.1VDD

8 16 --- mA

5V 20 40 --- mA

IOH2

PB Source Current

(For LED Driver)

3VVOH=0.9VDD

-4 -8 --- mA

5V -10 -20 --- mA

Ta=25ºC

DCDC 特性特性

Page 11: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

11Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Symbol Parameter

Test Conditions

Min. Typ. Max. UnitVDD Conditions

VDD Operating Voltage --- --- 3 --- 5.5 V

VOPOS Input Offset Voltage 5V After Calibration -2 --- +2 mV

CMRRCommon Mode Rejection Ratio

5V VCM=0~VDD-1.4V 60 --- --- dB

Ta=25ºC

HT45R38 OPA DCHT45R38 OPA DC 特性特性

Page 12: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

12Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Symbol Parameter Test Conditions Min. Typ. Max. unit

AOL Open Loop Gain --- 60 80 --- dB

SRSlew Rate +,Slew Rate -

No Load --- 1 --- V/uS

GBW Gain Bandwidth RL=1M, CL=100P --- --- 0.1 MHz

Ta=25ºC

HT45R38 OPA ACHT45R38 OPA AC 特性特性

Page 13: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

13Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Symbol Parameter Test Conditions Min. Typ. Max. Unit

VOS Comparator Input Offset Voltage

After Calibration-2 --- +2 mV

Vi Comparator Input Voltage Range

--- 0.2 --- VDD-0.8 V

Note: the OPA can be used as a comparator.

Ta=25ºC

HT45R38HT45R38 比較器特性比較器特性

Page 14: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

14Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

ASON is Channel Selection00000b=TG1 On, Others Off.00001b=TG2 On, Others Off.

………

01111b=TG16 On, Others Off.10000b=all TGs Off, Power Saving Mode

Timer B

OscillationCircuit

Unused bit ASON

b7 b6 b5 b4 b3 b2 b1 b0

--- --- --- 0 0 0 0 0

ASCR Register

C/R-FC/R-F 轉換圖轉換圖

Page 15: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

15Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Timer A

Timer B

RC OSC Output

T1ON

OVB=0

OVB=1

Interrupt

Reset T1ON

System Clock

System Clock/4

S1

S2

1. OVB=0, Timer A Overflow.2. OVB=1, Timer B Overflow.

1. RCO=0, Timer Mode and Timer B are Preloaded2. RCO=1, RC Mode

Timer B Count=1000RC OSC f=1MHz

1

2

3

Start Overflow

Timer A

Timer B

1ms

Unused bit RCO OVB

b7 b6 b5 b4 b3 b2 b1 b0

--- --- --- --- --- --- 0 0

RCOCR Register

計時轉換電路計時轉換電路

Page 16: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

16Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

S1

S2S3

OPP

OPN

PE0/AN0/OPO

+

-

PE0/AN0OPAOP

AOF0~AOF3 Low OffsetLow Offset

Note: the OPA can be used as a comparator

Use AOF0 ~ AOF3 to Configure the Offset Voltage.

HT45R38 Low offsetHT45R38 Low offset 調整調整

Page 17: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

17Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

The OPA/Comparator Diagram

Adjust Hysteresis

Schmitt Trigger

Adjust Offset Voltage to VCC/2

VCC

VCC/2

GND

VUTP

VLTP

VI

OffsetOffset 對輸出訊號的影響對輸出訊號的影響

Page 18: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

18Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

+

-

VCC

R1

R2

R3

R4

RC

RE

C1

C2

C3

V+

V-

A/D

AOF0~AOF3

Raise Gain

VCC/2

OPA Configuration and Method of Increasing Gain

如何增加如何增加 OPAOPA 的增益的增益

Page 19: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

19Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

HT45R36HT45R36 應用電路應用電路

Page 20: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

20Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

HT45R38HT45R38 應用電路應用電路

Page 21: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

21

A/D with OPA Type MCU

HT46R32 / HT46R34HT46R322 / HT46R342

Page 22: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

22Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Part No. ROM RAM I/O8-bit

Timer

InterruptLED

DriverOutput

PFD A/D PWM OPA Stack PackageExt. Int.

HT46R322Kx14 88x8 20 1 1 2

---V 12-bitx4 8-bitx2 1 6

28SKDIP,28SOP,28SSOP

HT46R322 8x8 44QFP

HT46R344kx15 192x8 20 1 1 2

---V 12-bitx4 8-bitx2 1 6

28SKDIP,28SOP,28SSOP

HT46R342 8x8 44QFP

家族成員家族成員

Page 23: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

23Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Program Memory 2K14 for HT46R32 and HT46R322 4Kx15 for HT46R34 and HT46R342

Data Memory 888 for HT46R32 and HT46R322 192x8 for HT46R34 and HT46R342

20 Bidirectional I/O Pins

8x8 High Current Drive Output (LED Driver) HT46R322 and HT46R342 only

Six-level Subroutine Nesting

Watchdog Timer (WDT)

HALT and Wake-up Feature Reduce Power Consumption

Low Voltage Reset (LVR)

家族特色家族特色

Page 24: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

24Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Holtek8-Bit MCUCore

8-BitPWM

AnalogSignals

4 channel

OPA

Timer /PFD

2 channelPWM

Signals

1 channelAnalog Signals

LED Driver(High Current

Drive Port)8x8 LEDs

External RC

Buzzer

Control I/O Key Inputs

VDD

HT46R322/342 only

12-BitADC

Oscillator

系統方塊圖系統方塊圖

Page 25: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

25Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

OPA Pin

HT46R32/34HT46R32/34 接腳圖接腳圖

Page 26: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

26Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

LED Driver orOther Applications

OPA Pin

HT46R322/342HT46R322/342 接腳圖接腳圖

Page 27: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

27Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

Max. 8x8=64 PixelLED Direct Driving

No External Transistors

應用電路應用電路

Page 28: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

28

A/D with USB Type MCU

HT46RB50HT46RB70

Page 29: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

29Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

RS232、 Printer Port、PS2 Port

RS232、 Printer Port、PS2 Port

RS232 、 Printer Port 、PS2 Port

RS232 、 Printer Port 、PS2 Port

Support Plug and Play, Auto Detection Easy to Expand, Support Up to 127 Devices Hot Plug Bus Power (max. 500mA from Host) / Self Power Different Speed Selection

Low Speed (1.5 Mbps) Full Speed (12 Mbps) High Speed (480 Mbps)

為何需要為何需要 USBUSB

Page 30: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

30Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

HT82K94E, HT82K95E, HT82K96E HT82J97E, HT82M99E

HT49RB50, HT49RB70

HT46RB50, HT46RB70

HT82A821R, HT82A822R

HT82A832R

Standard I/O USB

Standard ADC USB

ASSP Speaker USB

FullSpee

d

LowSpee

d

USB 2.0

Standard LCD USB

High Spee

d

High Spee

d

ASSP Phone USB

Holtek USB MCUHoltek USB MCU 成員成員

Page 31: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

31Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

HT46RB50, HT46RB70 all with SIO interface

HT46RB50/B70 with 1 and 2 bulk endpoint respectively

Note:

Part No. I/O

Timer InterruptEnd

PointA/D PWM SIO Stack Package

8-bit 16-bit Ext. Int.

HT46RB50

38 1 1 1 54

(8,8,8,64)10bitx8 8bitx2 V 6

28SKDIP,28SOP,48SSOP

HT46RB70

38 -- 2 1 56

(8,8,8,64,8,64)10bitx8 8bitx4 v 16

28SKDIP,28SOP,48SSOP

家族成員家族成員

Page 32: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

32Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Program Memory: 4Kx15 and 8Kx16 ROM

Data Memory: 192 bytes and 384 bytes RAM

Watchdog Timer (WDT)

Single Channel Serial Interface (SIO)

Up to 10-bit ADC 8 Channels

Up to 8-bit PWM 4 Channel Outputs

Up to 6/12MHz XTAL System Clock(register need to be set to 6MHz or 12MHz)

Low Voltage Reset Function (LVR)

家族特色家族特色

Page 33: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

33Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Internal 48MHz PLL frequency for Transceiver

Internal Regulator output 3.3V for D+ Pull-High

Full Speed USB (12 Mbps)

Support Remote Wake-up Function

HT46RB50 with 4 Endpoints (Endpoint 0~ Endpoint 3)

HT46RB70 with 6 Endpoints (Endpoint 0~ Endpoint 5) Endpoint 0: Control Pipe (Setup / Input / Output)

Endpoint 1, 2, 4: Interrupt Pipe (Input / Output)

Endpoint 3, 5: Bulk Pipe (Input / Output)

家族特色家族特色

Page 34: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

34Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Holtek8-bit MCUCore

SIO

Xtal 6/12MHz

VSS

D+

D-

V330

Byte TX

Regulator

1.5kPLL

FIFO

SIE

VDD

HOST

PWMAnalog Output

Filter

A/DAnalogSignal

Control I/O Key Input

系統方塊圖系統方塊圖

Page 35: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

35Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

Automatic Control

Data Collection

RS232 to USB Bridge

Handwriting System

Key Pad, Keyboard, Joystick…

應用電路應用電路

Page 36: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

36Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

為何為何 MCUMCU 需要程式需要程式

輸入單元IU

算術與邏輯單元ALU

輸出單元OU

控制單元CU

記憶體單元MU

表控制路線

表資料路線

CPU

什麼時間做什麼事。

遇到什麼狀況做什麼事。

Page 37: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

37Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

如何撰寫如何撰寫 MCUMCU 程式程式 程式語言依歷史演進可分為:

1. 機器語言。 0101010100011101

2. 低階語言,又稱組合語言。 每種 CPU 都有自己的組合語言。 利用英文替代 01010011 。 MOV A,01 、 AND A,FFH 、 ADD A,12H 。 80X86 、 8051 、 PIC16F877 、 ARM 等等。

3. 高階語言。 接近人類語言、更容易撰寫及閱讀 。 C 語言、 Basic 、 FORTRAN 、 COBOL 、 PASCAL 等等。

4. 物件導向語言。 把程式設計的概念物件化、具體化 。 Visual Basic 、 Visual C++ 、 Delphi 等等。

5. 自然語言。 人類口語化的語言 。

Page 38: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

38Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

談話內容可分為 3 類1. 敘述

今天我去小明家作客。 我看到一件漂亮的衣服。

2. 疑問 這是真的嗎? 我不相信!

3. 判斷 我覺得你在騙我。 肚子餓了。

人類談話內容歸類人類談話內容歸類

Page 39: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

39Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

程式撰寫內容歸類程式撰寫內容歸類程式撰寫內容可以分為 2 類:

1. 敘述 Sun=1+x X2+2x+1=0

2. 判斷 If x==1 While (x!=2)

Page 40: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

40Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

變數與副程式命名原則變數與副程式命名原則盡量少用無意義的數字與接腳,可將其命名。

#define True 1#define False 0#define SW0 _pa0

使用匈牙利命名法則變數以英文縮寫表示且第一個字大寫,可與指令或是暫存器名稱作區分,如遇一個英文字無法表示完成,可以用底線來完成。

mov Command_H,True sz SW0

副程式命名也是以此原則。 Init_IO_Port Init_Register

Page 41: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

41Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

結構化程式設計結構化程式設計何謂結構化程式設計?

由上而下的設計方式。 先定義設計最終目標,再細分構成最終目標所需的各部分,接著一直劃分到最基本元件。

模組化的設計方式。 對於副程式的變數傳遞只能一進一出。

只能用順序、選擇、重複等三種結構化特性來撰寫程式。

if-else, switch case for, while, do-while

禁用 goto 。善用註解與說明。

main

Scan_Key Disp_7Seg

delay BZ Hex_to_BCD

Page 42: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

42Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

程式撰寫方式程式撰寫方式

main

Scan_Key Disp_7Seg

Delay BZ Hex_to_BCD

按鍵顯示之程式架構圖

先撰寫 main主程式。撰寫 Scan_Key 副程式。撰寫 BZ 副程式。撰寫 Delay 副程式。

撰寫 Disp_7Seg 副程式。撰寫 Hex_to_BCD 副程式。

Page 43: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

43Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

程式測試方法程式測試方法

main

Scan_Key Disp_7Seg

Delay BZ Hex_to_BCD

按鍵顯示之程式架構圖

先針對硬體電路做測試。 先針對最基本的副程式作測試至完成為止。BZ 、 Delay 、 Hex_to_B

CD 測試過程中可以利用測試點的方式來做測試,例如利用 I/O Port 或是 HT-IDE3000 中的Watch視窗觀看執行過程是否有錯誤。

接著測試 Scan_Key 之副程式是否正常。

再者測試 Disp_7Seg 之副程式。

Page 44: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

44Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

程式撰寫與除錯程式撰寫與除錯

Watch Windows

RegisterWindows

Page 45: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

45Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

按鍵顯示實驗按鍵顯示實驗 DemoDemo 與說明與說明

Page 46: 1 微控制器 應用產品開發與實務 2007 年 8 月 7 日 Holtek Semiconductor 2 目錄 為何需要 MCU ? 可供開發使用的元件? 如何撰寫 MCU 程式? 範例說明。

46Holtek SemiconductorHoltek SemiconductorHoltek SemiconductorHoltek Semiconductor

結論結論生活中離不開 MCU 的產品。越來越多的硬體電路被加入到 MCU中。學習到變數如何命名。學習結構化程式寫法。如何利用 HT-IDE3000 之 Watch功能來進行程式除錯。