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

16F677 not running? I'm using an ICD2

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








16F677 not running? I'm using an ICD2
PostPosted: Tue Dec 12, 2006 3:43 pm     Reply with quote

Hello All,

I'm using a PIC 16F677 in circuit.
I'm using CCS version 4.005
I'm using an ICD2 with MPLAB 7.41 to program the chip.

MPLAB claims that I am actually programming the chip and can read the data back and identified the device properly.


However,

All I want to do is turn on an LED or turn it off with just test code.
Here is the code:

This is the .h file:

#include <16F677.h>
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled

#use delay(clock=4000000)
//#use i2c(Slave,Slow,sda=PIN_B4,scl=PIN_B6,address=0x)

//#use fixed_io(a_outputs=PIN_A0)
//#use fixed_io(c_outputs=PIN_C0, PIN_C1, PIN_C2, PIN_C7)





This is the .c file:

#include "C:\PSUFIRMW\Decemberrestart\davedec.h"
#include <stdio.h>
#include <string.h>

void main(void) //initialization
{

setup_adc_ports(sAN1|sAN2|sAN8|sAN11|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
//enable_interrupts(INT_AD);
//enable_interrupts(INT_SSP);
//enable_interrupts(GLOBAL);
setup_oscillator(FALSE);

while(1) //main program loop
{
output_low(PIN_C2);
output_low(PIN_C1);
output_low(PIN_C0);

}

}


please note that I have 3x 5V to a 330ohm resistor to an LED anode, then that LED's cathode connected in series to each PIN C1 individually.

In otherwords: the LEDs are active low and should get 15ma through them when turned on.

please note that i have remarked a few lines as I was just trying different things to get this to work properly.

When I put a multimeter on C0, C1 or C2, I read 3.7VDC which I think means the pins are tri-stated or something.

the PIC is getting 5V on the VDD pin.
I have a separate brown out circuit for the MCLR pin: its reading 5V on the MCLR pin when my board is powered on.

Also, MPLAB's own configuration bits:
Address 2007
Value 3CF1
Oscillator XT
Watchdog Timer Off
Powerup Timer Off
Master Clear Enable External
Code Protect Off
Data EE Read Protect Off
Brown Out Detect BOD and SBOREN disabled
Internal External Switch Over Mode enabled
Monitor Clock Fail-safe enabled
Guest








i posted teh above code
PostPosted: Tue Dec 12, 2006 3:44 pm     Reply with quote

The 2 blank includes are actually:

#include <stdio.h>
#include <string.h>

for some reason the stdio and string didn't paste over, but are actually there.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 12, 2006 4:02 pm     Reply with quote

You're using an early version of the vs. 4 compiler. So it's possible
that the analog pins that you're using (C0, C1, C2) are not being
properly setup as digital pins.

To test this idea, try moving your LEDs to some pure digitial pins
such as C5, C6, C7.

-------

The reason your #include files didn't show up, is because you had
HTML enabled when you made your post. You have to disable
with a checkbox below the posting window. It looks like this:
Quote:
x Disable HTML in this post

If you're a registered user (and you log in), the forum software
will remember this setting.
Guest








Thanks!
PostPosted: Tue Dec 12, 2006 4:26 pm     Reply with quote

Hello,

Thanks for the reply,


I also have an LED on Port C5, a purely digital output connected in the same way and it still doesn't light up.



I have a 4MHz crystal connected very close to pins 2 and 3 and have 22pF capacitors from ground to pin2 and pin3.




If you had to write a quick program to turn on an active LOW LED, what would you write?
Ttelmah
Guest







PostPosted: Tue Dec 12, 2006 5:02 pm     Reply with quote

You _may_ be running into the RMW PIC problem. When you do an individual pin output, the voltage on the other pins is read, this result is modified with the extra bit you are setting/resetting, and the resulting value is output on the port. Now you output a 'low', and then only one instruction latter, output another 'low'. If the first pin has not actually dropped to the 'low' input voltage by this point, it'll be read as a 'high', and the first low will be lost. This could then repeat for each of the subsequent outputs, and back round the loop, resulting in all the pins ending up high.
Try outputting a whole byte, or adding a short delay after each bit output.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 12, 2006 5:04 pm     Reply with quote

Quote:

If you had to write a quick program to turn on an active LOW LED,
what would you write ?

Try the program shown below, which will blink an LED on Pin C5.

Make sure you have a pull-up resistor on the MCLR pin. If you're using
the CCS ICD-U40, use 47K. If you have the Microchip ICD2, use 10K.
Code:

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

void main()
{

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

}
Guest








Hello Guys
PostPosted: Fri Dec 15, 2006 8:51 am     Reply with quote

Thank you both very much for caring enough to help me.


My problem was pilot error: I was using the MPLAB CCS Plugin, compiling with CCS to look for code errors:

HOWEVER I FORGOT TO CLICK COMPILE IN MPLAB!!! Yeah... everything works ok now, but I appreciate your help.


Perhaps a simple walkthrough with screenshot captures for setting up MPLAB + CCS + a demo board would be good to have posted as a Forum Sticky.


Thanks again guys!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 15, 2006 12:29 pm     Reply with quote

Quote:
Perhaps a simple walkthrough with screenshot captures for setting up MPLAB + CCS.

It's in the CCS FAQ. The tutorial:
http://www.ccsinfo.com/faq.php?page=ccs_mplab6

Main FAQ page:
http://www.ccsinfo.com/faq.php
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