Page 29 - PIC18F4550微處理機C語言設計實務
P. 29
ሔଡ଼ΥႧԊձ C ႧԊ 1
const:
ίᜊᅰΤ၈ۃࠦᅺͪ constdԨٜટረʚ੬ᅰ࠽f߰ᜊᅰ܁ѓމ੬ᅰdۆڌͪϤᅰ
މʔ̙һҷdᇜᙇኜۆึਗ਼Ϥᜊᅰᓖ׳ίόাኳٙЗໄʕdν؈ᇜᙇኜ೯ତϞ
ɛΆྡᜊһdึ೯̈ᙆѓৃࢹf
Էνj
const unsigned char Var1 = 123; // Var1 ܁ѓމ੬ᅰ 123
Var1 = 0; // Άྡᜊһ੬ᅰ Var1 ۆᇜᙇኜึ೯̈ᙆѓ
volatile:
ΪᏐᇜᙇኜतd߰ᜊᅰ܁ѓމϤdۆڌͪϤᜊᅰ࠽ᎇ̙ࣛঐҷᜊdϾ˲ᇜᙇ
ழ߰ආБ௰Գʷࣛdɰʔึਗ਼ϤᜊᅰٙהϞਗЪ՟ऊfɓছԴ͜ volatile ڌͪމ
մᗙٙᅲπኜTimer, UARTneא٫݊ᅲπኜึΪމ̮፩ɝϾҷᜊPORTe
א݊ίʕᓙՌό༁ࠦהԴٙ͜ᜊᅰeᒔ݊ʔซ௰Գʷࡌҷٙᜊᅰf
Էνj
static volatile unsigned char PORTA @ 0x05;
ڌͪ PORTA வࡈЗ 0x05 Зѧٙᜊᅰd̙ঐᎇࣛΪމՉ˼Ϊ९ҷᜊՉʫ࢙fԷ
νᛘ՟ PORTA ٙ࠽ܝdટഹࠅԱኽ༈࠽̘ਂкᓙϾӔ֛ʱ҉ٙਗЪࣛdᇜᙇኜ੬ึ
މə௰Գʷdఱ̥ᛘɓϣ PORTA ܝdఱɓٜਂਸ਼кᓙdӚΎ̘ࠠᛘ PORTAdԴ
ɝೌᇊਸ਼f܁ѓމ volatile ࣛdᇜᙇኜʔึމəಯˇόڗܓϾ̘ਂࠠልᛘ՟
PORTA ٙਗЪf
presistent:
߰ᜊᅰ܁ѓމϤdۆڌͪϤᜊᅰί MCU ක઼ਗࣛʫ࢙ԨʔึৰdϾ˲Ϥ
ᜊᅰึၾՉ˼ᜊᅰπ׳ίʔΝٙাኳЗໄf
Էνj
persistent long reset_count;
ڌͪ reset_count வࡈᜊᅰԨʔึΪމ MCU ࠠอ઼ਗࣛϾৰމཧdה˸̙˸
ίόකଢ଼̋ϤᜊᅰϾٝࠠอ઼ਗٙϣᅰf
19