Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

12F675 : Flashing LED a bit wonky (PICKit 1)

Status
Not open for further replies.

Cagao

New Member
Hi,

I recently got hold of the PICKit 1 from Microchip. Looked at the 'lessons' and learnt nothing (!) :mad: , so searched and searched for some REALLY basic asm code on t'internet.

I've managed to get one LED flashing on the demo board, but it seems a little eratic at times, between 2s-10s it looks like it's resetting (the flash rate increases for one cycle).

I'll include the code I've got in a min, but first one question....

what's the difference between 'list p=12F675' and '#include <p12f675.inc>'. I'm guessing the latter is just to give you some of the extra pre-defined 'equ' statements to use in your code? but what EXACTLY does the 'list' command do? Is it used to create the HEX code? or included, and dealt with inside the 'programmer'?

thanks for any guidence in advance, this is all new territory for me, i'm more a C/Perl developer.

well, here's my code so far...


list p=12F675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

;*****Set up the Constants****

COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops

;****Set up the port****
clrf GPIO
movlw 0x7
movwf CMCON ; disable comparator
bsf STATUS, RP0
movlw B'00001111'
movwf TRISIO ; All pins outputs
bcf STATUS, RP0

;****Turn the LED on****

Start
movlw b'00100000' ;Turn the LED on by first putting
movwf GPIO ;it into the w register and then

;****Start of the delay loop 1****

call Delay

;****Delay finished, now turn the LED off****

movlw b'00000000' ;Turn the LED off by first putting
movwf GPIO ;it into the w register and then on

;****Add another delay****

call Delay

;****Now go back to the start of the program

goto Start ;go back to Start and turn LED

Delay

Loop1

decfsz COUNT1,1 ;This second loop keeps the LED
goto Loop1 ;turned off long enough for us to
decfsz COUNT2,1 ;see it turned off
goto Loop1 ;

return

;****End of the program****

end
 
hi,
in your config word you have the watchdog timer enabled, this will cause the pic to reset unless you sprinkle some CLRWDT instructions throughout your code, try turning it off ( _WDT_OFF ).

the " list " directive tells the assembler which proccessor you are using.

stig.
 
with that removed, it's still doing the same.

I thought I was getting somewhere but this really is puzzling me.

a bit of an explanation of what that config setting does would be nice too.
 
ignore me, i guess it's ON by default, i just removed that bit, instead of explitely setting it to OFF.

thanks!
 
Clear the ANSEL register in bank1: CLRF ANSEL
You're not setting all the pins as outputs with the TRISIO register... no problem if the LED is connected to GPIO5, though.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top