Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Jon76

  • Rank
  1. Reynard, That was the problem! I redefined adc_measure() to AND ADCON0 with 0xC7 and shift "channel" left twice as you said, and the function now works on RA1. Thanks for the help. JT
  2. I'm having trouble getting the 16F616 to do a conversion on any ADC pin but RA0. Using the SourceBoost C compiler under MPLAB 8.10. With ANSEL = 1, TRISA = 1, adcon0.CHS0 = 0, and channel 0 selected, ADC works fine and writes ADC data to port c. With any other ADC input selected, and appropriate registers modified, the 'adc_measure( n )' function does not write the appropriate ADC value to port c. See code below. Int Osc set to 4 MHz, all other features disabled except MCLR. Programmed using ICD2. /* 16F616_analog_in.c */ //CODE to test 16F616 analog input functionality // Read an analog in channel and power LEDs as a function of value //#pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF // Set configuration fuses. // Interrupt vector 0x004 #pragma CLOCK_FREQ 4000000 #include <pic16f616.h> #include <system.h> //#include <icd2.h> // not needed with adapter board. #include <adc.h> void main() { ansel = 0x02; // Config all ADC pins to digital except RA1 trisa = 0x02; //configure all port A pins as output except RA1 trisc = 0; //configure all port C pins as output //Initialize ADC set_bit( adcon0, ADFM ); // AD result needs to be right justified //set_bit( adcon0, ADON ); // ADC on & consuming power clear_bit( adcon0, VCFG ); // Vref+ = Vdd //set_bit( adcon1, PCFG2 ); // Vref- = Vss set_bit( adcon1, ADCS1 ); // Select Tadc = Tosc / 32 (this depends on the Xtal here 10 MHz, should work up to 20 MHz) set_bit( adcon0, CHS0 ); // if cleared, Channel 0 is ADC in (RA0, pin 13). If set, Channel 1 is ADC in (RA1, pin 12). clear_bit( adcon0, CHS1 ); // clear_bit( adcon0, CHS2 ); // clear_bit( adcon0, CHS3 ); // volatile bit adc_on @ ADCON0.ADON; //AC activate flag adc_on = 1; // Activate AD module //Every 250ms sample ADC, discard 4 low bits and output into port B while( 1 ) { portc = adc_measure( 1 ) >> 4; // Read RA1, shift right 4 places, send to Port C delay_ms( 250 ); // wait } } This code does NOT function. What am I doing wrong? JT
  3. Thanks, Turns out that's the problem, pins were set to analog in. ANSEL = 0; solved the problem. Thanks again for the quick reply. JT
  4. Sorry for the confusion. I'm now programming a 16F877 with a 4 Mhz external osc as on the Pic Dem 2 board. My eventual goal is to figure out what I'm doing wrong on the '877 which I've used in the past with a different compiler, and then go back to the 16F616.
  5. I’m having difficulty getting the Sourceboost C compiler to integrate with MPLAB 8.1. The code will compile but when it is downloaded to the PIC and run, nothing appears to happen at the hardware, and the Watch List is not updated as if the registers have not been changed. I tried to program a 16F616 with no luck. I’m now trying the program WINK LED that I got off the web on a 16F877 on aPicDem2 board. Again no work! Code is as shown. //Wink LED CODE toggles RB0, RB1 #include <pic16f877.h> #include <system.h> #include <icd2.h> // Set configuration fuses. #pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF #pragma CLOCK_FREQ 4000000 void main() { trisb = 0; //configure port B pins as output while( 1 ) //endless loop { portb.0=1; // set portb pin0 to high. portb.1=0; // set portb pin1 to low. delay_ms( 500 ); // pause 0.5 seconds portb=0x02; // shows hex notation for entering data. delay_ms(500); // you can also write portb=2 in decimal } } What is the problem? Any help greatly appreciated!
  • Create New...