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

CCS programming novice.

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



Joined: 23 Jun 2016
Posts: 1

View user's profile Send private message

CCS programming novice.
PostPosted: Thu Jun 23, 2016 9:04 pm     Reply with quote

Hello guys, this is my first time programming a microchip using ccs. I want to program a Pic18f87k90. Here is the code I did for a square wave, please have a look at it and tell me if I am doing everything right.
Code:

#include <18f87K90.h>
#use delay(crystal=20mhz)
#use rs232(baud=9600)

// Square wave function
void main() {

   while (TRUE) {
     output_high(PIN_D2);
     delay_ms(1000);
     output_low(PIN_D2);
     delay_ms(1000);
   }
}


Thanks for your replies
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Jun 24, 2016 1:46 am     Reply with quote

Always tell us the compiler version. Smile

However comments:

1) Have you got the MCLR pin on the chip pulled up?.

2) Correct power connections. Figure 2-1 in the data sheet.

3) What voltage are you running the chip?. Vreg enabled or disabled?. Figures 31-1, and 31-2 in the data sheet.

4) You need to ensure the LCD drive is disabled. Otherwise D2, is a segment drive.

setup_lcd(LCD_DISABLED);

This is a general comment. You need to always ensure other peripherals on a pin are disabled. Segment output has priority over normal I/O.

5) Your #USE RS232, needs to specify a UART, or pins to apply to. Doesn't matter since you are not using it, but something like:

#USE RS232(UART1, BAUD=9600, ERRORS)

6) How are you testing the output?. Remember if this is feeding something like an LED, a current limiting resistor is needed.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jun 24, 2016 6:05 am     Reply with quote

7) #FUSES !!! you don't specify any and the 18f87K90 is a VERY complex chip with a long list of fuse options to consider.

you picked a doozy of a chip to "learn" on ..
is this because you have it on a development PCB of some kind already ?
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 24, 2016 8:08 am     Reply with quote

re: #7 yup ! I use the 18F46K22 and have a complete, separate file JUST for fuses !! I #include it as the 'defaults' aren't what I need and there's so many that I hate seeing 2 pages of fuses at the top of the programs!!

Even the 46K22 is 'fun' the 87K90 wouldn't be my first choice to learn on !!

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Jun 24, 2016 9:15 am     Reply with quote

The ones given for his code with the current compiler, are:
Code:

Configuration Fuses:
   Word  1: C215   VREGSLEEP INTRC_HP SOSC_DIG NOXINST HSH NOPLLEN FCMEN IESO
   Word  2: 7C7E   PUT BROWNOUT BORV18 ZPBORM NOWDT WDT1048576
   Word  3: 8B01   RTCOSC_T1 CCP2C1 ECCPE MSSPMSK7 MCLR
   Word  4: 0091   STVREN BBSIZ2K NODEBUG
   Word  5: C0FF   NOPROTECT NOCPB NOCPD
   Word  6: E0FF   NOWRT NOWRTC NOWRTB NOWRTD
   Word  7: 40FF   NOEBTR NOEBTRB

Which probably ought to work.
It's waking on the INTRC oscillator and switching to the HSH oscillator without PLL. If he hasn't actually got a working crystal, it'll then drop back to the internal oscillator.
It ought to _run_, though whether at the right rate is more dubious....
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 24, 2016 10:00 am     Reply with quote

hmm...
The ones given for his code with the current compiler...

I didn't see a hint as to which version.....
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Jun 24, 2016 2:27 pm     Reply with quote

Agreed totally. First line of my post... Smile

Assumed he most probably has the demo compiler, so a recent version. Could very easily be totally wrong in this assumption.
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