![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Experienced Member
|
I'm using the 18F1320 that comes with the Junebug kit in a breadboard arrangement with Hitachi HD44780 LCD controller and programming it with Swordfish SE.
The Swordfish code is as follow... (From one of the forums) Code:
Device = 18F1320
Clock = 8
// some LCD options...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.3
#option LCD_EN = PORTB.2
// import LCD library...
Include "LCD.bas"
Include "convert.bas"
Dim Variable As Word
// Start Of Program...
'Enable MCLR on Pin 4 (RA5)
Config MCLRE = ON
Config osc = INTIO2 // I had to add this to get the
OSCCON = $76 // one second timer to work correctly
DelayMS(150) // Let the LCD warm up
LCD.Cls // Clear the LCD screen
LCD.WriteAt(1,1,"Hello World") // Send some text to the LCD
Variable = 0 // Clear the "Variable" register
While True
Inc(Variable) // Decrement the "Var1" register
// Convert to a string,
// and always display 5 characters
LCD.WriteAt(2,1,Convert.DecToStr(Variable,5))
DelayMS(1000) // Delay for 1 second
Wend
Is it a 18F1320 problem or the way that Swordfish makes the HEX file? |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
You also should turn off the watchdog timer, I'm not sure if Swordfish takes care of this automatically but best to turn it off unless you're using it.
Code:
'Enable MCLR on Pin 4 (RA5) // Config MCLRE = ON Unnessary Config OSC=INTIO2, LVP=OFF, WDT=OFF // I had to add this to get the OSCCON = $72 // one second timer to work correctly |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Bill, it makes no difference. It still takes 33-35 seconds from reload or power recycle to start operating. Once it goes it seems to work 100% fine, (well, as accurate as an RC clock can be?)
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Also Swordfish can use the PK2CMD.EXE command line to program with the Junebug. Make sure you have the /R option to allow the device to come out of reset (RUN) automatically after programming.
Code:
/PPIC$target-device$ /F$long-hex-filename$ /M /R /H2 |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Are you running Windows?
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Bill helped me to get the Swordfish to program directly via the PICKit command line, but the 33s reset still persists. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
hi,
After pressing the RESET button, during the long delay period [33s] measure the voltage on pin 4 of the 18F1320, MCLR pin. Lets know what you measure Regards
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
+5V Rail: 5.044V MCLR before reset pressed: 5.040V MCLR with reset pressed : 0V MCLR again after reset pressed: 5.040V When pressing the reset button, the LCD screen stays static with last displayed values and text, and then only after the aforementioned time delay does the PIC actually reset and resume from start. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
It is because the initialization code for the LCD is run at 32kHz. Open LCD.bas and at the end you will find,
Code:
// initialise the module... Initialize Alternatively, make a module called init and include it before the LCD include. Init should contain, Code:
Module init OSCCON=$70 Last edited by Pommie; 10th May 2008 at 07:49 AM. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Your using the internal oscillator, so you have to remember that your Include files will initializes first, and of course, the piece of code that sets up the internal oscillator for 8Mhz will not be executed until that occurs.
basically your PIC is running at 31Khz until it gets to your first piece of code in the main program outside of the "LCD.bas" initialisation. Solution: Create a User Module called "IntOSC_1320.bas" In the module, copy and paste this code; Code:
Module IntOSC_1320 Clock = 8 Config OSC = INTIO2 OSCCON = %11110011 Now, back in your main program remove the Clock, Config and OSCCON settings, and include "IntOSC_1320.bas" before any other includes. Now your program will service the module's code first, and in return you will have an 8Mhz internal OSC from the get go
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Stay away from the padlock lol Only use this if you know what your doing! Just saying that as you do not want to know what happened when a newbie of SF learnt that little feature a little to early from me
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net Last edited by gramo; 10th May 2008 at 09:45 AM. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Gramo,
I suppose that's why they pay you the BIG BUCKS hey? Super solution! Works like a charm. Thank you very much sir! |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Mike. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Sorry Pommie.
When I open the forum I usually go to the last post first. Saves me time scanning (paging down through it all again). I did notice your post, but with gramo's warning for NOOBS not to play with library code, I'd thought it best to heed the warning. I'm now "playing" with the DS1820 1-wire temperature sensor chip, modifying the example code for the 18F1320, and not USART but LCD. So far I'm not having any luck. I don't read anything from the sensor. But, I'll first fiddle around as much as I can before posting another thread on that topic. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Is it an 18S20 or 18B20
There are libraries for both as part of Swordfish |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Brown-out reset on LF PIC | bananasiong | Micro Controllers | 10 | 17th May 2007 12:33 AM |
| 74LS90 power-on auto reset | Torben | Electronic Projects Design/Ideas/Reviews | 17 | 20th December 2006 04:18 AM |
| vx-5r reset problem | tom muleady | General Electronics Chat | 2 | 5th July 2006 06:01 PM |
| uC 'network' reset circuitry | rockin_rick | Electronic Projects Design/Ideas/Reviews | 8 | 30th May 2006 01:03 AM |
| How to reset SCR used for triggering camera flash | shootfirst | Electronic Projects Design/Ideas/Reviews | 20 | 28th September 2005 08:40 PM |