Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PORTB in P18F4620 I/O problem

Status
Not open for further replies.

poxkix

Member level 5
Member level 5
Joined
Aug 20, 2011
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,948
I'm having problems in my 4620. In simulation I used PORTB as pins for my lcd and it works really fine.
When I interfaced it on a actual circuit nothing will happen.

The connections are 100% correct. No questions asked. No hardware problems too.
Now, I have read the datasheet and PORTB has interrupts. Are these interrupts in ON state by default and should be turned off?
I just want to make the PORTB as normal digital I/O.

This is the code I sued for the PORT setup:
INTCON = 0x00;

Is that correct? I don't quite understand the datasheet.
 

There are several possible issues:

1. Have you disabled the ADCs on RB4:RB0?

Note: On a Power-on Reset, RB4:RB0 are
configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as
digital inputs.
By programming the Configuration bit,
PBADEN, RB4:RB0 will alternatively be
configured as digital inputs on POR.

2. RB7:RB6 are used for debugging. Have you disable debugging via configuration bits?

3. RB7:RB4 do have the interrupt on change feature and RB3:RB0 have external interrupt features.

Please post your code, so that one of us can examine it and advise you further. A schematic of your circuit was help as well.

BigDog
 
  • Like
Reactions: poxkix

    poxkix

    Points: 2
    Helpful Answer Positive Rating
Simulators don't always incorporate all the hardware quirks (LCD delays are one of them).
Do you leave enough time for LCD to power-up (about 30ms should be more than enough), and also between the commands (or sample D7).
Use LATB for output instead of PORTB (that should be used for input).
 

There are several possible issues:
1. Have you disabled the ADCs on RB4:RB0?
2. RB7:RB6 are used for debugging. Have you disable debugging via configuration bits?
3. RB7:RB4 do have the interrupt on change feature and RB3:RB0 have external interrupt features.
Please post your code, so that one of us can examine it and advise you further. A schematic of your circuit was help as well.
BigDog

Here is the code:
I thought ADCON1 0xFF would turn off everything.

Code:
void PORTSsetup(void);
void LCDsetup(void);

void main() {
     PORTSsetup();
     LCDsetup();

     while(1) {
     Lcd_Custom_Out(1,1,"TEST");
     }

}// end main

void PORTSsetup() {
     ADCON1 = 0xFF;
     TRISB = 0x00;
}// end PORTSsetup

void LCDsetup() {
     Lcd_Custom_Config(&PORTB, 7, 5, 4, 3,&PORTB, 1, 0, 2);
     Lcd_Custom_Cmd(LCD_CLEAR);
     Lcd_Custom_Cmd(LCD_CURSOR_OFF);
}// LCDsetup

Image
qwewqeqwe.png

Simulators don't always incorporate all the hardware quirks (LCD delays are one of them).
Do you leave enough time for LCD to power-up (about 30ms should be more than enough), and also between the commands (or sample D7).
Use LATB for output instead of PORTB (that should be used for input).

I just have realized that. Actually in the simulation it works very well now that I interfaced it on actual it doesn't work. The LCD's output is 2 rows of black figures.
 

I thought ADCON1 0xFF would turn off everything.

Actually ADCON1 = 0x0F would effectively turnoff the A/D on AN12:AN0 or you could set the configuration bit PBADEN = OFF to have RB3:RB0 configured as digital I/O on POR.


The LCD's output is 2 rows of black figures.

The black squares usually indicated a LCD initialization problem. Or I just noticed you do not have a proper contrast control setup for Vee, I would recommend using a 10KΩ Pot with the wiper arm attached to Vee or in a pinch you could use two 5KΩ resistors to bias the Vee. Improper contrast control can result in the appearance of the "black squares."

BigDog
 

Actually ADCON1 = 0x0F would effectively turnoff the A/D on AN12:AN0 or you could set the configuration bit PBADEN = OFF to have RB3:RB0 configured as digital I/O on POR.
The black squares usually indicated a LCD initialization problem. Or I just noticed you do not have a proper contrast control setup for Vee, I would recommend using a 10KΩ Pot with the wiper arm attached to Vee or in a pinch you could use two 5KΩ resistors to bias the Vee. Improper contrast control can result in the appearance of the "black squares."
BigDog

How do I read this -> AN12:AN0

I have checked that no problems in that part. Tried both with the POT and without. Still the same output using PORTB in a P18F4620.
So, by turning off the A/D using ADCON1 = 0x0F and turning off the INT would be the solution?
How do I code PBADEN = OFF? I tried ADCON1.PBADEN = 0xFF won't work or just by coding PBADEN = OFF. I'm using mikroC if that helps
 

AN12:AN0 means analog inputs from AN12 to AN0... these are multiplexed over PORTA and PORTB pins (check the PIN Diagrams in datasheet on page 4).

PBADEN is set during programming. In MikroC go to Project -> Edit Project. Setting "PORTB A/D" to "Disable" will turn of PBADEN.
Also check that you set the correct frequency. If you are using PLL, set freq*4 so that MikroC can calculate proper timings for the display.

You should try setting some LEDs on PORTB instead of LCD and just do a simple flashing loop to make sure the output is working fine (or check with multimeter of you don't have LEDs nearby). If that works fine, concentrate on the the wiring and software.
 
  • Like
Reactions: poxkix

    poxkix

    Points: 2
    Helpful Answer Positive Rating
AN12:AN0 means analog inputs from AN12 to AN0... these are multiplexed over PORTA and PORTB pins (check the PIN Diagrams in datasheet on page 4).
PBADEN is set during programming. In MikroC go to Project -> Edit Project. Setting "PORTB A/D" to "Disable" will turn of PBADEN.
Also check that you set the correct frequency. If you are using PLL, set freq*4 so that MikroC can calculate proper timings for the display.
You should try setting some LEDs on PORTB instead of LCD and just do a simple flashing loop to make sure the output is working fine (or check with multimeter of you don't have LEDs nearby). If that works fine, concentrate on the the wiring and software.

Cool. Thanks for that sir bjuric. I found out how to turn it off. By the way, is there another to turn them off by hard coding it?
Frequency you mean for the oscillator?

Okay, I'll try with the LEDs first with the PBADEN turned off

Settings:

OSC_HS_1H
WDT_OFF_2H
LVP_OFF_4L
XINST_OFF_4L
PBADEN_OFF_3H

Revised Code:
Code:
void PORTSsetup(void);
void LCDsetup(void);

void main() {
     PORTSsetup();
     LCDsetup();

     while(1) {
     Lcd_Custom_Out(1,1,"TEST");
     }

}// end main

void PORTSsetup() {
     ADCON1 = 0xF;
}// end PORTSsetup

void LCDsetup() {
     Lcd_Custom_Config(&PORTB, 7, 5, 4, 3,&PORTB, 1, 0, 2);
     Lcd_Custom_Cmd(LCD_CLEAR);
     Lcd_Custom_Cmd(LCD_CURSOR_OFF);
}// LCDsetup
 

You said:
The LCD's output is 2 rows of black figures.
This is commonly because of improper contrast setting.

https://www.edaboard.com/threads/233352/#post996761
https://www.edaboard.com/threads/194246/#post824737
https://www.edaboard.com/threads/194246/

I suggest you connect a 5k or 10k pot, with one leg going to +5V, the other to ground and the wiper to pin 3 of the LCD. Then adjust the pot until you see something on the screen and the squares disappear. If, however, you have all the connections right and this still doesn't give proper display, then it could be for other reasons.

If you wrote ADCON1=0xFF, that should do it. It disables the ADC analogue circuitry on each of the analogue input pins.

By the way, is there another to turn them off by hard coding it?
You can turn off / disable the analogue circuitry connected to all the analogue inputs by writing
Code:
ADCON1=0xFF
You can then turn the ADC off by writing
Code:
ADON_bit = 0;
That should be enough. In fact, even if you don't have the ADC turned off (but you probably will have), AN0:AN12 pins will still be digital.

Hope this helps.
Tahmid.
 

You said:
This is commonly because of improper contrast setting.
https://www.edaboard.com/threads/233352/#post996761
https://www.edaboard.com/threads/194246/#post824737
https://www.edaboard.com/threads/194246/
I suggest you connect a 5k or 10k pot, with one leg going to +5V, the other to ground and the wiper to pin 3 of the LCD. Then adjust the pot until you see something on the screen and the squares disappear. If, however, you have all the connections right and this still doesn't give proper display, then it could be for other reasons.
If you wrote ADCON1=0xFF, that should do it. It disables the ADC analogue circuitry on each of the analogue input pins.
You can turn off / disable the analogue circuitry connected to all the analogue inputs by writing
Code:
ADCON1=0xFF
You can then turn the ADC off by writing
Code:
ADON_bit = 0;
That should be enough. In fact, even if you don't have the ADC turned off (but you probably will have), AN0:AN12 pins will still be digital.
Hope this helps.
Tahmid.

Please read about my previous post. I stated The contrast issue is out of the question. Whether there is a POT or not it still displays only 2 lines of black figures.

I know my configurations and code are correct because if I transfer it to PORTC it displays perfectly.
So I guessed it is because of the A/D config and interrupt in PORTB. But I prefer to use PORTB since I will not use A/D and interrupts and it makes my circuit more easier of wiring.

I haven't tried the code with PBADEN turned off. So for now it will still be unclear.
 

So, in your code, add these:
Code:
ADCON1 = 0xFF;
ADON_bit = 0;
INTCON = 0;
Set PBADEN off. Turn debug off.

These were all mentioned in previous posts. I'm summarizing it here for you, because right now, I can't think of another reason for it not to work on PORTB if it works on PORTC.
 
  • Like
Reactions: poxkix

    poxkix

    Points: 2
    Helpful Answer Positive Rating
So, in your code, add these:
Code:
ADCON1 = 0xFF;
ADON_bit = 0;
INTCON = 0;
Set PBADEN off. Turn debug off.
These were all mentioned in previous posts. I'm summarizing it here for you, because right now, I can't think of another reason for it not to work on PORTB if it works on PORTC.

Thank you sir Tahmid. I will do this today and I'll post back after I test the curcuit
By the way, what is ADON_bit = 0? I can't get it to work in mikroC
 

ADON_bit is the bit ADON (bit 0 of ADCON0). If it doesn't work, write
Code:
ADCON0.ADON = 0;
or
Code:
ADCON0.F0 = 0;
Setting ADON to 0 turns ADC off.

Hope this helps.
Tahmid.
 

ADON_bit is the bit ADON (bit 0 of ADCON0). If it doesn't work, write
Code:
ADCON0.ADON = 0;
or
Code:
ADCON0.F0 = 0;
Setting ADON to 0 turns ADC off.
Hope this helps.
Tahmid.

Isn't ADON = 0 the same with ADCON1 = 0x0F?

Thanks for the help everyone. I'm now using the PORTB with the suggested settings.
Actually this is part of interface LCD and keypad connection. I'm taking in part by part so I can eliminate the problems before getting to the next one.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top