File: adc-read.c

package info (click to toggle)
kuttypy 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,896 kB
  • sloc: python: 58,651; javascript: 14,686; xml: 5,767; ansic: 2,716; makefile: 453; asm: 254; sh: 48
file content (24 lines) | stat: -rw-r--r-- 516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <avr/kp.h>   // Include file for I/O operations
#include <stdlib.h>   // include the utoa() function prototype


int main (void)
{
uint16_t data;
char a[6], *p;

DDRB = 255;             // Configure port B as output  
adc_enable();
uart_init(38400);

while (1)
    {
     data = read_adc(0);
     PORTB = data >> 2;    // convert 10 bit in to 8 bit
     utoa(data, a, 10);    // convert to ASCII string
     p = a;
     while(*p) uart_send_byte(*p++);
     uart_send_byte('\n');
     delay_ms(500);
    }
}