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

led Blink

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



Joined: 26 Dec 2008
Posts: 6

View user's profile Send private message

led Blink
PostPosted: Fri Dec 26, 2008 8:42 am     Reply with quote

I am using mplab and ccs compiler.

i am testing my pic 16f88 and i write a simple led blinking.

here there is the code:

#include <16F88.h>
void main(void) {

#byte OSCCON = 0x60
setup_adc(ADC_OFF);
set_tris_b( 0x00 );

#use delay(clock=4000000)
while(1) {
OUTPUT_HIGH(PIN_B5);
DELAY_MS(500);
OUTPUT_LOW(PIN_B5);
DELAY_MS(500);
}
}

i have compiled this code and all ok.

after i have selected the programmer picKit2
and then i program the target device.

but my led is off.

why ?

Can you help me ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 8:53 am     Reply with quote

A PIC16F88 has no OSCCON register. Clock operation depends on fuses settings, that may be wrong in your code, if present at all. You should show the complete code.
cchechio



Joined: 26 Dec 2008
Posts: 6

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 10:37 am     Reply with quote

PIC16F88 have OSCCON register.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 11:19 am     Reply with quote

I am surprised it compiled. You are not constructing your program
properly. Your pre-processor statements should be outside the Main code
as shown in the below example.

The below uses the internal oscillator at 4MHZ. I put
in the fuse statement and the setup_oscillator line rather than direct
register setting. Let the compiler do the work....

Code:

#include <16F88.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

void main()
{
  setup_adc(ADC_OFF);
  setup_oscillator(OSC_4MHZ);
//
while(1)
  {
   output_high(PIN_B5);
   delay_ms(500);
   output_low(PIN_B5);
   delay_ms(500);
  }
}
cchechio



Joined: 26 Dec 2008
Posts: 6

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 12:26 pm     Reply with quote

Ok.

but why my led is off.

i have compiled the code.

and click the button "Program the target device"

Where is my error ?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 12:40 pm     Reply with quote

The code is simple and should run with no problems if your hardware is good. I would suspect how the LED is connected to the PIC.

A few questions:

How is the LED connected to the PIC? Is it from the PIC to ground or to VCC? What is the value of the series resistor?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 1:44 pm     Reply with quote

Quote:
PIC16F88 have OSCCON register.
Right. But internal oscillator must be enabled by #fuses setting. You can trace code execution with MPLAB and PICkit 2, to see, if the output ports are actually set.
cchechio



Joined: 26 Dec 2008
Posts: 6

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 2:50 pm     Reply with quote

Here, there are how I have connected PIC16F88 :
Code:
_____________X--- 1
_____________X--- 2
_____________X--- 3
_____Vpp/MCLR --- 4 PROGRAMMER pickit2
__________GND --- 5
_____________X--- 6
_____________X--- 7
_____________X--- 8
_____GND_R=1k_-- 9
____________X--- 10
GND--KA--R=1k--- 11
_________ PGC--- 12 PROGRAMMER pickit2
_________ PGD--- 13 PROGRAMMER pickit2
___GND--||--5V--- 14
____________X--- 15
____________X--- 16
____________X--- 17
____________X--- 18
____________X--- 19

 
-||-  Capacitor (100nF)
-KA- Catod and Anod of a led
GND- GROUND
X--- pin unconnected

Where is the error ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 3:08 pm     Reply with quote

The hardware looks O.K., so a configuration errors seems likely. You have no MCLR pull-up, it doesn't work e. g. with MCLR #fuse enabled. Unfortunately, you didn't yet show your configuration.
cchechio



Joined: 26 Dec 2008
Posts: 6

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 3:43 pm     Reply with quote

i read the configuration from picKit 2 programmer:

my configuration is:
Device: PIC16F88
UserID: FF FF FF FF
Checksum 6E35
Configuration 3F70 0003

VDD Target:
O Check
X /MCLR


Program Memory
Enabled

EEPROM Data
Enabled
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 26, 2008 4:15 pm     Reply with quote

Seems O.K. except for MCLR connection. You need either a pullup or must disable MCLR function.
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