BASIC4MCU | 8051/PIC | DT-516 강좌 | DT516-064.c ADC 인터럽트사용 전압표시
페이지 정보
작성자 키트 작성일2017-08-23 13:17 조회1,094회 댓글0건첨부파일
본문
//-------------------------------------------------------------
// 82G516 E/V BOARD ( DT-516 )
//-------------------------------------------------------------
// XTAL : 22.1184Hz
//-------------------------------------------------------------
// filename: DT516-064.c
// ADC 인터럽트사용 전압표시
//-------------------------------------------------------------
#include
//
#include "DT516-main.h"
//
U_C pwm[16]={100};
U_I count=0;
//
U_C adc_cnt=0;
U_I adc_sum=0, ADC_I=0;
bit adc_flg=0;
//
void ADC_Interrupt(void) interrupt 9{ // ADC_Interrupt:
adc_sum+=((ADCH<<8) + ADCL);
if(++adc_cnt>=64){ adc_cnt=0; ADC_I=adc_sum/64; adc_sum=0; adc_flg=1; }
ADCTL=0xE8;
}
//
void Timer_0_Interrupt(void) interrupt 1{ // 7200Hz주기
P4=0xFF; // FND OFF
switch(FND_CNT){
case 0: P0=Seg_Data[count/1000]; FND_COM1=0; break;
case 1: P0=Seg_Data[(count/100)%10]&0x7F; FND_COM2=0; break;
case 2: P0=Seg_Data[(count/ 10)%10]; FND_COM3=0; break;
case 3: P0=Seg_Data[count%10]; FND_COM4=0; break;
}
if(++FND_CNT>3)FND_CNT=0;
//
if(delay_buf){ if(--delay_buf==0)delay_flg=1; }
}
//
//
void main(){
AUXR=(AUXR|0x40); P1=0xFF; P1M0=0xFF; P1M1=0; //P1.ch Hi-impedance input//ADCH=상위(BIT9,8) ADCL=하위
ADCTL=0xE8; AUXIE=2; // ADC0 인터럽트 이네이블
TMOD=2; ET0=1; TR0=1;
EA=1;
while(1){
if(adc_flg){ adc_flg=0;
count=(U_I)((float)ADC_I * 500.0 / 1023.0);
}
}
}
//-------------------------------------------------------------
ADC0의 전압을 표시 하는 예제입니다.
댓글 0
조회수 1,094등록된 댓글이 없습니다.