PDA

View Full Version : PIC16F887 Config problem



Agent36
- 13th November 2008, 21:14
Hi,
Can some one tell me where I have gone wrong with the code below please.


DEFINE OSC 8
DEFINE ADC_BITS 10 'Defines bit resoloution
DEFINE ADC_CLOCK 2 'Defines adc clock speed
DEFINE ADC_SAMPLEUS 50 'Defines sammple time of 50mS
TRISD = %00000000
TRISA = %11111111
ADCON1 = %00000000 '
ANSEL = %11111111 'All portA pins analog
ADCON0 = %01000001 'configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module
CM1CON0 = %00000000 'comparator 1 off
CM2CON0 = %00000000 'comparator 2 off


bar var word

main:
adcin 0,bar
portd = bar.highbyte
goto main


I am using a PICkit 2 with PBP 4.47 and MPLAB v8.10. All I want to do at the moment is output the a2d0 on portc. I have set the required registers using the data sheet for the 16f887 as far as I can tell.
Thankyou.

mister_e
- 13th November 2008, 21:29
Seems good, you have it left justified, but you read the highbyte.. that's not the problem here. So the question are

1) what doesn't work?
2) Expected to work on Internal or external OSC?
3) Config fuses?

PS: PBP 2.47 had some issue with that PIC about ADCIN and default clock. Problem solved in 2.50. Sur we had found a workaround in here somewhere...

mister_e
- 13th November 2008, 21:38
I knew I saw that before...
http://www.picbasic.co.uk/forum/showthread.php?t=6514&

Agent36
- 13th November 2008, 22:09
1) what doesn't work?
When I run the debug I can see the registers with either FF or 0 depending where the pot is, the output on portc is the same value as these viewed registers. The program acts like a comparator been left enabled on the a2d pin.

2) Expected to work on Internal or external OSC?
I am using the internal osc, I have tried to replicate one of the sample asm demo files to make sure I understand whats happening. I can also blink the LEDs without a problem.
This is the code


TRISC = %00000000
loop:

high portd.3
pause 250
high portd.2
pause 250
low portd.3
pause 250
low portd.2
pause 250
goto loop
end


3) Config fuses?
I think this may be the problem, if I set config fuses in the code I get duplicate label errors.
I have not set any in the code or changed them in the inc files as the blinky code above works.

Agent36
- 13th November 2008, 22:32
Mister e,
Thanks very much for the info on that work around!!!! I had only searched the forum using pic16f887. This little test program works fine now. Its only taken me three days to sort this.
Kind regards Nick

mackrackit
- 13th November 2008, 22:38
I see you have it working... anywho, this method is very reliable if you want to play with another way.
http://rentron.com/PICX2.htm