Page 26 - PIC18F4550微處理機C語言設計實務
P. 26
PIC18F4550 ฆஈଣዚ C ႧԊணࠇྼਕ
˸ char މԷd1 ࡈ Byte މ 8 ࡈ bitbit7ä0d͜ signed ܁ѓٙᜊᅰۨ࿒މϞ੭
͍ࠋୌᅰd˸ bit7 މୌЗʩiϾ unsigned މʔ੭ୌᅰf
signed char ̙ڌͪᇍఖމ –128ä127dunsigned char ᇍఖމ 0ä255fᔊఊԸႭd
߰ࠅπ׳ࠋᅰٙᅰ࠽ఱࠅਗ਼ᜊᅰ܁ѓϓϞᅰd˲̀Ͻᅇᜊᅰڗܓ݊щԑπ׳༈
ᅰ࠽f
ίᅠᄳ C ႧԊٙࣛࡉdৰəόᇁึЦ͜ՑόাኳPIC ʫٙ Program
memoryʘ̮dɰ̀ࠅԴ͜ՑᜊᅰdϾவԬᜊᅰ݊׳ໄί PIC ʫٙ RAMdί
όٙੂБཀʕdᜊᅰٙʫ࢙ึʔᓙٙᜊʷdШ݊ίόԴ͜ʘۃɓ֛ࠅԫ̋˸܁
ѓdᜫᇜᙇኜٝ༸הԴٙ͜ӊɓࡈᜊᅰٙɽʃdԨ˲މӊɓࡈᜊᅰʱৣাኳRAM
Зѧf܁ѓᜊᅰٙႧجνɨj
ᜊᅰۨ࿒ ᜊᅰΤ၈ ;
Էνj
char var1; // ܁ѓᜊᅰ var1dᜊᅰۨ࿒݊οʩ
unsigned int var2; // ܁ѓᜊᅰ var2dᜊᅰۨ࿒݊ೌୌᅰ
܁ѓᜊᅰٙࣛࡉɓ֛ࠅϽඎՑӊɓࡈᜊᅰίόʘʕԴ̙ࣛ͜ঐٙ௰ʃ࠽ձ௰ɽ
࠽d್ܝΎ፯͍ᆽٙᜊᅰۨ࿒̋˸܁ѓd߰፯፹ႬdϞ̙ঐίό༶Ъʕପ͛ɓ
Ԭࠇၑ፹ႬdவԨʔ݊ᇜᙇኜ̙˸кᓙ̈Ըd̀ࠅόᅠᄳٙɛІʊءจf
Էνj
unsigned char var1,var2,var3;
var1 = 100;
var2 = 200;
var3 = var1+var2;
ɪࠦٙԷɿ̙˸Ցdɓක܁ѓəɧࡈᜊᅰ var1evar2evar3 ே݊ unsigned
chardה˸ɧࡈᜊᅰٙ௰ɽ࠽ே݊ 255dvar1 ၾ var2 ٙڋ࠽ɓࡈ݊ 100 ̤ɓࡈ݊
200dே݊ୌΥ unsigned char ٙ࠽ɽ࠽dШ݊௰ܝҪ var1+var2 ٙ࠽׳ɝ var3 ఱึ೯͛
ਪᕚdίό༶ၑɪҎૐ var3 ݊ var1 ၾ var2 ٙ̋ᐼ࠽މ 300dШ݊ var3 ٙ௰ɽ࠽̥
ঐ݊ 255dה˸௰ܝ var3 ٙഐ؈ึᜊϓ݊ 44dΪމ൴ཀ 255 ٙʱਗ਼ึආЗՑɨɓࡈ
Byted̥वɨ௵ቱٙʱf
300 - 256=44
16