eee305 microcontroller systems lecture 8: analogue to digital conversion using pic microcontrollers...

Post on 22-Dec-2015

218 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

EEE305 Microcontroller Systems

Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler

(NB As of 18/04/13 this code uses the older HTC compiler, I will change it to the more modern XC8 compiler in class)

Teaching resources are at www.eej.ulst.ac.uk

My office 5B18, telephone 028 90 366364My email IJ.McCrum@ulster.ac.uk

http://www.eej.ulst.ac.uk/~ian/modules/EEE305 1/

Datasheet Chapter 11

C Code to read ADC and O/p reading

Last week’s code to use USART serial port

Main code to test ADC

Further experiments

• If the ADC returns a number from 0 to 1024• Scale this to 80 (the width of a PUTTY screen)• Use a for loop

For(i=0;i<scaled_reading;i++){putchar(‘*’);} Printf(“\r\n”);

• This will print a “graph” across the screen.

Making a Thermometer• Assume the thermistor initially reads 20 degrees • After holding for 60 seconds assume it reads 35 degrees• Scale the readings to display degrees• i.e If you get a reading of XX for 20 degrees and YY for 35

degrees.

20⁰C

35⁰C

XX YYZZ

??⁰C

Don’t forget to use variables of type float if they are needed

top related