View previous topic :: View next topic |
Author |
Message |
dan king
Joined: 22 Sep 2003 Posts: 119
|
16c505 portb pullups |
Posted: Thu Jun 15, 2006 8:10 am |
|
|
I'm trying to disable the port b pullups for the 16c505 using the pcb compiler (ver. 3.184) and the macro for setting the OPTION bits. For whatever reason the pullups are remaining enabled and I'm not sure why, any assistance would be appreciated.
Code: |
#include <16c505.h>
//#include <16f877.h> //16f877
#use delay(clock=4000000)
//#fuses HS,NOWDT,PUT //for 16f877
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,errors) //was C6 and 9600 baud
#fuses INTRC,NOWDT,CLKOUT // intRC = 4Mhz internal clock
////////////////////////////////////////////////////
// Constants and variables
#byte PORTB = 6
#byte PORTC = 7
#bit unload = PORTB.0
#bit load = PORTB.1
#bit data = PORTB.2
int result;
int loop;
int load_command = 26;
int unload_command = 44;
int nothing = 0;
///////////////////////////////////////////////////////
// General prototypes //
// local prototypes
/////////////////////////////////////////////////////
void tx_data(int);
/////////////////////////////////////////////////////
// MACRO
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
//==============================
void main(){
set_options(0b11000010);
//bit 7 = enable wakeup on change for rb0,1,3,4 = 0. 1 = disabled
//bit 6 = enable weak pullups on rb0,1,3,4 = 0 1 = disabled
//bit 5 = timer0 clk source select bit, 0= internal clk 1 = external source
//bit 4 = timer0 source edge, 0 = external lo to hi 1 = external hi to lo
//bit 3 = prescaler assignment, 0 = timer0 1 = WDT
//bits 2- 0 = prescaler
//000 = 1:2
//001 = 1:4
//010 = 1:8
//100 = 1:16
//101 = 1:32
//110 = 1:64
//111 = 1:128
//configure peripherals
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
set_tris_b(0b00000011);
result = 0;
// loop until reset
while(1){
if (load){
tx_data(load_command);
}
else if (unload){
tx_data(unload_command);
}
delay_ms(4);
}
}
/////////////////////////////////////////////////////////////////////////////
void tx_data(int command)
{
data = 1; //start bit
delay_ms(2);
for (loop=0; loop<6; loop++){ //data payload = 6 bits
data = (command & 0b00100000);
command = command << 1;
delay_ms(2);
}
data = 1; //stop bit
delay_ms(2);
data = 0;
}
|
Thanks,
Dan |
|
|
epideath
Joined: 07 Jun 2006 Posts: 47
|
|
|
dan king
Joined: 22 Sep 2003 Posts: 119
|
|
Posted: Thu Jun 15, 2006 10:07 am |
|
|
Thanks but not only is PORT_B_PULLUPS(FALSE) not available for the 16c505 but the INTCON reg is not used to clear the PU's. It's supposed to accomplished through writing to the OPTION parameter. For whatever reason I can't get it to work properly. For a quick fix, I simply changed the logic I'm polling for and rewired the switch to pull the port low. I would like to know a fix for the future.
Thanks for the input though.
Dan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 15, 2006 11:36 am |
|
|
Quote: | For a quick fix, I simply changed the logic I'm polling for and rewired the switch to pull the port low |
I would never do this. I would fix the problem.
The option register controls the pullups. If they're not being turned
off, the implication is that the option register is being re-programmed
later in the program, perhaps by a CCS function. A quick look at
the .LST file would tell if this is happening.
I don't have the PCB compiler, so I can't test this, but the Timer 0
prescaler is controlled by the OPTION register in the 16c505.
In your code below, you are setting up Timer0 after you call the
set_options() macro. I suspect that setup_timer_0() is the cause
of the problem. Try moving the set_options() line so it's below
the setup_timer_0() line. Also check the .LST file.
Code: |
set_options(0b11000010);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
set_tris_b(0b00000011);
result = 0; |
Change it to this:
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
set_options(0b11000010);
set_tris_b(0b00000011);
result = 0; |
|
|
|
dan king
Joined: 22 Sep 2003 Posts: 119
|
|
Posted: Thu Jun 15, 2006 12:19 pm |
|
|
Thanks for the suggestion, I'll try that straight away. I never thought of the setup_timer affecting the option reg so we'll see.
FWIW:
The quick fix is still for bench testing so I can continue working until I find the solution.
If the culprit isn't the setup routine, I'll review the .lst. I just wanted to check if anyone had experienced this before I dug into the list.
I'll let you know how I make out.
Rgds,
Dan |
|
|
dan king
Joined: 22 Sep 2003 Posts: 119
|
|
Posted: Thu Jun 15, 2006 12:27 pm |
|
|
Yup, that did it !!! Thanks a bunch.
Rgds,
Dan |
|
|
|