반응형
Analog to Digital Converter
ADC 레지스터
ADMUX
ADCSRA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 |
/*
* GccApplication1.cpp
*
* Created: 2018-09-04 오전 11:21:22
* Author : USER
*/
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
#include "lcd.h"
#include <stdio.h>
#include <stdlib.h>
#define LED_SEL1 (*(volatile unsigned char *)0xA000)
#define LED_SEL2 (*(volatile unsigned char *)0xB000)
#define FND (*(volatile unsigned char *)0x8000)
void io_init(void)
{
MCUCR|=(1<<SRE) | (1<<SRW10);
XMCRA=(1<<SRL2) | (0<<SRL1) | (0<<SRL0) | (1<<SRW01) | (1<<SRW00) | (1<<SRW11);
XMCRB |= 0x00;
}
void fndController (char loc , char number){
FND = (number <<3)|loc;
}
void fndDisplay (unsigned long long number){
fndController(5,number%10);_delay_ms(1);
fndController(4,(number%100)/10);_delay_ms(1);
fndController(3,(number%1000)/100);_delay_ms(1);
fndController(2,(number%10000)/1000);_delay_ms(1);
fndController(1,(number%100000)/10000);_delay_ms(1);
fndController(0,number/100000);_delay_ms(1);
}
int main(void)
{
io_init();
lcd_init();
lcd_clear();
ADCSRA = 0xe7;
ADMUX = 0x01;
char str[16];
while (1)
{
unsigned int sum = ADC ;
itoa(sum,str,10);
lcd_putsf(0,0,str);
_delay_ms(1);
}
}
|
cs |
// 가변저항을 돌리면 LCD 에 값이 출력된다.
http://tackbro.tistory.com/entry/AVR-%EA%B0%80%EB%B3%80%EC%A0%80%ED%95%AD%EC%9C%BC%EB%A1%9C-atmega-128%EC%97%90%EC%84%9C-ADC-%EC%82%AC%EC%9A%A9-%EC%98%88%EC%A0%9C
반응형
'Study > 8-bit MCUs' 카테고리의 다른 글
[NPAVR Board] AVR - Atmega128 (Dot Matrix) (0) | 2018.09.04 |
---|---|
[NPAVR Board] AVR - Atmega128 (keyMatrix) (0) | 2018.09.04 |
[NPAVR Board] AVR - Atmega128 (Character LCD, Switch) (0) | 2018.09.04 |
[NPAVR Board] AVR - Atmega128 (Character LCD) (0) | 2018.09.04 |
[NPAVR Board] AVR -Atmega128 (FND, Switch) (0) | 2018.09.03 |