View previous topic :: View next topic |
Author |
Message |
Alex18
Joined: 23 Jun 2016 Posts: 1
|
CCS programming novice. |
Posted: Thu Jun 23, 2016 9:04 pm |
|
|
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: 19545
|
|
Posted: Fri Jun 24, 2016 1:46 am |
|
|
Always tell us the compiler version.
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
|
|
Posted: Fri Jun 24, 2016 6:05 am |
|
|
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
|
|
Posted: Fri Jun 24, 2016 8:08 am |
|
|
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: 19545
|
|
Posted: Fri Jun 24, 2016 9:15 am |
|
|
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
|
|
Posted: Fri Jun 24, 2016 10:00 am |
|
|
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: 19545
|
|
Posted: Fri Jun 24, 2016 2:27 pm |
|
|
Agreed totally. First line of my post...
Assumed he most probably has the demo compiler, so a recent version. Could very easily be totally wrong in this assumption. |
|
|
|