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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ATMEGA16驅(qū)動(dòng)內(nèi)部EEPROM程序

          ATMEGA16驅(qū)動(dòng)內(nèi)部EEPROM程序

          作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏
          // 8MHZ晶體在ATMEGA16上運(yùn)行

          // 顯示效果:顯示按鍵設(shè)定數(shù)字
          #include
          #include
          #define uchar unsigned char
          #define uint unsigned int
          #pragmadata:code
          const uchar table[]="I LIKE AVR !";
          const uchar table1[]="WWW*FUMANCHE*COM";
          const uchar table_num[]="01234567890";

          本文引用地址:http://www.ex-cimer.com/article/201611/323964.htm

          void delay(uint ms)//延時(shí)
          {
          uint i,j;
          for(i=0;i {
          for(j=0;j<1142;j++);
          }
          }
          void write_com(uchar com) //寫(xiě)指令
          {
          PORTD&=~BIT(4);
          PORTD&=~BIT(5);
          PORTC=com;
          PORTD|=BIT(6);
          delay(1);
          PORTD&=~BIT(6);
          }

          void write_dat(uchar dat) //寫(xiě)數(shù)據(jù)
          {
          PORTD|=BIT(4);
          PORTD&=~BIT(5);
          PORTC=dat;
          PORTD|=BIT(6);
          delay(1);
          PORTD&=~BIT(6);
          }

          /*EEPROM讀取函數(shù)*/
          /*addr:地址;number:長(zhǎng)度;p_buff:讀出數(shù)據(jù)存放指針*/

          void eprom_read(unsigned int addr, unsigned char number, unsigned char *p_buff)
          {

          while(EECR & (1 << EEWE));

          EEARH = 0x00;

          while(number --)
          {
          EEARL = addr ++;
          EECR |= (1 << EERE);
          *p_buff++ = EEDR;
          }
          }
          /*EEPROM寫(xiě)入函數(shù)*/
          /*addr:地址;number:長(zhǎng)度;p_buff:寫(xiě)入數(shù)據(jù)存放指針*/

          void eprom_write(unsigned int addr, unsigned char number, unsigned char *p_buff)
          {

          EEARH = 0x00;

          while(number --) {
          while(EECR & (1 << EEWE));
          EEARL = addr ++;
          EEDR = *p_buff ++;
          EECR |= (1 << EEMWE);
          EECR |= (1 << EEWE);
          }
          }

          void main()
          {

          uchar i;
          uchar bai,shi,ge,temp;
          DDRB = 0xf0; //PB口低四位設(shè)為輸入
          PORTB = 0x0f; //PB口低四位上拉電阻使能
          DDRC=0XFF; //液晶端口設(shè)定為輸出
          DDRD|=BIT(4)|BIT(5)|BIT(6);

          delay(250); //加入延時(shí),避免影響干擾下一句
          PORTD&=~BIT(6);

          write_com(0X38); //液晶初始化
          delay(5);
          write_com(0X01); //顯示清屏
          delay(5);
          write_com(0X0C); //開(kāi)顯示
          delay(5);
          // write_com(0X0F); //顯示光標(biāo)并閃爍
          // delay(5);
          delay(250); //啟動(dòng)延時(shí)
          eprom_read(0x10, 0x01, &temp);//讀出記錄

          while(1)
          {
          if(PINB==0x0e) //PB0按鍵檢測(cè)
          {
          delay(250); //啟動(dòng)延時(shí)
          eprom_read(0x10, 0x01, &temp);//讀出記錄
          temp++; //刷新記錄
          eprom_write(0x10, 0x01, &temp);//寫(xiě)入記錄
          }
          while(PINB==0x0e); //當(dāng)按鍵始終按下時(shí)等待

          if(PINB==0x0d) //PB1按鍵檢測(cè)
          {
          delay(250); //啟動(dòng)延時(shí)
          eprom_read(0x10, 0x01, &temp);//讀出記錄
          temp--; //刷新記錄
          eprom_write(0x10, 0x01, &temp);//寫(xiě)入記錄
          }
          while(PINB==0x0d);


          delay(5);
          ge=temp%10;
          shi=temp%100/10;
          bai=temp/100;
          write_com(0X80+0X06);//數(shù)據(jù)起始指針設(shè)置--重新設(shè)置為這個(gè)地址開(kāi)始存放數(shù)據(jù)
          write_dat(table_num[bai]);
          delay(5);
          write_dat(table_num[shi]);
          delay(5);
          write_dat(table_num[ge]);
          delay(5);

          write_com(0X80+0X40);//數(shù)據(jù)起始指針設(shè)置
          delay(5);
          for(i=0;i<16;i++) //循環(huán)13次顯示內(nèi)容
          {
          write_dat(table1[i]);
          delay(5);
          }
          /*
          for(i=0;i<16;i++) //循環(huán)16次從LCD屏幕左邊一直顯示到右邊
          {
          write_com(0X1c);
          delay(500);
          }
          */

          }
          }
          //本程序通過(guò)驗(yàn)證,運(yùn)行穩(wěn)定??!



          關(guān)鍵詞: ATMEGA16EEPRO

          評(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); })();