Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

write the PIC C in PIC16F877A

Status
Not open for further replies.

AlexNg

Newbie level 6
Joined
Mar 4, 2006
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,337
I want to use analog to digital converter in PIC16F877A, but i do not know how to write a program using PIC C. Can anyone help?
 

Do you mean H-Tech PICC, have a close look in the samples directory, there are usualy examples for most of the peripherals.
Most of the Pics have the same architecture for the modules so the code is easily ported.
Here is some code for a 10 bit A/D converter:

Code:
/*--- Initialise A/D converter ---*/

void init_adc(void)
  {      
  ADCON0 = 0x94;  /* Right justified result, Vdd as ref */
  ADCON1 = 0x20;  /* Conversion clock Fosc/32 */
  }
  
/*--- Read A/D conversion ---*/

static uint16_t read_ad(uint8_t channel)
  {
  uint16_t result = 0;
  uint8_t acquisitionTime = 5;
 
  ADCON0 &= 0xe3;	         /* Clear current channel select */
  ADCON0 |= (channel << 2); /* Select channel */  
  ADON = 1;                 /* Turn on A/D */
   
  while(acquisitionTime--){ /* Sample channel */
    continue;
    }
    
  GODONE = 1;     /* Start conversion */
  
  while(GODONE){  /* Wait for conversion end */
    continue;
    }
    
  result = ADRESH;
  result <<= 8;
  result |= ADRESL;
  return result;
  }
 

If I have helped you, it is better to click on the helped me button, then I get 3 points.
Simple thanks messages are frowned upon by the board!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top