日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 電源 > 數(shù)字電源
[導讀]2051的比較器模擬AD源程序(C語言)/* io分配: * ;* OUTPUT: * ;* P1.0 ...... 模擬量輸入 * ;* P1.1

2051的比較器模擬AD源程序(C語言)

/* io分配:                                       *
;*   OUTPUT:                                                    *
;*      P1.0 ...... 模擬量輸入     *
;*      P1.1 ...... DA輸入比較基準電壓    *
;*      P1.2~7..... R-2R DA電阻網(wǎng)絡    *
;*      P3.7 ...... LED 模擬亮度輸出    *
;* CPU CLOCK EQU 6M                                             */
//xiaoqi last edit in 2001.11
//#pragma src
#i nclude "AT89x051.h"
#i nclude <stdlib.h>
#i nclude<math.h>
#i nclude<intrins.h>

//變量類型標識的宏定義,大家都喜歡這么做
#define Uchar unsigned char
#define Uint unsigned int

#define Ledlight() (P3 &= 0x7f)
#define Leddark()  (P3 |= 0x80)

sbit P36 = P3^6;  // 比較器內(nèi)部判斷腳
sbit LED = P3^7;  // 一個發(fā)光二級管觀察亮度變化

// 內(nèi)部標志位定義
bit less;   // 比較是否大于 1.小于,0.大于

// 全局變量定義
Uchar timer1,          // 通用延時計數(shù)器
 timer2,          // 按鍵蜂鳴器反應定時器
 adcdata,  // ad轉(zhuǎn)換變量
 pwm1;   // PWM輸出比例

// 函數(shù)列表
void DelayMs(unsigned int number);      // 毫秒延時
void timers0();           // 在定時器中斷中做數(shù)碼管的掃描顯示(ct0)
void Initall(void);          // 系統(tǒng)初始化
void timers1(void);          // TC1定時器中斷用于掃描顯示與鍵盤
Uchar adcread(void);   // adc轉(zhuǎn)換程序

void main(void)  using 0
{
 DelayMs(120);
 Initall();
 pwm1 = adcread();
 LED=1;
 while(1)
 {
  pwm1 = adcread();
  timer2=10;
  while (timer2);
 }
}

// 毫秒延時
void DelayMs(unsigned int number)
{
 unsigned char temp;

 for(;number!=0;number--)
  for(temp=112;temp!=0;temp--);
}

/*************************************
   在定時器中斷中做LED的PWM輸出
*************************************/
void timers0() interrupt 1 using 1
{
 TH0 = 0xff;
 TL0 = 0xd0;
 timer1--;
 if (timer1==pwm1)LED=0;
 if (timer1==0){
  LED=1;
  timer1=0x40;
  timer2--;
  };
}

/****************[!--empirenews.page--]
;* 6位 ADC轉(zhuǎn)換
;****************/
Uchar adcread(void)
{
 Uchar i=0x3f,temp=0;
 P36 =1;
 P1 = 3; _nop_();_nop_();  // 從零開始
 while ((i--)&& (P36))
  {
  temp += 4;
  P1 = temp|3;
  _nop_();
  }
 temp >>= 2;
 return temp;
}

/****************
;* 系統(tǒng)初始化
;****************/
void Initall(void)
{
 TMOD = 0x11;  // 0001 0001 16進制計數(shù)器
 IP = 0x8;  // 0000 1000 t1優(yōu)先
        IE = 0x8A;  // 1000 1010 t0,t1中斷允許
 TCON = 5;  // 0000 0101 外部中斷低電平觸發(fā)
        TR0 = 1;  // 打開定時器中斷,IE中已經(jīng)打開,在明示一下
 TR1 = 0;
        ET0 = 1;
 ET1 = 0;
        P1 = 0xff;
}
 
/*************************************
   TC1定時器中斷用于掃描顯示與鍵盤(ct1)
*************************************/
void timers1(void) interrupt 3 using 2
{
_nop_();  //實驗中沒有啟用
}

本站聲明: 本文章由作者或相關機構(gòu)授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉