Here's the code from the Inchworm quick start guide coming really soon.
Although this ones written for the Fireflys 16F88, the quick start will show code and schematics for the 12F509, 16F84A and 16F628A
It's designed simply to be your first "hello world" style program. The Firefly User Guide will describe how the very simple program works.
Wow, sounds great, can't wait to see this guide.
Would this code adapt directly to the 16F628A, given the first 2 lines of code are changed?
If so, I'll try that as soon as I get my serial cable. I found some IDC connectors and I'm pretty confident I've got everything else setup to get this chip programmed.
Here's the 16F628A version. An LED and 220ohm resistor on RA.0 should flash every 1.2sec
Hey the beauty of a WDT reset program is in theory it will never crash (cause it crashes all the time)
Code:
;*** WDT reset toggles RA.0
list p=16F628A
include <p16F628A.inc>
__CONFIG 0x3F34
org 0
bsf STATUS, RP0
movlw b'00001110'
movwf OPTION_REG
movlw 7
movwf CMCON
movlw b'11111110'
movwf TRISA
bcf STATUS, RP0
movlw 1
xorwf PORTA, f
sleep
end
Depends on the part - on old PIC's it was, and you had to check if it was a reset or a wakeup - but some modern PIC's simply continue on from where the sleep instruction was.
Yes, that's why you have a goto to jump past it, 0x0005 would obviously be the minimum, and it would move higher if an ISR was used - it's probably a good idea to have an RETFIE at 0x0004 just in case an interrupt should happen to occur?.
If you want to make it even shorter, you can get rid of the write to CMCON as the POR value is 7 on the 16f88. If you change it to flash LED 2 you can also get rid of the clr ANSEL.
Interrupts don't just happen and if a stray interrupt occurred then it would keep executing the retfie because the offending interrupt bit isn't cleared. Do you also put 2 returns at the end of subroutines just in case it misses the first?
If you want to make it even shorter, you can get rid of the write to CMCON as the POR value is 7 on the 16f88. If you change it to flash LED 2 you can also get rid of the clr ANSEL.
Interrupts don't just happen and if a stray interrupt occurred then it would keep executing the retfie because the offending interrupt bit isn't cleared. Do you also put 2 returns at the end of subroutines just in case it misses the first?
No, but by accidentally setting a bit wrong in a register you could inadvertently cause an interrupt - as already shown in a post elsewhere in this forum - an RETFIE would help prevent disaster!.
I thought the idea was to generate a general purpose header?, to base further programming on - it makes good sense to have an RETFIE and a jump past the interrupt vector.
No, but by accidentally setting a bit wrong in a register you could inadvertently cause an interrupt - as already shown in a post elsewhere in this forum - an RETFIE would help prevent disaster!.
Not really as the unserviced interrupt will cause the the retfie to be called for ever more and therefore result in a crash anyway.
I thought the idea was to generate a general purpose header?, to base further programming on - it makes good sense to have an RETFIE and a jump past the interrupt vector.
I thought this was a check it's working type program. For a general template I use the ones supplied by Microchip such as you find in C:\Program Files\Microchip\MPASM Suite\Template\Code\f88temp.asm
This is not the master header version, it's the lazy typer program for the impatient first time PIC programmer to see that silly little LED blink. Not even good programming practice, just quick and dirty. It's only 15 bytes long... Heck the 12F509 / 16F84 version is even smaller.
This is not the master header version, it's the lazy typer program for the impatient first time PIC programmer to see that silly little LED blink. Not even good programming practice, just quick and dirty. It's only 15 bytes long... Heck the 12F509 / 16F84 version is even smaller.
If you're giving a simple minimum program as an example, you may as well make it right! - rather than start people on bad practices. What's the difference between 15 bytes and 20 bytes when you're not even having to type them in?.
I tried the flash a LED code for the 16F628A. When I "Release from Reset" the PIC, RA.0 is turned high and thus it lights up my LED.. but it never turns off, it just stays high all the time.
Are you sure the code is correct?
Also, do I have to set some configuration bits to some values in MPLAB in order to have it work or leaving it to defaults should be ok?
By the way.. there doesn't appear to be any loop control in the code.. do the program simply ends after the sleep instruction, and then, on a PIC, when the program has ended.. it just starts again from the beginning?
And the "sleep" command make it sleep for about 1.2 seconds and the xorwf instruction inverts the status of RB0?
By the way.. there doesn't appear to be any loop control in the code.. do the program simply ends after the sleep instruction, and then, on a PIC, when the program has ended.. it just starts again from the beginning?
And the "sleep" command make it sleep for about 1.2 seconds and the xorwf instruction inverts the status of RB0?
That's right, it uses the WDT timer and prescaler. The speed is determined by the value used in the OPTION_REG (look at the data sheet, you can go as long as 2.5sec or much shorter)
The program doesn't care how fast the clock is, 32KHz or 4MHz still runs the same. The sleep command just stops the program till an event occurs.
PS a neat trick (it's in one of the Microchip app notes) is the WDT timer is temperature sensitive. You can make a simple thermometer with it...