MPLAB IED PIC question. - RC Groups
Shop our Airplanes Products Drone Products Sales
Thread Tools
Jul 15, 2010, 03:39 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
Question

MPLAB IED PIC question.


Hi,

I have just received my PICKIT2, I have programmed all the 12 lessons without any problem. When I inserted code (Hello World) from 123 PIC Projects for the evil genius by opening "new" and writing it, it said "build failed".
Would it be the toolsuite picked?
Only the codes sent with PIC kit2 seem to work.
The PIC kit2 software HEX programmer works as long as the HEX file is valid. I will see If I can use other files.
Is there anything else I need for MPLAB IED?

Thanks,

Inventor1
AZ
Sign up now
to remove ads between posts
Jul 15, 2010, 04:39 PM
We want... Information!
Bruce Abbott's Avatar
To begin with, you must select the correct processor (configure/select device menu) and you must add your file to the project's 'source files' folder.

Read the lines above where it says 'build failed'. Any clues there?
Jul 15, 2010, 07:54 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
The processor is correct, the source file from 123 PIC. is as follows:

include <pic.h>
__CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT
&
MCLRDIS & PWRTEN & WDTDIS & INTIO);
int i;
main()
{
PORTA =0;
CMCON0 =7;
ANSEL =o;
TRISA4 =0;
TRISA5 =
while (1==1)


for (i=0; i<25000; i++);
RA4 =RA4 ^ 1;

}

}



The error sheet is


Debug build of project `C:\PK2 Lessons\LPC Demo Board\PICFlash\123Flash1.mcp' started.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Thu Jul 15 17:40:16 2010
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F690 "123Flash1.asm" /l"123Flash1.lst" /e"123Flash1.err" /d__DEBUG=1
Warning[205] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 1 : Found directive in column 1. (include)
Error[105] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 1 : Cannot open file (Include File "pic.h" not found)
Warning[205] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 2 : Found directive in column 1. (__CONFIG)
Error[109] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 2 : Unmatched (
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 2 : Symbol not previously defined (FCMDIS)
Error[124] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 2 : Illegal argument
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 3 : Illegal character (&)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 4 : Found label after column 1. (MCLRDIS)
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 4 : Illegal character (&)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 5 : Found label after column 1. (int)
Error[122] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 5 : Illegal opcode (i)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 6 : Found label after column 1. (main)
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 6 : Illegal character (()
Error[108] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 7 : Illegal character ({)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 8 : Found label after column 1. (PORTA)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 9 : Found label after column 1. (CMCON0)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 10 : Found label after column 1. (ANSEL)
Error[113] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 10 : Symbol not previously defined (o)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 11 : Found label after column 1. (TRISA4)
Warning[207] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 12 : Found label after column 1. (TRISA5)
Error[128] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 12 : Missing argument(s)
Error[129] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 22 : Expected (ENDW)
Error[129] C:\PK2 LESSONS\LPC DEMO BOARD\PICFLASH\123FLASH1.ASM 23 : Expected (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\PK2 Lessons\LPC Demo Board\PICFlash\123Flash1.mcp' failed.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Thu Jul 15 17:40:18 2010
----------------------------------------------------------------------
BUILD FAILED






Is MPASM able to compile that code?
What alternative codes are there to test my MPLAB?
The book does not say what "pic.h" is or where it comes from.
I was able to compile this code with MPLAB, the problem was not having the right chip, or Xtal, my chip is PIC16f690.





;-------------------------------------------------------------------------;
; EGGTIMER.ASM A 3 minute countdown timer for boiling eggs ;
;-------------------------------------------------------------------------;

LIST P=16F84 ; tells which processor is used
INCLUDE "p16f84.inc" ; defines various registers etc. Look it over.
ERRORLEVEL -224 ; supress annoying message because of tris
__CONFIG _PWRTE_ON & _LP_OSC & _WDT_OFF ; configuration switches

;-------------------------------------------------------------------------;
; Here we set up the user defined registers ;
;-------------------------------------------------------------------------;
CBLOCK H'0C' ; first free register address is 12
sec ; keeps track of seconds
sec10 ; keeps track of tens of seconds
mins ; keeps track of minutes
w_temp ; holds value of W during interrupt
status_temp ; holds value of STATUS during interrupt
finflag ; act as a flag to indicate end of countdown
oldsec10 ; holds last displayed value of sec10
ENDC

ORG 0 ; start a program memory location zero

goto main ; jump over the interrupt routine

ORG 4

;-------------------------------------------------------------------------;
; here is the interrupt routine, happens every second if GIE is enabled ;
;-------------------------------------------------------------------------;
movwf w_temp ; save W
swapf STATUS,W ; save status
movwf status_temp ; without changing flags

decf sec, f ; decrement seconds register
movlw H'FF' ; check if underflow
subwf sec, W ; will give zero if sec = H'FF'
btfss STATUS, Z ; skip next instruction if underflow
goto restore ; no underflow, leave interrupt routine
movlw 9 ; change seconds register to 9
movwf sec
decf sec10, f ; now we follow the same procedure ...
movlw H'FF' ; for the sec10 register
subwf sec10, W
btfss STATUS, Z ; skip if underflow
goto restore ; no underflow, leave
movlw 5 ; change sec10 register to 5
movwf sec10
decf mins, f ; and decrement minutes register
movlw H'FF' ; check if ...
subwf mins, W ; an underflow of minutes ...
btfss STATUS, Z ; yes means the count is finished
goto restore ; no underflow
incf finflag, f ; set the finished flag
restore:
swapf status_temp,W ; get original status back
movwf STATUS ; into status register
swapf w_temp,f ; old no flags trick again
swapf w_temp,W ; to restore W
bcf INTCON,T0IF ; clear the TMR0 interrupt flag
retfie ; finished reset GIE

;================================================= ========================;
; This is the main program ;
;================================================= ========================;
main:

;-------------------------------------------------------------------------;
; initialize the ports, set up interrupts etc: ;
;-------------------------------------------------------------------------;
movlw B'00000000' ; all bits low in W
tris PORTA ; contents of W copied to PORT A ...
movlw B'00010000' ; RB4 input, all other output
tris PORTB ; and PORT B
movlw B'00000100' ; port B pull-ups active
; prescalar assigned to TMR0 and set 1:32
option ; rolls over each second
movlw B'00100000' ; T0IE set, GIE not set yet...
movwf INTCON ; in the interrupt register
clrf PORTB ; display 0

;-------------------------------------------------------------------------;
; initialize some other registers: ;
;-------------------------------------------------------------------------;
clrf sec ; start with sec = zero
clrf sec10 ; and sec10 = zero
clrf oldsec10 ; make oldsec10 the same
movlw D'3' ; and minutes = 3
movwf mins
clrf finflag ; clear the finished flag

;-------------------------------------------------------------------------;
; wait for pushbutton to start ;
;-------------------------------------------------------------------------;
btfsc PORTB, 4 ; switch closed, (gives 0)?
goto $ -1 ; not yet
; switch has been detected closed
; ( no debounce necessary )
clrf TMR0 ; start with timer at zero
bcf INTCON, T0IF ; and make sure the interrupt flag is clear
bsf INTCON, GIE ; enable interrupts, countdown starts

;-------------------------------------------------------------------------;
; This is the main loop that displays the time and checks if finished ;
;-------------------------------------------------------------------------;
loop: ; now go into a loop displaying registers in..
; sequence each time sec10 changes, (every
; ten seconds), and checking for finished flag
btfsc finflag, 0 ; skip next if finflag not set
goto finished ; time up
movf oldsec10, W ; check if sec10 has changed
subwf sec10, W ; zero flag set if sec10 is same as oldsec
btfsc STATUS, Z ; skip over if not the same
goto loop ; else keep checking
movf sec10, W ; replace oldsec10
movwf oldsec10 ; making it equal to sec10
movf mins, W ; display minutes
movwf PORTB ; on LEDs
call onesecond ; for one second
clrf PORTB ; blank briefly
call msec250
movf sec10, W ; now the same with sec10
movwf PORTB ; show 10's of seconds
call onesecond ; for one second
clrf PORTB ; blank
goto loop


;-------------------------------------------------------------------------;
; We come to this point when the countdown is over ;
;-------------------------------------------------------------------------;
finished:
movlw H'F' ; turn on all leds indicating finish
movwf PORTB
goto $ ; go into an endless loop

;-------------------------------------------------------------------------;
; Four calls to a delay for 250 millisecond = 1 second delay ;
;-------------------------------------------------------------------------;
onesecond: ; a subroutine that delays for 1 seconds
call msec250
call msec250
call msec250
call msec250
return

;-------------------------------------------------------------------------;
; This subroutine delays for 250 milliseconds ;
;-------------------------------------------------------------------------;
msec250: ; a subroutine to delay 250 msec
movlw D'250' ; W is changed but no separate register needed
nmsec: ; could call it here with # msec in W
nop ; each nop is 0.122 milliseconds
nop
nop ; each total loop is 8 X 0.122 = 0.976 msec
nop
addlw H'FF' ; same as subtracting 1 from W
btfss STATUS, Z ; skip if result is zero
goto nmsec ; this is 2 X 0.122 msec
return ; back to calling point

end ; end of program



Thanks,

Inventor1
AZ
Jul 15, 2010, 08:57 PM
We want... Information!
Bruce Abbott's Avatar
Quote:
Originally Posted by AZInventor1
Is MPASM able to compile that code?
No. That program is written in C, so you need to select the Hi-tech C compiler. If you didn't install it with the MPLAB package, you can download it from here.

'pic.h' is the standard C library file.

The eggtimer program is written in assmbler, so it can be assembled by MPASM. Any references to '16F84A' need to be changed to '16F690'. You may also need to change the __CONFIG options and CBLOCK start address to suit your chip, and there may be other other hardware differences to consider (read the 16F690 datasheet to see what is required).
Jul 16, 2010, 05:23 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
I do have Hi-tech universal c toolsuite- c compiler.
When I tried to build it, it showed this error.


Build C:\PK2 Lessons\LPC Demo Board\PICFlash\LEDFlash for device 16F690
Using driver C:\Program Files\HI-TECH Software\PICC\9.70\bin\picc.exe

Make: The target "C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.70\bin\picc.exe" --pass1 "C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c" -q --chip=16F690 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Warning [374] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 1.9 missing basic type; int assumed
Error [314] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 1.9 ";" expected
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 8.1 undefined identifier "PORTA"
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 9.1 undefined identifier "CMCON0"
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 10.1 undefined identifier "ANSEL"
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 10.8 undefined identifier "o"
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 11.1 undefined identifier "TRISA4"
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 12.1 undefined identifier "TRISA5"
Error [195] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 13.1 expression syntax
Error [312] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 16.23 ";" expected
Error [192] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 17.1 undefined identifier "RA4"
Error [285] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 21.1 no identifier in declaration
Warning [374] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 21.1 missing basic type; int assumed
Error [314] C:\PK2 Lessons\LPC Demo Board\PICFlash\Flash.c; 21.1 ";" expected

********** Build failed! **********



Inventor1
AZ
Jul 17, 2010, 01:02 AM
We want... Information!
Bruce Abbott's Avatar
There are a number of typing mistakes in your source code. If you double-click on each warning or error message, it will take you to the line which has the error. It's best to start at the top, because one mistake may cause other errors to occur (eg. a missing include file will cause lots of 'undefined identifier' messages).

After fixing the syntax errors you will still get an error on line 9, because the 16F690 does not have a CMCON0 register. You can safely comment out or remove this line, because the 16F690's comparators are already disabled by default.

Here is the corrected source code, showing changes required in red, and my comments (not to be included in the code!) in blue;

#include <pic.h> preprocessor directives must start with #
__CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT
&
MCLRDIS & PWRTEN & WDTDIS & INTIO);
int i;
main()
{
PORTA =0;
/* CMCON0 =7; */ 16F690 does not have a CMCON0 register
ANSEL =0; number zero, not letter o
TRISA4 =0;
TRISA5 =0; number zero required
while (1==1)
{

for (i=0; i<25000; i++);
{
RA4 =RA4 ^ 1;
}
}

}
Jul 17, 2010, 01:19 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
Thanks, I managed to compile, and build successfully, now the PIC16f690 does not show any light. How would I change the output port, is it PORTA=0?

#include <pic.h>
__CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT
&
MCLRDIS & PWRTEN & WDTDIS & INTIO);
int i;
main()
{
PORTA =0;
/* CMCON0 =7; */
ANSEL =0;
TRISA4 =0;
TRISA5 =0;
while (1==1)
{

for (i=0; i<25000; i++);
{
RA4 =RA4 ^ 1;
}
}

}



Inventor1
AZ
Jul 17, 2010, 03:23 PM
Registered User
Never programmed in C but at a guess the TRISA4, TRISA5 etc is configuring PORT A, possibly the =0 value sets it as an output - Then the program appears to run a loop with RA4 (port A bit 4) being toggled. Try placing the LED on RA4 (pin 3 of the DIL package)
Last edited by Malc C; Jul 17, 2010 at 03:28 PM.
Jul 17, 2010, 05:27 PM
"Simplify, then add lightness"
According to the schematics of the low pin count demo board the leds are on port C, bits 0-3 and are active high. To turn them on you would have to turn off the tristate bits and then turn on the output port bits.

All of the capitalized names in that C code would be defined in the pic.h file or in other files included in pic.h. I don't use 8 bit pics and don't have the .h files, but my guess would be that this would turn on the leds.
TRISC = 0xF0;
PORTC = 0x0F;

PS Most likely could also do to turn on a single led.
TRISC0 = 0;
RC0 = 1;
Last edited by jeffs555; Jul 17, 2010 at 05:33 PM.
Jul 17, 2010, 05:51 PM
Registered User
You might try BSF Bit Set File, and BCF to clear it. TRIS has to be done first
to configure the port bits for in or out.

Some people just do this at the beginning of the program, but that is a big mistake. You should do it every time, just before you run the port.

I fixed a machine for some company recently that had that error. Glitches can
change the port config bits, then it goes haywire. Resetting all the time stopped the crashing they were having.

BSF 6,0 (reg 6, bit 0)
Jul 17, 2010, 08:24 PM
"Simplify, then add lightness"
BSF and BCF are assembler commands. In C, the statments "RC0 = 1;" and "RC0 = 0;" would most likely be compiled into BSF and BCF commands to set and clear bit 0 in port C.
Jul 17, 2010, 08:56 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
It worked!
Thank you all for helping me!

Quote:
Originally Posted by Malc C
Never programmed in C but at a guess the TRISA4, TRISA5 etc is configuring PORT A, possibly the =0 value sets it as an output - Then the program appears to run a loop with RA4 (port A bit 4) being toggled. Try placing the LED on RA4 (pin 3 of the DIL package)
I placed a led on my programmer on pin RA4, and it worked. I guess that the pin out diagram for the PICKIT1 is different than PICKIT2.
I will keep in mind that the codes for each PIC are different, and adjust as needed.

Inventor1
AZ
Jul 17, 2010, 09:15 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
I changed as many lines as possible, but still have pin 3 "RA4" as output.
Could any other line control the output pin?
This is the modified code.


#include <pic.h>
__CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT
&
MCLRDIS & PWRTEN & WDTDIS & INTIO);
int i;
main()
{
PORTC =0;
/* CMCON0 =7; */
ANSEL =0;
TRISC0 = 0;
PORTC = 0;

while (1==1)
{

for (i=0; i<25000; i++);
{
RC0 =RC0 ^ 1;
}
}

}

Thanks,

Inventor1
AZ
Jul 17, 2010, 10:07 PM
We want... Information!
Bruce Abbott's Avatar
There's no reference to RA4 in that code. Perhaps you forgot to compile and update the chip?
Jul 17, 2010, 11:00 PM
Xtreme web coder, and PIC guy!
AZInventor1's Avatar
Thank you again!

I had to delete and re type the "flash.c" file code, because it kept on going back to the original code. Now the right LED is flashing!

Inventor1
AZ


Quick Reply
Message:

Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Marine absorbs IED blast, walks away MtnGoat Life, The Universe, and Politics 13 Jul 08, 2010 12:30 PM
Discussion MPLAB how convert C to HEX micro17 DIY Electronics 2 Feb 15, 2010 02:34 PM
Question HBFPv2 Linkage question w/pic normal or not? demisemiquaver Beginner Training Area (Heli-Electric) 2 Oct 13, 2009 12:43 PM
Discussion PIC Interrupt Question AndyOne DIY Electronics 18 Sep 01, 2009 04:50 PM
IED containing Sarin in Iraq MattLarson29 Life, The Universe, and Politics 99 May 21, 2004 03:17 AM