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 CCS Technical Support

Please Help Me With The Strange Problem---UPDATED

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



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

Please Help Me With The Strange Problem---UPDATED
PostPosted: Sun Feb 22, 2004 8:52 pm     Reply with quote

hi, all,
I use PCW 3.094 and MPLAB 6.40 to program PIC16F877. The program is very simple:
//
#include <16f877.h>

#use delay (clock=20000000)
#fuses HS, NOWDT, PUT, NOBROWNOUT, NOLVP, PROTECT

void main(){

set_tris_b(0);

while (true)
output_b(0b11111111);
}
//
My programmer is MPLAB ICD2. All are going right, programming successfully and verifying program successfully, too, but there is no output, i.e, none of Port B pins goes high.
Can anyone tell me how to solve it??


Last edited by water_river on Tue Feb 24, 2004 9:33 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 22, 2004 8:54 pm     Reply with quote

There is a hidden SLEEP instruction placed at the end of main()
by the compiler. If you let your program run off the end of main(),
the PIC will to sleep. To avoid this, put a constant loop at the end.

void main()
{
set_tris_b(0);

while (true)
{
output_b(0b11111111);
}

while(1); // ADD THIS LINE
}
water_river



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

Program Memory Selection??
PostPosted: Mon Feb 23, 2004 12:18 am     Reply with quote

It still doesn't work
I have checked the program memory selection. Under the self-selection mode, it programs from 0x0 to 0xB only. How come?
Then I use the manual selection and change it to full range, but it still doesn't work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 23, 2004 1:07 am     Reply with quote

I made that post just as I was leaving work after an extended day.
Not wise.

Your code doesn't fall off the end of main(), because you have
a while() statement there. Even then, in sleep mode, the PIC
retains the state of the pins. So that's not the problem.

I would look closely at this:
Quote:
Under the self-selection mode, it programs from 0x0 to 0xB only. How come?


I installed PCM vs. 3.094, and I don't see anything immediately wrong
with the code in the .LST file.

If someone else hasn't solved your problem in the meantime, when
I get into work tomorrow, I will compile your code with vs. 3.094 and
run it on a 16F877, and try to solve your problem. Normally, I don't
post unless I have tested the code first on an actual chip. I can only
say that I was tired and the company owner had kept me late.
water_river



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

PostPosted: Mon Feb 23, 2004 3:06 am     Reply with quote

thank you in advance.
I'll wait for your reply
Ttelmah
Guest







Re: Please Help Me With The Strange Problem
PostPosted: Mon Feb 23, 2004 3:32 am     Reply with quote

water_river wrote:
hi, all,
I use PCW 3.094 and MPLAB 6.40 to program PIC16F877. The program is very simple:
//
#include <16f877.h>

#use delay (clock=20000000)
#fuses HS, NOWDT, PUT, NOBROWNOUT, NOLVP, PROTECT

void main(){

set_tris_b(0);

while (true)
output_b(0b11111111);
}
//
My programmer is MPLAB ICD2. All are going right, programming successfully and verifying program successfully, too, but there is no output, i.e, none of Port B pins goes high.
Can anyone tell me how to solve it??


I'd say that the odds are that you have a hardware problem. How is MCLR wired?. How are the power pins wired (you need to connect both)?. Have you verified that there is 5v on the processor when trying to run, and that the crstal is oscillating?. Though the code is not really 'right' (you are not specifying #use fast_io, so the TRIS statement is uneccessary), this will not stop it working.

Best Wishes
water_river



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

PostPosted: Mon Feb 23, 2004 3:46 am     Reply with quote

I am using the Demo board from Microchip, so there should not be any problem with hardware, i think.
In fact, when I use another compiler, PCM, it works.
Maverick
Guest







PostPosted: Mon Feb 23, 2004 10:18 am     Reply with quote

add this line after the #use delay...

#use fast_io(b);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 23, 2004 2:13 pm     Reply with quote

I tested your code, as shown below, with PCM 3.094, and it worked OK.
I modified it slightly, to work with my bootloader, by reducing the
clock speed to 4 MHz. But that shouldn't matter.

I checked pins B0-B7 with my oscilloscope, and they were at a high
logic level.

So it likely is a hardware problem. Do you have anything
connected to the Port B pins ? If have an LED (or several)
connected to those pins, and you don't have series resistors
to limit the current, then this could cause the problem that
you're seeing.


Code:
#include <16f877.h>
#use delay (clock=4000000)
#fuses XT, NOWDT, PUT, NOBROWNOUT, NOLVP

void main()
{

set_tris_b(0);

while (true)
   output_b(0b11111111);
}
water_river



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

PostPosted: Tue Feb 24, 2004 12:20 am     Reply with quote

When I changed Port B to C, it still doesn't work.
Now I am using PCM, there is no problem.
But the problem is that I need to program PIC18F8720 in the project, although the C program would be almost similar.
water_river



Joined: 17 Feb 2004
Posts: 16

View user's profile Send private message

Same C program but two different program memories written
PostPosted: Tue Feb 24, 2004 9:48 pm     Reply with quote

hi, all,
With the same C program:
//
#include <16f877.h>

#use delay (clock=20000000)
#fuses HS, NOWDT, PUT, NOBROWNOUT, NOLVP, PROTECT

void main(){

//set_tris_b(0x00);

while(true)
output_b(0b11111111);
}
//
using two CCS compiler to program, I view the program memory and find it written differently:

in the case of using PCM:
MOVLW 0
MOVWF 0xa
GOTO 0x4
NOP
CLRF 0x4
MOVLW 0x1f
ANDWF 0x3, F
MOVLW 0x9f
MOVWF 0x4
MOVLW 0x7
MOVWF 0
MOVLW 0
BSF 0x3, 0x5
MOVWF 0x6
MOVLW 0xff
BCF 0x3, 0x5
MOVWF 0x6
GOTO 0xb
SLEEP
ADDLW 0xff
...
INCF 0, W (end memory)

in the case of using PCW:

MOVLW 0
MOVWF 0xa
GOTO 0x4
NOP
CLRF 0x4
MOVLW 0x1f
ANDWF 0x3, F
MOVLW 0xf
BSF 0x3, 0x5
ADDLW 0x9f
ADDLW 0xff
...

Obviously, the one done by PCW does not work.
Do any know why??
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