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

16F88 problems

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



Joined: 20 Sep 2003
Posts: 47
Location: Brussel - Belgium

View user's profile Send private message

16F88 problems
PostPosted: Fri Dec 10, 2004 4:04 pm     Reply with quote

Hello,

after working with PCW 3.163, I have now the PCW 3.213. The reason of this change, I want to use the 16F88.

I try my two first programs with this Pic but nothing work. Then I use the projet wizard to be sure that I don't make mistake. But it is the same.(I use ICDU-40 to test but without it is the same)

Here the code given by the wizard (I have only write what is on the while {}).

First program : with extern xtal of 4 Mhz.

Code:
#include <16F88.h>
#device *=16
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, DEBUG, NOPROTECT, FCMEN, NOIESO

void main()
{
   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   while(true)
      {
      output_low (PIN_B1);
      delay_ms (500);
      output_high (PIN_B1);
      delay_ms (500);
      }
}


Second program : internal Xtal.

Code:
#include <16F88.h>
#device *=16
#device ICD=TRUE
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, DEBUG, NOPROTECT, FCMEN, IESO

void main()
   {
   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   while(true)
      {
      output_low (PIN_B1);
      delay_ms (500);
      output_high (PIN_B1);
      delay_ms (500);
      }
   }


In both case, when I run step /step, at the first instruction (port_b_pullups(TRUE);) the following message is comming :

Invalid clock value from the debugger. Debugging may not have been enabled.

For the external Xtal, on the screen of the debugger, it's write Ready MCU at 3.99 Mhz.
For the internal Xtal, it's write Ready MCU at 0,03 Mhz. I have change INTRC_IO to INTRC without succes.

I never had this problem with 16F876 (only external Xtal....!) and old PCW version.
If somebody have experience with this Pic, its suggestions are appreciated.
Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 10, 2004 5:31 pm     Reply with quote

I think your program is too complicated, as a first test program.
Try the following program. It's for use with an external 4 MHz
crystal. Of course, the crystal will require external capacitors.
A value of 22 pf will work. This program assumes the PIC
is running at +5 volts. Also check that the MCLR pin is connected
to +5 volts through a resistor. I believe CCS recommends 47K
for use with their ICD.

Use your ICD as a programmer only. Don't use it as a debugger
for this first test program.

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

void main()
{
setup_adc_ports(NO_ANALOGS);

while(1)
  {
   output_low (PIN_B1);
   delay_ms (500);
   output_high (PIN_B1);
   delay_ms (500);
  }

}
GDetienne



Joined: 20 Sep 2003
Posts: 47
Location: Brussel - Belgium

View user's profile Send private message

PostPosted: Sat Dec 11, 2004 6:36 am     Reply with quote

Thanks PCM for your good and quick answer.

Your "very short" program work fine. If I change XT with INTRC_IO it work also without extern Xtal.

Now I try to implement the other set up and fuse to determine what was wrong.

Strange that the projet wizard give bad code.....
Have a nice week end.
Guest








PostPosted: Sun Feb 20, 2005 2:52 pm     Reply with quote

PCM programmer,

I used your simple code (using the 16LF88 with PCW 3.215) for the internal RC.
It didn't work.
I add :
OSCCON = 0x6c;
and it's start working.
After some debugging I removed the line :
#device ICD=TRUE
And the internat OSC stop working.
Any idea please?
I use :
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, LVP


thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 20, 2005 4:19 pm     Reply with quote

I'm not at the company right now, so I only have vs. 3.219 to test
your problem.

1. Does your program have the #fuses statement above the #use delay
statement, like my sample program does ? Example:
Code:
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

If you use INTRC_IO, and you put the #fuses statement first,
then the compiler will automatically insert code to setup the OSCCON
register. For vs. 3.129, the startup code is shown below. The setup
code for OSCCON (register address 0x8F) is shown in bold.
The compiler puts 0x60 into OSCCON.

.................... void main()
.................... {
0019: CLRF 04
001A: MOVLW 1F
001B: ANDWF 03,F
001C: BSF 03.5
001D: BCF 1F.4
001E: BCF 1F.5
001F: MOVF 1B,W
0020: ANDLW 80
0021: MOVWF 1B
0022: MOVLW 07
0023: MOVWF 1C
0024: MOVF 1C,W
0025: BCF 03.5
0026: BCF 0D.6
0027: MOVLW 60
0028: BSF 03.5 // Switch to Bank 1
0029: MOVWF 0F // Put 0x60 into OSCCON (at 0x8F)


If you don't have the #fuses statement first, that could explain why
you had to put in your own statement to setup OSCCON.
Or, it could be a problem with your version of the compiler.
I have to wait until Monday morning to test it with vs. 3.215.

2. If you're using #device ICD=TRUE, then I assume you have an ICD.
The ICD does not use Low Voltage Programming. But you have
the fuse set to LVP. Why ? I think you should change it to NOLVP.
If it's set to LVP, the PIC can lock up and the program will not run.

3. What ICD do you have ? I have the ICD2. I don't know very
much about the CCS ICD. But, I believe that #device ICD=TRUE
is only needed if you use the ICD as a debugger. If you use it as
a programmer, then you don't need that statement. With older
versions of MPLAB (I'm using 7.01 -- the latest version), you have
to disconnect the ICD2 from your project board after programming
it, in order to let the PIC program run. So, if you're using the
ICD as a programmer then please disconnect the ICD cable from
your board. Then maybe it will run.
GDetienne



Joined: 20 Sep 2003
Posts: 47
Location: Brussel - Belgium

View user's profile Send private message

Always problems with 16F88 ...
PostPosted: Mon Feb 21, 2005 7:45 am     Reply with quote

Dear PCM programmer,

this week end I have start again my projet with 16F88. The same projet work with 16F876.

One test program with LCD and MCLR on port A work.
If I put two LED on port B. No caracters on my LCD.

I search and I send you (on this forum) the results or questions with my code.

Thanks in advance.
wave_man



Joined: 06 Jan 2005
Posts: 4
Location: spokane, WA

View user's profile Send private message

PIC16F88 Problems
PostPosted: Wed Feb 23, 2005 1:40 pm     Reply with quote

I have begun work with a prototype brush motor controller board based around the 16F88. I am running at 20mHz, very clean clock. The critical "Hello world" milestone is passed.

The next step I am trying to accomplish is the reading of a single analog input port. The reading always comes up 0.0 in the serial window. The pin on the PIC reads 4.99V. Here is my code:

#include <16f88.h>
#device ADC=10
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=PIN_B5, rcv=PIN_B2)
#include <stdlib.h>

main()
{
long reading;
float outp;
set_tris_a(0b00001011); //problem here?
set_tris_b(0b11000100);
setup_adc_ports (sAN1);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(1); //should this be (0)?
setup_timer_0(RTCC_INTERNAL);

while(TRUE)
{
delay_ms(1000);
reading=read_adc();
outp=reading/1024;
// this is for 10-bit a/d setting
printf("\r\nThe reading is %9.4f ",outp);
//printf("\r\n hello world!");
}
}

If you can help out I would very much appreciate it.

wave_
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 2:32 pm     Reply with quote

The problem is that you're dividing two integers. Since the numerator
is always smaller than the denominator, the result is always = 0.

You should change those numbers to floats. Example:
Code:
outp = (float)reading/1024.0;
wave_man



Joined: 06 Jan 2005
Posts: 4
Location: spokane, WA

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 11:42 am     Reply with quote

Oh Jeez...

Type conversion error, what a rookie move. Thanks very much for your help.
I will try this fix out.

wave_man
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