CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Having trouble with PORTB1 and B2

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

Having trouble with PORTB1 and B2
PostPosted: Fri Jan 25, 2008 1:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2008 1:35 pm     Reply with quote

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

View user's profile Send private message

Code
PostPosted: Tue Jan 29, 2008 4:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 29, 2008 4:32 pm     Reply with quote

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

View user's profile Send private message

Code
PostPosted: Tue Jan 29, 2008 4:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 30, 2008 3:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 04, 2008 4:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 04, 2008 5:25 pm     Reply with quote

Are these tests being done with a hardware board or with a simulator ?
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Mon Feb 04, 2008 10:31 pm     Reply with quote

Try another pic , sometimes pic pins i/o might die when doing test...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group