BASIC4MCU | 질문게시판 | 답변 : codevision avr 질문입니다.
페이지 정보
작성자 master 작성일2020-12-02 16:41 조회2,197회 댓글0건본문
#include <mega128a.h>
#include <delay.h>
//
typedef unsigned char U8;
//
const U8 SEG_NUM[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int cnt=0;
//
interrupt [TIM0_COMP] void timer0_comp_isr(void){ // 1ms
U8 N1,N2,N3; int i; static s=0;
if(++cnt>=1000){ cnt=0;
i=ADCW;
i=(int)((float)i*500.0/1023.0+0.5); // 10mV 단위 전압 값으로 변환
N1=i/100; // 정수부 추출
N2=i/10%10; // 소수 첫째 자리 추출
N3=i%10; // 소수 둘째 자리 추출
}
//
switch(s){
case 0: PORTG=8; PORTD=(SEG_NUM[N3]<<4)|(PORTD&0x0F); PORTB=(SEG_NUM[N3]&0x70)|(PORTB&0x0F); break; // PG3=1,소수 둘째 자리
case 1: PORTG=4; PORTD=(SEG_NUM[N2]<<4)|(PORTD&0x0F); PORTB=(SEG_NUM[N2]&0x70)|(PORTB&0x0F); break; // PG2=1,소수 첫째 자리
case 2: PORTG=2; PORTD=(SEG_NUM[N1]<<4)|(PORTD&0x0F); PORTB=(SEG_NUM[N1]&0x70)|(PORTB&0x0F)|0x80; break; // PG1=1,정수부 // DP on(소수점)
}
if(++s>2)s=0;
}
//
void main(void){
DDRB=0xF0; DDRD=0xF0; DDRG=0x0F;
TCCR0=0x0D; OCR0=124; TIMSK=2; //16000000/128/(1+124),1ms
ADMUX=0x06; ADCSRA=0xE7;
SREG|=0x80;
while(1){}
}
댓글 0
조회수 2,197등록된 댓글이 없습니다.