PDA

View Full Version : trouble configuring 16F677



keithv
- 10th June 2016, 01:07
I'm trying to use a 16F677 to read the input from a potentiometer and then output the position of the pot by turning on one of 8 LEDs. The ADCIN is a number between 0 - 255. The first LED is 0 - 31, the second LED is 32 - 63, the third LED is 64 - 91, ....the eighth LED is 224 - 255.

PBP compiles my code OK, but when I use the programmer to write to the chip, I get an error message that there is a problem with the configuration. The problem is not with the chip or the programmer. I am able to write other programs to the chip. Just not this one. potentiometerx is connected to pin4/PORTA.3/AN3

ANSEL = %10001000
ANSELH = %00000000




TRISA = %00001000
TRISB = %00000000
TRISC = %00001000




x1 var PORTC.0
x2 var PORTA.2
x3 var PORTA.1
x4 var PORTA.0
x5 var PORTA.5
x6 var PORTA.4
x7 var PORTC.4
x8 var PORTC.5




positionx var byte


mainloop:


adcin 3, positionx


if positionx < 32 then
x1 = 1
x2 = 0
x3 = 0
x4 = 0
x5 = 0
x6 = 0
x7 = 0
x8 = 0
elseif (positionx >= 32) and (positionx < 64) then
x1 = 0
x2 = 1
x3 = 0
x4 = 0
x5 = 0
x6 = 0
x7 = 0
x8 = 0
elseif (positionx >= 64) and (positionx < 96) then
x1 = 0
x2 = 0
x3 = 1
x4 = 0
x5 = 0
x6 = 0
x7 = 0
x8 = 0
elseif (positionx >= 96) and (positionx < 128) then
x1 = 0
x2 = 0
x3 = 0
x4 = 1
x5 = 0
x6 = 0
x7 = 0
x8 = 0
elseif positionx >= 128 and positionx < 160 then
x1 = 0
x2 = 0
x3 = 0
x4 = 0
x5 = 1
x6 = 0
x7 = 0
x8 = 0
elseif positionx >= 160 and positionx < 192 then
x1 = 0
x2 = 0
x3 = 0
x4 = 0
x5 = 0
x6 = 1
x7 = 0
x8 = 0
elseif positionx >= 192 and positionx < 224 then
x1 = 0
x2 = 0
x3 = 0
x4 = 0
x5 = 0
x6 = 0
x7 = 1
x8 = 0
elseif positionx > 224 then
x1 = 0
x2 = 0
x3 = 0
x4 = 0
x5 = 0
x6 = 0
x7 = 0
x8 = 1
endif


goto mainloop

richard
- 10th June 2016, 03:13
potentiometerx is connected to pin4/PORTA.3/AN3





Pin 4 is RA3/MCLR/VPP not an3 and not an analog pin

AN3 is RA4 Pin 3 that you are trying to use for led 6


there is no #config info in you post so the actual configuration of pin 4 is unknowable here