I cannot get any code for my PIC18F2331 to compile. I get a "missing bit in SET command" and I have installed the updates. Its says the problem is in system.h lines 113-116, and if I comment then out, it will compile but the HEX will not download to the PIC. I have to open the ASM in MPLAB and compile it there to download, but the program still doesn't work. Is there some other step required for the PIC18F processors?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have got a 18f4620 that works/behaves rather well with GCBasic in its present form. There will be some gotcha's tho when some of the code doesn't handle more particular 18f registers. If you are going to use the A2D module, there will be further problems, as the same sort of changes need to be implemented there also.
So just to get you up and running, a change is required to the system.h file in the include/lowlevel folder, and the GC_Subs file in the Source folder.
Replace this block of code in the system.h file. Sorry no tabs will come thru on post. It looks like ANS0, and ANS1 get set twice, but didn't want to disturb the code. The error was coming from GCBasic trying to set the PCFG3:0 bits which the 18f2331 series doesn't have.
#IFDEF NoVar(ANSEL)
#IFDEF NoBit(PCFG4)
#IFDEF NoVar(ADCON2)
#IFDEF NoBit(ANS0)
#IFDEF Bit(PCFG3)
SET PCFG3 OFF
#ENDIF
SET PCFG2 ON
SET PCFG1 ON
SET PCFG0 OFF
#ENDIF
#IFDEF Bit(ANS0)
SET ANS0 OFF
SET ANS1 OFF
#ENDIF
#ENDIF
#IFDEF Var(ADCON2)
#IFDEF Bit(ANS4)
#IFDEF BIT(ANS8)
SET ANS8 OFF
SET ANS7 OFF
SET ANS6 OFF
SET ANS5 OFF
#ENDIF
Set ANS4 OFF
Set ANS3 OFF
Set ANS2 OFF
Set ANS1 OFF
Set ANS0 oFF
#ENDIF
#IFDEF BIT(PCFG3)
SET PCFG3 ON
SET PCFG2 ON
SET PCFG1 ON
SET PCFG0 ON
#ENDIF
#ENDIF
#ENDIF
Next is a line in the GC_Subs file. Be sure to set WDTEN=Off in the config line, as no default has been set yet.
'Check to see if WDT and LVP need to be configured
WDT% = 0: LVP% = 0
FOR PD% = 1 TO COC%
IF INSTR(ConfigOp$(PD%), "WDT_") <> 0 THEN WDT% = 1
IF INSTR(ConfigOp$(PD%), "WDTEN_") <> 0 THEN WDT% = 1
IF INSTR(ConfigOp$(PD%), "LVP_") <> 0 THEN LVP% = 1
NEXT PD%
Hope that works for you. Looks like my 18f4431 will have a life after all.
Kent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't have a GC_Subs file in the Source folder. I did the other part with the system.h and it seems to compile but still won't load onto the pic unless I recompile the ASM to HEX in MPLAB. This is my first time playing with PICs, so I might not have it wired up properly on my protoboard. I am using an Enhanced JDM serial programmer with the PIC18F2331.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there an assembler error that you get, or can you tell? I am using the Crimson editor, and it will show that GCBasic compiles and whether the assembler is successful or fails. My tool chain is Pickit 2->GCBasic->MPASM(specified at install).
Trust me there is a GC_Subs file in the source folder, it shows up as a .bas file that is read by Notepad. Unless you change the GC_Subs.bas file you are likely not setting the configuration word correctly. The MPASM may give you the appearance that your pic is programmed, but its not, or at least not correctly.
By the way the GC default setting should read:
IF INSTR(ConfigOp$(PD%), "WDTEN_") <> 0 THEN WDTEN_% = 1
Hang in there, GCBasic is fun once you get rolling. The 18f2331 is pretty advanced in a lot of ways, and there are more tripping points compared with the 16f's. The 16f's are perhaps more time tested, and therefore less bugs. When you write a bunch of code, or want more advanced features, then the 18f's are the only way to go.
Kent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This patch incorporates what Kent has suggested above. I was able to compile a LED blinking program with it, so it should behave.
There was a file called GCB_Subs.bas, but I got rid of it a while back. The code in gcbasic is now distributed between gcbasic.bas, assembly.bi, preprocessor.bi, utils.bi and variables.bi. Also, no more % or $ symbols used in the code any more, the latest version of FreeBASIC doesn't allow them.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the basic blink led code. It compiles and works with the 18f4431 definition. If it doesn't work for you, then perhaps you have a hardware or programmer problem. I have heard that some type of programmers will not work correctly from a laptop USB port, because the programming voltage is derived directly from the port.
Kent
'Chip model
#chip 18f2331,20
#config WDTEN=Off
#define Led PortA.0
dir PortA.0 out
Main:
Set Led On
wait 1 s
Set Led Off
wait 1 s
Goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That would be great. I haven't been able to try the programmer on another computer yet as finding serial ports is a real pain these days. I am using a Dell Latitude X300 and the serial port is on the docking bay, so that may be some problem, but it seems to be able to read/erase the PIC, identify it and program MPLAB files.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to get to the bottom of this, so sorry if you have answered these questions already, but some I know, some have not.
Have you got the led program working? Does it, or does it not work when asm compiled in MPLAB? Even my Pickit 2 will look to program a chip with the wrong chip device file, but it at least will warn me that the device is not what is expected or a match. Is the led backwards? Check the output pin with a DVM.
The up-dated a-d.h file will be of no use unless you have success getting your chip programmed first.
For sure, your programmer supports the 18f2331? Is there a data sheet, web page or forum for your programmer?, maybe some help or tips there.
What assembler are you using GCASM or MPASM? If GCASM, then possibly it is not handling the configuration word(s) correctly, try MPASM. You can edit the path for the compile.bat file? or reinstall GCBasic and tic the MPASM option (you would have to re-update with the zip file per Hugh's instructions).
Other ideas:
Is the breadboarded Pic configured properly, with the MCLR pin having a 10k pullup?
Have you got another pic to try besides the 18f2331? Does it work with GCBasic and your programmer setup? Popular alt chips, with lots of programming examples, 12f675, 16f88, 16f877a.
If your programmer is continuing source of irritation, then I highly recommend the Microchip Pickit 2 programmer. Its usb, small form factor, programs pretty much all pics, increasing MPLAB support, $35USD.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will reinstall MPLAB and GCBASIC tonight and setup everything to use MPASM.
The PIC is compatible with the programmer, and the LED program did not work, but I did not have a 10K pullup resistor on MCLR. And by pullup, I am assuming that it connects to the +5v.
The programmer does erase the PIC and recognizes it as the PIC18F2331 and also recognizes my other two PICs but they are all 18F series.
I will reinstall everything and try again and post what happens with the LED program.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot get any code for my PIC18F2331 to compile. I get a "missing bit in SET command" and I have installed the updates. Its says the problem is in system.h lines 113-116, and if I comment then out, it will compile but the HEX will not download to the PIC. I have to open the ASM in MPLAB and compile it there to download, but the program still doesn't work. Is there some other step required for the PIC18F processors?
Have got a 18f4620 that works/behaves rather well with GCBasic in its present form. There will be some gotcha's tho when some of the code doesn't handle more particular 18f registers. If you are going to use the A2D module, there will be further problems, as the same sort of changes need to be implemented there also.
So just to get you up and running, a change is required to the system.h file in the include/lowlevel folder, and the GC_Subs file in the Source folder.
Replace this block of code in the system.h file. Sorry no tabs will come thru on post. It looks like ANS0, and ANS1 get set twice, but didn't want to disturb the code. The error was coming from GCBasic trying to set the PCFG3:0 bits which the 18f2331 series doesn't have.
#IFDEF NoVar(ANSEL)
#IFDEF NoBit(PCFG4)
#IFDEF NoVar(ADCON2)
#IFDEF NoBit(ANS0)
#IFDEF Bit(PCFG3)
SET PCFG3 OFF
#ENDIF
SET PCFG2 ON
SET PCFG1 ON
SET PCFG0 OFF
#ENDIF
#IFDEF Bit(ANS0)
SET ANS0 OFF
SET ANS1 OFF
#ENDIF
#ENDIF
#IFDEF Var(ADCON2)
#IFDEF Bit(ANS4)
#IFDEF BIT(ANS8)
SET ANS8 OFF
SET ANS7 OFF
SET ANS6 OFF
SET ANS5 OFF
#ENDIF
Set ANS4 OFF
Set ANS3 OFF
Set ANS2 OFF
Set ANS1 OFF
Set ANS0 oFF
#ENDIF
#IFDEF BIT(PCFG3)
SET PCFG3 ON
SET PCFG2 ON
SET PCFG1 ON
SET PCFG0 ON
#ENDIF
#ENDIF
#ENDIF
Next is a line in the GC_Subs file. Be sure to set WDTEN=Off in the config line, as no default has been set yet.
'Check to see if WDT and LVP need to be configured
WDT% = 0: LVP% = 0
FOR PD% = 1 TO COC%
IF INSTR(ConfigOp$(PD%), "WDT_") <> 0 THEN WDT% = 1
IF INSTR(ConfigOp$(PD%), "WDTEN_") <> 0 THEN WDT% = 1
IF INSTR(ConfigOp$(PD%), "LVP_") <> 0 THEN LVP% = 1
NEXT PD%
Hope that works for you. Looks like my 18f4431 will have a life after all.
Kent
I don't have a GC_Subs file in the Source folder. I did the other part with the system.h and it seems to compile but still won't load onto the pic unless I recompile the ASM to HEX in MPLAB. This is my first time playing with PICs, so I might not have it wired up properly on my protoboard. I am using an Enhanced JDM serial programmer with the PIC18F2331.
Is there an assembler error that you get, or can you tell? I am using the Crimson editor, and it will show that GCBasic compiles and whether the assembler is successful or fails. My tool chain is Pickit 2->GCBasic->MPASM(specified at install).
Trust me there is a GC_Subs file in the source folder, it shows up as a .bas file that is read by Notepad. Unless you change the GC_Subs.bas file you are likely not setting the configuration word correctly. The MPASM may give you the appearance that your pic is programmed, but its not, or at least not correctly.
By the way the GC default setting should read:
IF INSTR(ConfigOp$(PD%), "WDTEN_") <> 0 THEN WDTEN_% = 1
Hang in there, GCBasic is fun once you get rolling. The 18f2331 is pretty advanced in a lot of ways, and there are more tripping points compared with the 16f's. The 16f's are perhaps more time tested, and therefore less bugs. When you write a bunch of code, or want more advanced features, then the 18f's are the only way to go.
Kent
Should be all fixed, download
http://gcbasic.sourceforge.net/newfiles/gcbasic.zip. Extract the .h files to
the include/lowlevel folder, and the rest to the GCBASIC install directory.
This patch incorporates what Kent has suggested above. I was able to compile a LED blinking program with it, so it should behave.
There was a file called GCB_Subs.bas, but I got rid of it a while back. The code in gcbasic is now distributed between gcbasic.bas, assembly.bi, preprocessor.bi, utils.bi and variables.bi. Also, no more % or $ symbols used in the code any more, the latest version of FreeBASIC doesn't allow them.
Download link is slightly incorrect - it has a stray period at the end. "."
http://gcbasic.sourceforge.net/newfiles/gcbasic.zip. <<<<<<<<<
Now the program compiles without errors, but the HEX gives me the following errors when I download it:
Erasing Device ...
Erasing finished!
Programming started ...
Verify Error: Code Mem 0x000000: PIC=0x00FF Buf=0x004F
Verify Error: Code Mem 0x000001: PIC=0x00FF Buf=0x00EC
Verify Error: Code Mem 0x000002: PIC=0x00FF Buf=0x0000
Verify Error: Code Mem 0x000003: PIC=0x00FF Buf=0x00F0
Verify Error: Code Mem 0x000004: PIC=0x00FF Buf=0x0016
Verify Error: Too much errors in Code Mem, giving up!
Verify Error: Cfg Mem 0x000001: PIC=0x00CF Buf=0x00C2
Verify Error: Cfg Mem 0x000003: PIC=0x003F Buf=0x003E
Verify Error: Cfg Mem 0x000005: PIC=0x009D Buf=0x001D
Verify Error: Cfg Mem 0x000006: PIC=0x0085 Buf=0x0081
Programming finished with verify errors!
BTW I am using PICPgm Programmer to download the file.
Here is the basic blink led code. It compiles and works with the 18f4431 definition. If it doesn't work for you, then perhaps you have a hardware or programmer problem. I have heard that some type of programmers will not work correctly from a laptop USB port, because the programming voltage is derived directly from the port.
Kent
'Chip model
#chip 18f2331,20
#config WDTEN=Off
#define Led PortA.0
dir PortA.0 out
Main:
Set Led On
wait 1 s
Set Led Off
wait 1 s
Goto Main
I was thinking it could be hardware, and I will try it on another computer. The weird thing is it will download any hex file compiled in MPLAB. I tried using another programmer and I got this as errors:
Programming...
Erasing ("bulk" or "chip") ...
EraseAll: missing bulk erase algorithm !
Erasing FAILED !
Programming CODE, 0x000000..0x0000B6
Verifying CODE, 0x000000..0x0000B6
Verifying 0x000000..0x0000B6
Verify Error: 000000: read 00FFFF, wanted 00EC4F, mask 00FFFF ==> diff=0013B0
Verify Error: 000002: read 00FFFF, wanted 00F000, mask 00FFFF ==> diff=000FFF
Verify Error: 000004: read 00FFFF, wanted 00EF16, mask 00FFFF ==> diff=0010E9
Verify Error: 000006: read 00FFFF, wanted 00F000, mask 00FFFF ==> diff=000FFF
More Verify Errors, unable to list all (total=92)
Programming CONFIG, 0x300000..0x300012
Verifying CONFIG, 0x300000..0x300012
Verifying 0x300000..0x300012
Verify Error: 300000: read 00CF00, wanted 00C2FF, mask 00FFFF ==> diff=000DFF
Verify Error: 300002: read 003F0F, wanted 003E0F, mask 00FFFF ==> diff=000100
Verify Error: 300004: read 009D3C, wanted 001D3C, mask 00FFFF ==> diff=008000
Verify Error: 300006: read 000085, wanted 00FF81, mask 00FFFF ==> diff=00FF04
ERROR: Programming FAILED !
Got the a-d.h modified for the 18fXX31 series. Update should be available soon.
Kent
That would be great. I haven't been able to try the programmer on another computer yet as finding serial ports is a real pain these days. I am using a Dell Latitude X300 and the serial port is on the docking bay, so that may be some problem, but it seems to be able to read/erase the PIC, identify it and program MPLAB files.
Is the update available yet? I have checked all my hardware and it seems OK.
Trying to get to the bottom of this, so sorry if you have answered these questions already, but some I know, some have not.
Have you got the led program working? Does it, or does it not work when asm compiled in MPLAB? Even my Pickit 2 will look to program a chip with the wrong chip device file, but it at least will warn me that the device is not what is expected or a match. Is the led backwards? Check the output pin with a DVM.
The up-dated a-d.h file will be of no use unless you have success getting your chip programmed first.
For sure, your programmer supports the 18f2331? Is there a data sheet, web page or forum for your programmer?, maybe some help or tips there.
What assembler are you using GCASM or MPASM? If GCASM, then possibly it is not handling the configuration word(s) correctly, try MPASM. You can edit the path for the compile.bat file? or reinstall GCBasic and tic the MPASM option (you would have to re-update with the zip file per Hugh's instructions).
Other ideas:
Is the breadboarded Pic configured properly, with the MCLR pin having a 10k pullup?
Have you got another pic to try besides the 18f2331? Does it work with GCBasic and your programmer setup? Popular alt chips, with lots of programming examples, 12f675, 16f88, 16f877a.
If your programmer is continuing source of irritation, then I highly recommend the Microchip Pickit 2 programmer. Its usb, small form factor, programs pretty much all pics, increasing MPLAB support, $35USD.
I will reinstall MPLAB and GCBASIC tonight and setup everything to use MPASM.
The PIC is compatible with the programmer, and the LED program did not work, but I did not have a 10K pullup resistor on MCLR. And by pullup, I am assuming that it connects to the +5v.
The programmer does erase the PIC and recognizes it as the PIC18F2331 and also recognizes my other two PICs but they are all 18F series.
I will reinstall everything and try again and post what happens with the LED program.