AVR 1 include mega 128 h delay h

  • Slides: 13
Download presentation

AVR 프로그램(1) #include <mega 128. h> <delay. h> <stdio. h> <math. h> #asm. equ

AVR 프로그램(1) #include <mega 128. h> <delay. h> <stdio. h> <math. h> #asm. equ __lcd_port=0 x 1 B ; PORTA #endasm #include <lcd. h> LCD를사용 #define ADC_VREF_TYPE 0 x 40 int i; unsigned char string[20] = {0, }; unsigned int lux = 0; float adc = 0; float sum = 0; unsigned int read_adc(unsigned char adc_input) { ADMUX=adc_input | (ADC_VREF_TYPE & 0 xff); delay_us(10); ADCSRA|=0 x 40; while ((ADCSRA & 0 x 10)==0); ADCSRA|=0 x 10; return ADCW; } ADC 설정

AVR 프로그램(2) void main(void) { PORTF=0 x 00; DDRF=0 x 00; while (1) {

AVR 프로그램(2) void main(void) { PORTF=0 x 00; DDRF=0 x 00; while (1) { // Place your code here sum = 0; ACSR=0 x 80; SFIOR=0 x 00; for(i=0; i<10; i++) { sum += read_adc(0); } adc = sum/10; ADMUX=ADC_VREF_TYPE & 0 xff; ADCSRA=0 x 86; lcd_init(16); lcd_clear(); lux = 8 * 0. 00001 * exp(0. 0261 * adc); sprintf(string, "ACD = %d", read_adc(0)); lcd_gotoxy(0, 1); lcd_puts(string); lcd_gotoxy(0, 0); sprintf(string, "LUX = %d", lux); lcd_puts(string); lcd_gotoxy(0, 1); sprintf(adcstring, "ACD = %. f", adc); 각 포트와 INT부분을 설정하는 구문 delay_ms(1000); lcd_clear(); }; } LCD로 화면에 출력 하는 구문