View previous topic :: View next topic |
Author |
Message |
cypher
Joined: 05 Oct 2007 Posts: 31
|
Having trouble with PORTB1 and B2 |
Posted: Fri Jan 25, 2008 1:26 pm |
|
|
Hi,
I'm trying to read PORT B. However, pins B1 and B2 are always high for some reason. I have set_tris_b(0xFF) but it doesn't make a difference. Looking at the datasheet it says port b has a weak pull-up and they can be swicthed on by clearing the RBPU bit in the INTCON2 register. I don't know if it will make a difference. But how do you set internal registers in this complier. I don't think the compiler allows setting internal register bit on/off like other compilers.
Any suggestions on how to read B1 and B2? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 25, 2008 1:35 pm |
|
|
Post your PIC, compiler version, a compilable test program, and a list
of external hardware connections (if applicable).
Do this in all questions. |
|
|
cypher
Joined: 05 Oct 2007 Posts: 31
|
Code |
Posted: Tue Jan 29, 2008 4:22 pm |
|
|
Hi,
Here's the code I have:
Code: |
#include <18F6722.h>
#device ADC=10
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#fuses INTRC_IO,NOWDT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, force_sw, invert)
#use standard_io(A)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)
#use standard_io(E)
#use standard_io(F)
#use standard_io(G)
#define SW_EN PIN_B0
#define SW_MODE PIN_B1
#define SW_TEMP0 PIN_B2
#define SW_TEMP1 PIN_B3
#define SW_TEMP2 PIN_B4
#define SW_TEMP3 PIN_B5
#define SW_TEMP4 PIN_B6
#define SW_TEMP5 PIN_B7
void main (void)
{
set_tris_b(0xFF);
int r_sw_en = 0;
int r_sw_mode = 0;
int r_sw_temp0 = 0;
int r_sw_temp1 = 0;
int r_sw_temp2 = 0;
int r_sw_temp3 = 0;
int r_sw_temp4 = 0;
int r_sw_temp5 = 0;
r_sw_en = input(SW_EN);
r_sw_mode = input(SW_MODE);
r_sw_temp0 = input(SW_TEMP0);
r_sw_temp1 = input(SW_TEMP1);
r_sw_temp2 = input(SW_TEMP2);
r_sw_temp3 = input(SW_TEMP3);
r_sw_temp4 = input(SW_TEMP4);
r_sw_temp5 = input(SW_TEMP5);
printf("%d\r",r_sw_en);
printf("%d\r",r_sw_mode);
printf("%d\r",r_sw_temp0);
printf("%d\r",r_sw_temp1);
printf("%d\r",r_sw_temp2);
printf("%d\r",r_sw_temp3);
printf("%d\r",r_sw_temp4);
printf("%d\r",r_sw_temp5);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 29, 2008 4:32 pm |
|
|
Post your PIC, compiler version, a compilable test program,
and a list of external hardware connections (if applicable). |
|
|
cypher
Joined: 05 Oct 2007 Posts: 31
|
Code |
Posted: Tue Jan 29, 2008 4:59 pm |
|
|
1. I'm using a PIC18LF6722
2. Compiler version - 4.047
3. Code posted as above
4. I just have a 470 Ohm in series to each portb pin and 10K pull-ups for the DIP switch which i'm using as the input on/off. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Jan 30, 2008 3:45 am |
|
|
you don't need to have the #use standard_io if you are using standard_io and you definately don't want that set_tris_b in there.
The PORT_B PULLUPS are off on power up unless you specify them to be on and if that were the problem you would see it on the other pins as well.
I am using the same chip but with a different compiler and I am having no problems.
Can you check your hardware ? have you got a multimeter or something to physically check B0 and B1 ? |
|
|
cypher
Joined: 05 Oct 2007 Posts: 31
|
|
Posted: Mon Feb 04, 2008 4:30 pm |
|
|
Ok, so I removed the standard_io and the tris statements and still no luck. Also I checked the voltage on the inputs, and it seems ok. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 04, 2008 5:25 pm |
|
|
Are these tests being done with a hardware board or with a simulator ? |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Mon Feb 04, 2008 10:31 pm |
|
|
Try another pic , sometimes pic pins i/o might die when doing test... |
|
|
|