View previous topic :: View next topic |
Author |
Message |
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
pic 18f6722 |
Posted: Sun Mar 09, 2014 7:45 am |
|
|
i am using the pic18f6722 for the first time. I tried a simple LED toggle program using CCS, but it wont work.
i tried putting some value on one of its port, which works fine.
so i concluded that the delay_ms() function is not working in it. i tried internal oscillator, external oscillator of 4MHZ, but nothing seems to make the delay function work.
if someone would have simple code blinking a led with delay_ms(), working on internal oscillator or external oscillator 4MHz, it would be very helpful.
thankyou in advance. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 09, 2014 7:48 am |
|
|
Please show us your program so we can debug it.Select the 'code' button in the line that says 'message body', before and after you 'cut and paste' your program. Also tell us which version of the compiler you have.
Also, please delete the 2nd thread that you have. I suspect you might have pressed the 'submit' button twice(easy to do !).
hth
jay |
|
|
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
|
Posted: Sun Mar 09, 2014 8:00 am |
|
|
this is the file i used for testing
Code: |
#include "main.h"
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
// TODO: USER CODE!!
while(1)
{
output_bit( PIN_D0, 0);
delay_ms(1000);
output_bit( PIN_D0, 1);
delay_ms(1000);
}
}
|
this is main.h file which i have included
Code: |
#include <18F6722.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K //1K words Boot Block size
#use delay(clock=8000000)
|
|
|
|
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
|
Posted: Sun Mar 09, 2014 8:08 am |
|
|
i have version 4.038.
the LED does not glows at all with code that i have posted above.
If i swap position of output bit as shown below, the LED glows and does not gets OFF.
Code: |
while(1)
{
output_bit( PIN_D0, 1);
delay_ms(1000);
output_bit( PIN_D0, 0);
delay_ms(1000);
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 09, 2014 8:33 am |
|
|
possible problem ....
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
99.9999% of PIC programmers do NOT use LVP, so change to NOLVP.
also
#FUSES NOPUT //No Power Up Timer
I always set to PUT, as it allows the PIC a little bit of time to get organized internally.
I didn't see anything else that's 'obvious' wrong...though I don't know why the 'code' button didn't work either!
hth
jay
++++++++++++++++++++++
Reason: User amit disabled BBcode in his profile.
Fixed.
- Forum Moderator
++++++++++++++++++++++ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Sun Mar 09, 2014 2:58 pm |
|
|
Code: |
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
|
These are both wrong.
Need to be 'setup_spi(FALSE);' etc..
These will prevent the pins for both SPI1, and SPI2 from being used for normal I/O. Haven't checked what pins they are on this chip, but won't help...
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 09, 2014 3:34 pm |
|
|
Quote: | #FUSES XINST //Extended set extension and Indexed Addressing mode enabled |
And this is wrong. It will enable the extended instruction set which is
not supported. Your program will do crazy things. Change it to NOXINST. |
|
|
amit
Joined: 08 Mar 2014 Posts: 7 Location: India
|
|
Posted: Tue Mar 11, 2014 7:07 am |
|
|
PCM Programmer,
Your suggestion worked i used NOXINST and it worked instantly, thankyou. |
|
|
|