mikroC - C Compiler for Microchip PIC microcontrollers
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;
do {
temp_res = Adc_Read(2);
PORTD = temp_res;
PORTB = temp_res >> 2;
} while(1);
}
Hardware Connection
+5V
page
140
// Configure analog inputs and Vref
// PORTA is input
// Pins RB7, RB6 are outputs
// PORTD is output
// Get results of AD conversion
// Send lower 8 bits to PORTD
// Send 2 most significant bits to RB7, RB6
PIC16F877A
+5V
MCLR/Vpp/THV
RA0/AN0
RA1/AN1
RA2/AN2/Vref-
RA3/AN3/Vref+
RA4/TOCKI
RA5/AN4
RE0/RD/AN5
RE1/WR/AN6
+5V
RE2/CS/AN7
Vdd
Vss
OSC1
OSC2
RCO/T1OSO
RC1/T1OSI
RC2/CCP1
RC3
RD0/PSP0
4MHz
RD1/PSP1
MikroElektronika: Development tools - Books - Compilers
330R
RB7/PGD
RB6/PGC
330R
RB5
RB4
RB3/PGM
330R
RB2
RB1
RB0/INT
330R
Vdd
Vss
330R
RD7/PSP7
RD6/PSP6
RD5/PSP5
330R
RD4/PSP4
RC7/RX/DT
RC6/TX/CK
330R
RC5
RC4
330R
RD3/PSP3
RD2/PSP2
330R
330R
mikroC
making it simple...
LB7
LB6
LD7
LD6
LD5
LD4
LD3
LD2
LD1
LD0
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?