mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

Library Example

/* This code snippet reads analog value from channel 2 and displays it on PORTD (lower 8 bits) and PORTB (2 most significant bits). */

unsigned temp_res;

void main() { ADCON1 = 0x80; TRISA = 0xFF; TRISB = 0x3F; TRISD = 0;

//Configure analog inputs and Vref

//PORTA is input

//Pins RB7, RB6 are outputs

//PORTD is output

do {

 

 

 

 

temp_res = Adc_Read(2);

// Get results of AD

conversion

PORTD = temp_res;

//

Send

lower 8 bits

to PORTD

PORTB = temp_res >> 2;

//

Send

2 most significant bits to RB7, RB6

} while(1);

 

 

 

 

}

Hardware Connection

+5V

+5V

10K

Reset

4MHz

PIC16F877A

 

 

 

330R

LB7

 

MCLR/Vpp/THV RB7/PGD

 

 

 

 

 

RA0/AN0

RB6/PGC

 

 

 

RA1/AN1

RB5

330R

LB6

 

 

 

RA2/AN2/Vref-

RB4

 

 

 

RA3/AN3/Vref+

RB3/PGM

 

 

 

RA4/TOCKI

RB2

330R

LD7

 

 

 

 

 

 

 

RA5/AN4

RB1

 

 

 

RE0/RD/AN5

RB0/INT

330R

 

 

RE1/WR/AN6

 

LD6

+5V

Vdd

 

 

 

 

 

 

 

 

RE2/CS/AN7

Vss

 

 

 

Vdd

RD7/PSP7

330R

LD5

 

Vss

RD6/PSP6

 

 

 

 

 

OSC1

RD5/PSP5

330R

 

 

OSC2

RD4/PSP4

LD4

 

 

 

RCO/T1OSO

RC7/RX/DT

 

 

 

RC1/T1OSI

RC6/TX/CK

330R

LD3

 

RC2/CCP1

RC5

 

 

 

 

 

RC3

RC4

 

 

 

RD0/PSP0

RD3/PSP3

330R

LD2

 

 

 

RD1/PSP1

RD2/PSP2

 

 

330R LD1

330R

LD0

page

 

140

MikroElektronika: Development tools - Books - Compilers