View previous topic :: View next topic |
Author |
Message |
help Guest
|
PIC18F452 LED problem |
Posted: Fri Jun 01, 2007 11:00 pm |
|
|
Helllo,
I am a beginner for the PIC18F452 chip. I tried to test a simple circuit. I would like to light on LED on A1, A2 and A3. It doesn't work. When I pull out the 9V adaptor, LED (A1, A2 and A3) suddenly on then off. Could any expert help me? Thanks a lot!!
Hardware:
- Connect 1k ohms with LED on A1, A2 and A3 pin.
- Connect potentiometer with 5V pull-up on A0 and A5.
- Connect voltage regulator to supply Vdd 5V
- Connect oscillator on OSC1 and OSC2
- MCLR for reset
Software (with CCS code)
#include <18f452.h>
#include <stdlib.h>
#include <CTYPE.h>
#include <STDDEF.h>
#include <STDLIB.h>
#include <STRING.h>
#include <STDIO.h>
#include <LIMITS.h>
#include <SETJMP.h>
#use fast_io(A)
void main ()
{
output_high(PIN_A1);
output_low(PIN_A2);
output_high(PIN_A3);
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
help Guest
|
PIC18F452 LED problem |
Posted: Fri Jun 01, 2007 11:13 pm |
|
|
Sorry, I repost the software...
#include <18f452.h>
#include <stdlib.h>
#include <CTYPE.h>
#include <STDDEF.h>
#include <STDLIB.h>
#include <STRING.h>
#include <STDIO.h>
#include <LIMITS.h>
#include <SETJMP.h>
#use fast_io(A)
void main ()
{
set_tris_a(0xF1);
output_high(PIN_A1);
output_low(PIN_A2);
output_high(PIN_A3);
} |
|
|
help Guest
|
PIC18F452 LED problem |
Posted: Fri Jun 01, 2007 11:30 pm |
|
|
PCM programmer,
I tried the code you provide and change the "B0" to A1. The problem is still there. When I pull out the 9V adaptor, the A1 LED on then off...Thanks... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 01, 2007 11:47 pm |
|
|
I changed the pin to A1 as shown below, and compiled with PCH vs.
4.039 and tested it on a PicDem2-Plus board. It works OK. It blinks
the LED.
If this code doesn't work, I think either your programmer doesn't work
or you have some other hardware problem on your board.
Code: |
#include <18F452.h>
#fuses XT, NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock = 4000000)
//====================================
void main()
{
while(1)
{
output_high(PIN_A1);
delay_ms(500);
output_low(PIN_A1);
delay_ms(500);
}
} |
|
|
|
help Guest
|
PIC18F452 LED problem |
Posted: Sun Jun 03, 2007 7:00 am |
|
|
It works! I change #fuses setting to HS and NOLVP. Thank you! |
|
|
|