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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AVR AD轉(zhuǎn)換的C語言編程

          AVR AD轉(zhuǎn)換的C語言編程

          作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          #include

          #define uchar unsigned char
          #define uint unsigned int

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


          uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
          uchar Data[4]={0,0,0,0};

          void DelayMs(uint i) //0.25ms
          {uchar j;
          for(;i!=0;i--)
          {for(j=250;j!=0;j--) {;}}
          }

          void Display(uchar *p) //間隔5ms顯示
          {uchar i,sel=0x01;
          for(i=0;i<4;i++)
          {PORTB=sel;
          PORTC=0xff-Table[p[i]];
          DelayMs(20);
          sel=sel<<1;
          }
          }

          uint ADC_Convert(void)
          {uint temp1,temp2;
          temp1=(uint)ADCL;
          temp2=(uint)ADCH;
          temp2=(temp2<<8)+temp1;
          return(temp2);
          }

          void Process(uint i,uchar *p)
          {p[0]=i/1000;
          i=i%1000;
          p[1]=i/100;
          i=i%100;
          p[2]=i/10;
          i=i%10;
          p[3]=i;
          }

          /*
          void Timer0_Init(void)
          {SREG=SREG|0x80; //全局中斷開;
          TIMSK=TIMSK|0x01;//T/C0溢出中斷使能;
          TCCR0=0x05;//CLK/1024;128uS
          TIFR=0x01;//T/C0中斷標(biāo)志位寫1清0;
          TCNT0=256-125;//125*128us=16ms
          }*/


          void main(void)
          {uint i;
          //設(shè)置A口為不帶上拉輸入;
          DDRA=0x00;
          PORTA=0x00;
          //設(shè)置B口為推挽1輸出;
          DDRB=0xff;
          PORTB=0xff;
          //設(shè)置C口為推挽1輸出;
          DDRC=0xff;
          PORTC=0xff;
          //B口初始化輸出1;C口初始化輸出0;點(diǎn)亮全部數(shù)碼管;
          PORTB=0xff;
          PORTC=0x00;
          //ADC初始化;
          ADMUX=0x02;//選擇第三通道;
          ADCSR=0xe6;//125K轉(zhuǎn)換速率,自由轉(zhuǎn)換模式;啟動(dòng)AD轉(zhuǎn)換器;
          //延時(shí)待系統(tǒng)穩(wěn)定;
          DelayMs(3000);

          while(1)
          {i=ADC_Convert();
          Process(i,Data);
          Display(Data);
          }
          }

          /*#pragma interrupt_handler Timer0:10
          void Timer0()
          {Int_Cnt+=1;
          // Timer0_Init();

          }*/



          關(guān)鍵詞: AVRAD轉(zhuǎn)換C語言編

          評(píng)論


          技術(shù)專區(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); })();