

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


to AN
Resistors PORTB LEDs 8 8
#include <p18f4580.h> #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF
unsigned char Sample_AN0; // Variable to store A/D result
void GetVoltage(void) { ADCON0bits.GO = 1; // start a conversion (sampling) while ( ADCON0bits.GO == 1 ); // wait for completion Sample_AN0 = ADRESH; // Transfer A/D result }
void Result(void) { PORTB = Sample_AN0; }
void main (void) // main program { ADCON1 = 0x00; // AN10 ‐ AN0 are analog, VDD and VSS are references ADCON2 = 0x05; // Left justified, convert using 1.25 MHz TRISB = 0; // PortB as output
while (1) { ADCON0 = 0b00 0001 01; // select input AN1, enable ADC GetVoltage(); Result(); } }
to AN
Resistors PORTB LEDs 8 8
to AN