View previous topic :: View next topic |
Author |
Message |
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
Need help flashing an LED with PIC16F18323 |
Posted: Fri Oct 13, 2023 12:08 pm |
|
|
Code: |
#include <16F18323.h>
#fuses NOWDT
#use delay(internal = 1MHZ)
void main(void)
{
while(TRUE)
{
output_bit(PIN_C0, 0);
delay_ms(500);
output_bit(PIN_C0, 1);
delay_ms(500);
}
}
|
I can't get the RS232 to work properly so now trying an LED. Any ideas? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Oct 13, 2023 12:25 pm |
|
|
You dont specify an oscillator type in the fuses so maybe the oscillator isn't running?
Code: |
//////// Fuses: LP,XT,HS,NOEXTOSC,ECL,ECM,ECH,RSTOSC_HFINTRC_PLL
//////// Fuses: RSTOSC_EXT_PLL,RSTOSC_SOSC,RSTOSC_LFINTRC
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 12:29 pm |
|
|
Thank you. I thought the "internal" took care of that? Also, forgot to mention that the compiler is 5.116. It works fine on a 16F15223. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Oct 13, 2023 1:00 pm |
|
|
which programmer ? IE With MPLAB v8.xx, you have to set the 'build configuration' to 'release' NOT 'debug' before you compile your code. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 1:03 pm |
|
|
Hello, I am using the ICD-U64. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat Oct 14, 2023 7:10 am |
|
|
Take us through how your hardware is all setup and connected?.
I have just tested your RS232 program, and it works as posted, except
I connected both RX and TX pins (you really do need to do this, the RX
is always enabled, and if it is connected to an indeterminate state it can
result in the chip drawing more power and if you ever try to use interrupts
you can get spurious triggers).
I also had a pull-up on MCLR (your code as posted enables the MCLR
pin).
How is your supply generated?.
How are the connections made?.
How is the ICD connection made?.
What decoupling do you have, particularly adjacent to the chip?.
How is the RS232 connected?.
How is the LED connected?.
I wired a TTL output USB-RS232 converter directly to the TX pin, for
the RS232. Then tried this flash an LED code, and it too ran fine.
Had a 270R resistor feeding a red LED. Hopefully you _have_ got
a current limiting resistor on the LED connection, otherwise the chip
will reset when it tries to turn the LED on.
Code: |
#include <16F18323.h>
#fuses PUT, NOWDT,NOMCLR //depending on how you have MCLR wired?
#use delay(INTERNAL=32MHZ)
#pin_select U1TX=PIN_C4
#pin_select U1EX=PIN_C5
#use rs232(UART1,baud=28800,parity=N,bits=8,errors,stream=VT)
void main(void)
{
set_slow_slew_C(FALSE); //ensure slew rate limiting off
fprintf(VT, "Hello World!!\r\n");
while(TRUE)
{
fprintf(VT, "Hello World??\r\n");
delay_ms(1000);
}
}
|
|
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Mon Oct 16, 2023 12:36 pm |
|
|
Code: |
#include <16F18323.h>
#fuses NOWDT
#use delay(internal = 1MHZ)
void main(void)
{
output_bit(PIN_C1, 1);
while(TRUE);
}
|
I can't even set this bit. It measures 0 on the voltmeter but works fine on the board with the 16F15223. It it possible to be able to program a PIC and the chip still be bad? The weird thing is that none of the boards with the '323 seem to work despite being able to program them. The reset pin is at 4.15v after programming. The board gets power from the programmer.
OK, it gets more weird. It works if I run the program with the debugger. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Mon Oct 16, 2023 12:58 pm |
|
|
Code: |
#include <16F18323.h>
#fuses NOWDT
#use delay(internal = 1MHZ)
void main(void)
{
while(TRUE)
{
output_bit(PIN_C1, 0);
delay_ms(500);
output_bit(PIN_C1, 1);
delay_ms(500);
}
}
|
This program flashes the LED only if I run it in the debugger. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Oct 16, 2023 2:09 pm |
|
|
Maybe someone with an ICD-U64 can test and explain how to program the PIC but I suspect you've compiled the code in 'debug' mode and not 'release'.
I had similar problem until Microchip changed MPLAB so allow ME to choose the 'default' build configuration....when using the PICKit3. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Mon Oct 16, 2023 3:39 pm |
|
|
I added the statement:
and now it works. Also, I deleted the #device statement and it still works. Apparently, something got reset or happy. If anyone knows why this worked, I would be most grateful to know. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Mon Oct 16, 2023 4:21 pm |
|
|
randy.shaffer wrote: | Also, I deleted the #device statement and it still works. |
....Uh, it shouldn't work at all if you deleted the #device line.
Years ago, I ran into periodic compiler weirdness quite a bit, and in desperation I reinstalled the compiler. That fixed it, but in time, it would start to play up again.
Some time later, I started having obvious SSD issues. Turns out that my hard drive was failing and for some reason CCS was the 'canary in the coal mine.' Try reinstalling your compiler just to see if some of the weirdness goes away. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Mon Oct 16, 2023 4:26 pm |
|
|
Thank you newguy, I will give that a try. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Oct 17, 2023 12:48 am |
|
|
Note my question about how the MCLR line is wired....
Note my using NOCLR.....
When you have the ICD connected it pulls up the MCLR line. If you don't
have this connected, the MCLR line needs a pull-up. Otherwise the chip
won't run unless you select NOMCLR.
If you are running in MPLAB, this _defaults_ to running in debug mode
unless you explicitly turn this off. I always have this off unless I want to
debug. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Tue Oct 17, 2023 8:53 am |
|
|
Thank you, Ttelmah. The MCLR pin has a 10k pull-up. I am using the CCS IDE and the ICD-U64 programmer. |
|
|
|