View previous topic :: View next topic |
Author |
Message |
Jerry Finsen Guest
|
PORT_B_PULLUPS problem |
Posted: Sat Mar 01, 2003 7:14 pm |
|
|
I am trying to set the Port B Pull to TRUE and my program consistently hangs. Below is a minimum code segment that displays this. The printf displays if the pullup statement is commented out. Make it active and the nothing and it hangs.
I am using 3.146 under W2K and running on a meLabs X1 board. Equivalent code using PicBasic Pro works fine.
#include <16F877.h>
#use delay(clock=20000000)
#fuses HS,NOWDT
#use RS232(baud=9600, parity=n, bits=8, xmit=PIN_C6, rcv=PIN_C7)
void main() {
setup_adc_ports(NO_ANALOGS);
// port_b_pullups(TRUE);
printf("\fStart Test #3 ");
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12262 |
|
|
sar
Joined: 08 Sep 2003 Posts: 36
|
Re: PORT_B_PULLUPS problem |
Posted: Sat Mar 01, 2003 9:01 pm |
|
|
<font face="Courier New" size=-1>Try this:
#include <16F877.h>
#use delay(clock=4000000) //change to 20000000 for your app
#fuses XT,PUT,BROWNOUT,NOWDT //change to HS for your app
#include stdio.h
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS=8 )
void display();
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
port_b_pullups(TRUE);
while(1)
display();
}
void display()
{
printf("fStart Test #3\r\n ");
delay_ms (1000);
}
Will printf once a second with port_b_pullups active TRUE.
SAR</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12263 |
|
|
sar
Joined: 08 Sep 2003 Posts: 36
|
Re: PORT_B_PULLUPS problem |
Posted: Sat Mar 01, 2003 9:08 pm |
|
|
<font face="Courier New" size=-1></font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12264 |
|
|
sar
Joined: 08 Sep 2003 Posts: 36
|
Re: PORT_B_PULLUPS problem |
Posted: Sat Mar 01, 2003 9:10 pm |
|
|
<font face="Courier New" size=-1></font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12265 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PORT_B_PULLUPS problem |
Posted: Sat Mar 01, 2003 11:58 pm |
|
|
:=I am trying to set the Port B Pull to TRUE and my program consistently hangs. Below is a minimum code segment that displays this. The printf displays if the pullup statement is commented out. Make it active and the nothing and it hangs.
:=#fuses HS,NOWDT
:=void main() {
:= setup_adc_ports(NO_ANALOGS);
:=// port_b_pullups(TRUE);
:= printf("\fStart Test #3 ");
:=}
------------------------------------------
Add NOLVP to the fuses statement. This will cure the
problem of hanging when pullups are enabled. Example:
#fuses HS, NOWDT, NOLVP
---
You also have another problem, where the last two characters
in your printf() are cut off. You've tried to cure it by
adding two spaces at the end. You don't need to do that.
Instead, add a while(1) loop as the last statement in main().
This will prevent your program from falling off the end of
main(), and hitting the hidden SLEEP instruction that CCS
puts at the end of main().
The SLEEP instruction puts your PIC to sleep while it's still
got your last two chars queued up inside the USART transmitter.
Example:
void main()
{
setup_adc_ports(NO_ANALOGS);
port_b_pullups(TRUE);
printf("\fStart Test #3\n\r"); // Don't need trailing spaces
while(1); // Prevent PIC from going to sleep
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12268 |
|
|
Jerry Finsen Guest
|
Re: PORT_B_PULLUPS problem |
Posted: Sun Mar 02, 2003 7:02 am |
|
|
:=Add NOLVP to the fuses statement. This will cure the
:=problem of hanging when pullups are enabled. Example:
Thanks
Bumping my way through the learning curve...
jerry
___________________________
This message was ported from CCS's old forum
Original Post ID: 12272 |
|
|
|