View previous topic :: View next topic |
Author |
Message |
cchechio
Joined: 26 Dec 2008 Posts: 6
|
led Blink |
Posted: Fri Dec 26, 2008 8:42 am |
|
|
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
|
|
Posted: Fri Dec 26, 2008 8:53 am |
|
|
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
|
|
Posted: Fri Dec 26, 2008 10:37 am |
|
|
PIC16F88 have OSCCON register. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Dec 26, 2008 11:19 am |
|
|
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
|
|
Posted: Fri Dec 26, 2008 12:26 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 12:40 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 1:44 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 2:50 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 3:08 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 3:43 pm |
|
|
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
|
|
Posted: Fri Dec 26, 2008 4:15 pm |
|
|
Seems O.K. except for MCLR connection. You need either a pullup or must disable MCLR function. |
|
|
|