My First Program in mikroC PRO for PIC

The following code sample includes a simple loop for demonstrating A/D conversion on MCU PORTA and sending results to LEDs connected to PORTD and PORTC. Examine these lines carefully in order to see how our humble example deals with a highly complicated task of A/D conversion. mikroC PRO for PIC spares you from consulting the manuals for specific MCUs, code adjustments for different types of PIC MCUs, address arithmetic, etc. Just let the compiler take care of it.
 
 
unsigned int temp_res;

void main() {
  ANSEL  = 0x04;              // Configure AN2 pin as analog
  ANSELH = 0;                 // Configure other AN pin as digital I/O
   C1ON_bit = 0;               // Disable comparators
  C2ON_bit = 0;
 
  TRISA  = 0xFF;              // PORTA is input

  TRISC  = 0;                 // PORTC is output
  TRISD  = 0;                 // PORTD is output

  do {
    temp_res = ADC_Read(2);   // Get 10-bit results of A/D conversion
    PORTD = temp_res;           // Send lower 8 bits to PORTD

    PORTC = temp_res >> 8;    // Send 2 most significant bits to RC1, RC0
   } while(1);
}

2 comments :

  1. For beginers in PIC,
    it is better to start with mikroc or mikrocPro software. these softwares simply explains pic programming in an efficient manner. most of the programs are based on PIC16F88. but its not problem, most of the 16F series will works with this programs.

    ReplyDelete
  2. ANSEL ANSELH registers are used in PIC16f88 , if you are using PIC 16f877A or 87 series , you cant see these two registers, instead of these 2 you can use ADCON register.

    ReplyDelete

Copyright © Rough Record. Designed by OddThemes