PIC18F4550 PortA read problem

Thread Starter

shoraff

Joined Jun 5, 2010
3
Hi,

I am doing a small project at home with an LCD and four push buttons connected to PIC18F4550 controller.

LCD is connected to PORTD & PORTB, which is working perfectly fine. But four push buttons connected as keypad matrix is connected to PORTA, which is giving lot of issues.

I have configures PORTA0:A1 as output pins and PORTA2:A3 as input pins. During initialization I have set - ADCON1 = 0x0f, CMCON = 0x07, TRISA=0x0C.

I set the output A0 as high using LATA=0x01 and read the PORTA after few milli seconds. Delay routine is

Rich (BB code):
	for(i=0;i<100;i++)
	{
		_asm 
		NOP 
		_endasm
	}
When I read PORTA, I always get junk data. When I don't press any key then the value should be zero as I mask the PORTA with 0x0C to consider only input pins.

As well when I run the program in release mode, I feel the controller is getting reset.

Can anyone help me in sorting this problem out?

Initialization code
Rich (BB code):
#pragma config FOSC=XT_XT //INTOSCIO_EC //4 MHz crystal
#pragma config PLLDIV = 1
#pragma config WDT=OFF
#pragma config LVP=OFF
 

coldpenguin

Joined Apr 18, 2010
165
With my 18f4550, I found it very sensitive to interference on the pins, you must have a 10k between vdd and MCLR, otherwise it will constantly reset.
On my similar circuit, I put in 1MOhm resistors holding RA0-3 down to ground. Otherwise I could see it floating at around 3v (when running with the debugger it went high low high low)
 
Top