Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

porta 0&1 not reading on 18f1230

Status
Not open for further replies.
still no go:
#pragma config OSC=INTIO2, WDT=OFF
#include <p18f1230.h>

void main(){

unsigned int cnt;

OSCCON= 0b01110000; //8MHz please
OSCTUNE=0b00011100;
CMCON=0x00;


TRISA = 0b00111111;
TRISB = 0b00000001;
cnt = 0;

ADCON1 = 0;

while(1) {

if(PORTAbits.RA1 == 1){
cnt++;
}

}
}
 
Can you explain how are you able to debug your hardware (buttons and pots etc.) when the PIC is not attached to the PCB board?

EDIT: Sorry my mistake again.. Apparently you do attach the chip to the board when doing in-circuit debugging. I think you have a hardware bug. Can you measure the pin-levels with a multimeter?
 
Last edited:
yes you are rite there, we are attached now,
and i have tested 5v direct on pin with the multimeter

but wait,, i have done some code to read those ports in analog, and they are reading analog values accurately, but then i delete the adc.h, and all the analog subroutines with it

and go back to digital reading where it is no go again.... i'v swapped chips already...
 
You keep changing things so fast that it is impossible to debug in a forum discussion. Debugging is about testing simple things and build up there. And changing only one thing at a time.
 
okok, i will slow down, i just thought it was important that it is working for analog, which suggests it to not be hardware.

i will go back to testing for 5v with voltmeter... pins are showing...
4.76v on vcc
4.74v on A0
4.74v on A1
4.74v on A2
4.74v on A3


and you are rite, one thing at i time, i am prolly missing step...
 
I just thought it was important that it is working for analog, which suggests it to not be hardware.

If the analog works, it does not prove that the buttons work. Measure the buttons when they are pressed, and when they are not pressed.
 
sweet you found it!!
ADCON1= 0B00001110;
which switches all ports to digital except a0!
i am surprised that as suggested adcon1 = 0 was not the default value to turn all the analog off, or that you would need it at all for pure digital, in fact i thought that adccon1 was part of adc.h!
thnx a ton everyone!!
 
That means the datasheet is incorrect!!

The ADCON1 register used to be 1 = digital 0 = Analogue. This datasheet definitely has it the other way round.

Here are the two datasheets.... One downloaded with ISIS ( wrong) The other direct from Microchip...
 

Attachments

  • Capture.png
    Capture.png
    223.9 KB · Views: 185
i got mine while ago, usually direct from digikey, i think, but ADCON1= 0B00001110; is def what worked, i looked at my data sheet and it is identical, except they flipped the 1's & 0's for all the registers except vcfg,
crazy little bugs!
atuff.jpg
 
I seen this exact thing happen in another "Thread" and this is what I learned from it.

Rule 1: When in doubt read the Data Sheet.

Rule 2: Still in doubt? Obtain the Manufactures Data Sheet:rolleyes:
 
i got mine while ago, usually direct from digikey, i think, but ADCON1= 0B00001110; is def what worked, i looked at my data sheet and it is identical, except they flipped the 1's & 0's for all the registers except vcfg,
crazy little bugs! View attachment 82447

Looks like theres a Rule 3: Go to digikey, or go to the errata.

Edit: Or go to the (Errata)
 
Last edited:
i found out the hard way in one my posts we were talking about a transistor and 3 different manufacturers of exactly the same part had three different datasheets!
to make it worse it isnt a case of downloading the manufacturers datasheet!! life is not that simple! once you have the correct datasheet then you have to go hunt down the errata! i have spent ages trying to write an article on the pic30f4013, and i was especially looking forward to trying out the 10 bit mode of the ADC (it has 10 bit and 12bit on that chip) because all the marketing stuff and all the info on the chip tells you it will sample 1MILLION times a second!!! but just to make sure i checked the datasheet and guess what???? :rolleyes:. it backs it all up this chip can sample 1 Million times a second!!! woohooo yay weeeeeeeeeeeeeeeeeeeeee:stop: that is untill you read the errata and find out thats all cobblers! and infact the chip can do 750K per second :( so dont trust the data sheet just because its from the people that make the chip, also read and errata because sometimes even the datasheet lies ;)
 
Status
Not open for further replies.

Latest threads

Back
Top