<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          atmega16串口通信

          作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏

          USART 波特率寄存器- UBRRL和UBRRH

          UCSRC寄存器與UBRRH寄存器共用相同的I/O地址。

          • Bit 15 – URSEL: 寄存器選擇

          通過(guò)該位選擇訪問(wèn)UCSRC 寄存器或UBRRH 寄存器。當(dāng)讀UBRRH 時(shí),該位為0 ;當(dāng)寫(xiě)UBRRH 時(shí), URSEL 為0。

          • Bit 14:12 – 保留位

          這些位是為以后的使用而保留的。為了與以后的器件兼容,寫(xiě)UBRRH 時(shí)將這些位清零。

          • Bit 11:0 – UBRR11:0: USART 波特率寄存器

          這個(gè)12 位的寄存器包含了USART 的波特率信息。其中UBRRH 包含了USART 波特率高4 位,UBRRL 包含了低8 位。波特率的改變將造成正在進(jìn)行的數(shù)據(jù)傳輸受到破壞。寫(xiě)UBRRL 將立即更新波特率分頻器。

          進(jìn)行通信之前首先要對(duì)USART 進(jìn)行初始化。初始化過(guò)程通常包括波特率的設(shè)定,幀結(jié)構(gòu)的設(shè)定,以及根據(jù)需要使能接收器或發(fā)送器。對(duì)于中斷驅(qū)動(dòng)的USART 操作,在初始化時(shí)首先要清零全局中斷標(biāo)志位( 全局中斷被屏蔽)

          串口初始化:

          使用串口->使能接收 ->使能發(fā)送->波特率(本例使用 9600)->奇偶校驗(yàn)(disable)->數(shù)據(jù)位數(shù)(8bit)->中斷(RX Complete interrupt)

          //ICC-AVR application builder : 2007-5-10 下午 08:51:56

          // Target : M16

          // Crystal: 11.059Mhz

          //UART0 initialisation

          // desired baud rate: 9600

          // actual: baud rate:9600 (0.0%)

          // char size: 8 bit

          // parity: Disabled

          void uart0_init(void)

          {

          UCSRB = 0x00; //disable while setting baud rate

          UCSRA = 0x00;

          UCSRC = 0x86;

          UBRRL = 0x47; //set baud rate lo

          UBRRH = 0x00; //set baud rate hi

          UCSRB = 0x98;

          }

          //省略了端口初始化

          //call this routine to initialise all peripherals

          void init_devices(void)

          {

          //stop errant interrupts until set up

          CLI(); //disable all interrupts

          port_init();

          uart0_init(); //注意這句 調(diào)用串口初始化

          MCUCR = 0x00;

          GICR = 0x00;

          TIMSK = 0x00; //timer interrupt sources

          SEI(); //re-enable interrupts

          //all peripherals are now initialised


          上一頁(yè) 1 2 3 下一頁(yè)

          關(guān)鍵詞: atmega16串口通

          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();