freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

avr1000xmega的c語言代碼編寫入門-資料下載頁

2025-06-23 04:45本頁面
  

【正文】 an enumerator type will trigger a piler warning. This can be used to the programmers advantage. Imagine a function that sets the receive plete interrupt level for a USART module. If the function accepts the interrupt level as an integer type (. unsigned char), any legal or illegal value can be passed to the function. If the function instead accepts a parameter of type USART_RXCINTLVL_t, only the four predefined constants in the USART_RXCINTLVL_t enumerator can be passed to the function. Passing anything else will result in a piler warning. 每個(gè)枚舉符的常量單獨(dú)使用時(shí),其表現(xiàn)很像是一個(gè)普通的常數(shù)。然而,使用枚舉符的優(yōu)點(diǎn)在于創(chuàng)建一個(gè)新的數(shù)據(jù)類型。 USART_RXCINTLVL_t 就像是一個(gè)int或char 那樣,可以作為一個(gè)類型名使用。一個(gè)枚舉符常數(shù)完全可以作為整數(shù)使用,但是把一個(gè)整數(shù)賦給一個(gè)枚舉符類型,將會(huì)觸發(fā)一個(gè)編譯器警告。這可能是習(xí)慣了程序員的優(yōu)勢的緣故。試想一個(gè)函數(shù)設(shè)置一個(gè)USART模塊接收完成中斷級(jí)別,如果此函數(shù)接受中斷級(jí)別為整數(shù)類型(如無符號(hào)的字符),那么任何合法的或非法的值都可以傳遞給此函數(shù);如果此函數(shù)改為接受USART_RXCINTLVL_t類型的參數(shù),那么可以傳遞給此函數(shù)的就只有4個(gè)預(yù)先在USART_RXCINTLVL_t枚舉符中定義的常量。除此而外,給此函數(shù)傳遞任何其它參數(shù)都將會(huì)導(dǎo)致編譯器警告。Notice that the constants in Code Listing 314 are shifted to the actual bit position. This means that the enumerator contstants are the actual values that shall be written to the register. No additional shifting is needed. 請注意,在代碼列表314中的常量被轉(zhuǎn)移到當(dāng)前的位位置,這意味著枚舉符常量就是應(yīng)寫入該寄存器的當(dāng)前值,無需額外的轉(zhuǎn)移。 Functions Calls and Module Drivers 函數(shù)調(diào)用與模塊驅(qū)動(dòng)程序When writing drivers for module types that have multiple instances, the fact that all instances have the same register memory map, can be utilized to make the driver reusable for all instances of the module type. If the driver takes a pointer argument, pointing to the relevant module instance, the driver can be used for all modules of this type. When considering portability this represents a great advantage. 在為含有多個(gè)實(shí)例的模塊類型編寫驅(qū)動(dòng)程序時(shí),可以利用所有實(shí)例都具有相同的寄存器內(nèi)存映射這個(gè)事實(shí),來使驅(qū)動(dòng)程序可重復(fù)用于該模塊類型的所有實(shí)例。如果該驅(qū)動(dòng)程序需要一個(gè)指針參數(shù),指向相關(guān)的模塊實(shí)例,那么該驅(qū)動(dòng)程序可用于這種類型的所有模塊。然而,就可移植性而言,這就表現(xiàn)出了具有極大的優(yōu)勢。Consider a device with 8 Timers/Counters. The functions to initialize and access the Timer/Counter modules can be shared by all module instances. Even though there is a small overhead in passing the module pointer to the functions, the total code size will often be reduced because the code is reused for all instances of each module type. Even more important, development time, maintenance cost, and portability can be greatly improved by using this approach. 設(shè)想一個(gè)設(shè)備有8個(gè)計(jì)時(shí)器/計(jì)數(shù)器,初始化和訪問這些計(jì)時(shí)器/計(jì)數(shù)器模塊的函數(shù)可以讓所有模塊實(shí)例共享。即使在將模塊指針傳遞給函數(shù)的過程中有較小的開銷,但總的代碼大小往往會(huì)縮小,因?yàn)槊總€(gè)模塊類型的所有實(shí)例代碼是重復(fù)使用的。更重要的是,由于使用這種方法,可以使開發(fā)時(shí)間、維護(hù)成本以及可移植性都得到了極大的改善。Code Listing 315 shows a function that uses a modulepointer to select a clock source for any Timer/Counter module. 代碼列表315顯示了一個(gè)使用模塊指針的函數(shù)來選擇任何計(jì)時(shí)器/計(jì)數(shù)器模塊的時(shí)鐘源。Code Listing 315. Example function using module instance pointer 代碼列表315. 以使用模塊實(shí)例指針的函數(shù)為例The function takes two arguments: a module pointer of the type, TC_t, and a group configuration type, TC_CLKSEL_t. The code in the function uses the Timer Counter module pointer to access the CTRLA register to set a new clock selection for the Timer/Counter module provided through the tc parameter. 該函數(shù)采用了兩個(gè)參數(shù):一個(gè) TC_t 類型的模塊指針,和一個(gè) TC_CLKSEL_t 類型的組配置。函數(shù)中的代碼使用計(jì)時(shí)器計(jì)數(shù)器模塊指針來訪問 CTRLA 寄存器,以便設(shè)置新的時(shí)鐘選擇由 tc 參數(shù)提供的計(jì)時(shí)器/計(jì)數(shù)器模塊。Code Listing 316 shows how the function in Code Listing 315 can be used to configure different Timer/Counter modules with different clock selections. 代碼列表316顯示了如何將代碼列表315中的函數(shù)用于給各不相同的計(jì)時(shí)器/計(jì)數(shù)器模塊配置各不相同的時(shí)鐘選擇。Code Listing 316. Calling a function that takes a module pointer as parameter 代碼列表316. 調(diào)用的函數(shù)將模塊的指針作為參數(shù)4 Alternative Ways of Writing Code4. 編寫代碼的替代方式For convenience and to avoid forcing AVR programming veterans to change their programming style it is still possible to use a programming style that does not involve structs. It is also possible to use the bit name style that is used for megaAVR174。. This section briefly describes alternative ways of accessing registers and using bit names. 為了方便和避免AVR編程老手被迫改變自己的編程風(fēng)格,仍然可以使用一種不涉及結(jié)構(gòu)的編程風(fēng)格。還有可以使用megaAVR174。所用的位名稱的風(fēng)格。本節(jié)簡要介紹了訪問寄存器和使用位名稱的替代方法 Register Names 寄存器名It is possible to access any register without using the module structs. To refer to a register directly, concatenate the module instance name, an underscore and the register name. The same naming convention is used when programming in assembly. 不使用模塊結(jié)構(gòu)就可以訪問任何寄存器。要直接訪問寄存器,連接模塊的實(shí)例名稱、下劃線和寄存器名,在匯編語言編程時(shí)使用的相同的命名約定。Example: To access the CTRLA register of Timer/Counter C0, use the name TCC0_CTRLA. 例如:要訪問計(jì)時(shí)器/計(jì)數(shù)器C0的寄存器CTRLA,使用名稱TCC0_CTRLA Bit Positions 位位置It is possible to use bit masks to set or clear bits. A bits position within a register is defined using the same name as the bit mask, with an additional prefix, “_bp” for bit position. Code Listing 41 shows how the bit position can be used to configure a register. 可以使用位掩碼來設(shè)置或清除位。給一個(gè)寄存器內(nèi)的某個(gè)位位置定義使用與位掩碼相同的名稱,附加一個(gè)位位置的前綴“ _bp ”。代碼列表41顯示了如何用位位置來配置寄存器。Code Listing 41. Alternative register access code. 代碼列表41. 替代寄存器訪問代碼The bit position definitions are included for patibility reasons. They are also needed when programming in assembly for instructions that use a bit number. 位位置的定義包含有兼容性的原因,還需要在匯編語言編程中使用位編號(hào)時(shí)的指令。5 Summary 5 總結(jié)For reference, an overview of the different postfixes used when dealing with bit configuration is listed in Table 51. 我們將執(zhí)行位配置時(shí)所用到的各種后綴名的簡要介紹列在表51中,以供參考。Table 51. Overview of postfixes 表51. 后綴名的簡要介紹Using the suggested methods to write Ccode for XMEGA is by no means mandatory, but the advantages offered should be considered used to ensure robust, portable, reusable, and highly readable code. The larger the project, and the more features the device has the bigger the advantage. For small projects it can be argued that there is no benefit, but turning that argument upside down one can say that there is not disadvantage either. 采用建議的方法編寫XMEGAC語言代碼決無命令的意味,但應(yīng)考慮利用其所提供的優(yōu)勢,以確保穩(wěn)固、可移植、可重復(fù)使用以及具有很強(qiáng)的可讀性代碼。項(xiàng)目越大,功能越強(qiáng)的設(shè)備具有更大的優(yōu)勢。對(duì)于小型項(xiàng)目,可以推斷沒有什么優(yōu)勢,但把這種推論倒掛,可以說也沒有什么缺點(diǎn)。One thing is for sure: good code style is always an advantage.有一件事是肯定的:良好的編碼風(fēng)格總是有優(yōu)勢的。19 /
點(diǎn)擊復(fù)制文檔內(nèi)容
醫(yī)療健康相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1