Page 26 - PIC18F4550微處理機C語言設計實務
P. 26

PIC18F4550 ฆஈଣዚ C ႧԊணࠇྼਕ


                       ˸ char މԷd1 ࡈ Byte މ 8 ࡈ bit€bit7ä0d͜ 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
   21   22   23   24   25   26   27   28   29   30   31