Searching \ for '[PIC:] Driving 2 LEDs using PIC 12F675' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/displays.htm?key=leds
Search entire site for: 'Driving 2 LEDs using PIC 12F675'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] Driving 2 LEDs using PIC 12F675'
2004\06\23@215957 by Emrah Bozkurt

picon face
Hello all,

I have been struggling with a very simple (yet
impossible) project in which I will drive 2 LEDs using
2 switches and a PIC 12F675.
I could not manage to make the PIC work on the
breadboard for almost 2 weeks (day and night!)..I am
using IC-Prog for downloading the hex into PIC.
Please help me on the possible errors that exist on my
code. (Maybe the error is on the hardware. If anyone
accepts, I can immediately send the circuit schematic
via email)
My code is below:

;=========== INITIALIZATIONS =========================

           LIST       P=12F675
           INCLUDE    "P12F675"
TRISIO      EQU        85h     ; TRISIO REGISTRY IS
                              ; INTRODUCED.
GPIO        EQU        05h     ; I/O PORTS ARE
                              ; INTRODUCED.
STATUS      EQU        03h     ; STATUS REGISTRY IS
                              ; INTRODUCED.
CMCON       EQU        19h     ; COMPARATOR CONTROL
                              ; REGISTRY IS
                              ;INTRODUCED.
ANSEL       EQU        9Fh     ; ANALOG SELECT
                              ; REGISTRY IS
                              ; INTRODUCED.
OPTION_REG  EQU        81h     ; OPTION REGISTER IS
                              ; INTRODUCED.
TMR0        EQU        01h     ; TIMER REGISTER IS
                              ; INTRODUCED.
PIR1_COUNT  EQU        0Ch     ; COUNTER REGISTER IS
                              ; INTRODUCED.
OSCCAL      EQU        90h     ; OSCCAL REGISTRY IS
                              ; INTRODUCED.
CONFIG      EQU      2007h     ; CONFIG IS
                              ; INTRODUCED. (DURING
                              ; TRIAL, I ALSO
                              ; COMMENTED
                              ; OUT THIS LINE AND
                              ; CONFIGURED THE
                              ; CONFIG WORD DIRECTLY
                              ; FROM
                              ; IC-PROG'S FUSES MENU)

;=====SET INTERNAL OSCILLATOR, DISABLE COMPARATORS
;=====AND A/D CONVERTERS ===========

           BCF     CONFIG, 5  ; GP3 BECAME INPUT AND
                              ; MCLR IS CONNECTED TO
                              ; Vdd INTERNALLY.
                              ;(DURING TRIAL, I ALSO
                              ; COMMENTED OUT THIS
                              ; LINE AND CONFIGURE
                              ; THE CONFIG WORD
                              ; DIRECTLY FROM
                              ; IC-PROG'S FUSES MENU)
           BCF    CONFIG, 3   ; WDT DISABLED.(DURING
                              ; TRIAL, I ALSO
                              ; COMMENTED OUT THIS
                              ; LINE AND CONFIGURE
                              ; THE CONFIG WORD
                              ; DIRECTLY FROM
                              ; IC-PROG'S FUSES MENU)

           BSF    STATUS, RP0 ; JUMP TO BANK 1.
           CALL   3FFh        ; GET THE CALIBRATION
                              ; VALUE.
           MOVWF  OSCCAL      ; CALIBRATE.

           BCF    STATUS, 5   ; JUMP TO BANK 0.
           CLRF   GPIO        ; INITIALIZE GPIO.
           MOVLW  07h         ; SET COMPARATOR PINS
                              ; AS DIGITAL I/O PINS
           MOVWF  CMCON       ; (Set comparators as
                              ; OFF)
           BSF    STATUS, 5   ; JUMP TO BANK 1.
           CLRF   ANSEL       ; SET A/D PINS AS
                              ; DIGITAL I/O PINS
                              ; (Disable A/D
                              ; Converters).


;==== DEFINE INPUT AND OUTPUT PINS====================

           MOVLW  0Ch         ; SET GP<3:2> AS
                              ; INPUTS.
           MOVWF  TRISIO      ; AND SET GP<5:4,1:0>
                                AS OUTPUTS.
           BCF    STATUS, 5   ; JUMP TO BANK 0.


;=========== MAIN PROGRAM =====================

CHECK_SW1

           BTFSC  GPIO, 3    ; IS SW1 BUTTON PUSHED ?
           GOTO   LED1_OFF   ; IF NOT, GO TO
                             ; LED1_OFF.
           CALL   LED1_ON    ; IF YES, CALL LED1_ON
                             ; SUBPROGRAM.
           GOTO   CHECK_SW1  ; CHECK SW1 BUTTON
                             ; AGAIN.

CHECK_SW2

           BTFSC  GPIO, 2    ; IS SW2 BUTTON PUSHED ?
           GOTO   LED2_OFF   ; IF NOT, GO TO
                             ; LED2_OFF.
           CALL   LED2_ON    ; IF YES, CALL LED2_ON
                             ; SUBPROGRAM.
           GOTO   CHECK_SW2  ; CHECK SW2 BUTTON
                             ; AGAIN.


LED1_OFF
           BCF    GPIO, 4    ; MAKE LED1 OFF.
           GOTO   CHECK_SW2  ; CHECK SW2
                             ; BUTTON.

LED1_ON
           BSF    GPIO, 4    ; MAKE LED1 ON.
           RETURN

LED2_OFF
           BCF    GPIO, 1    ; MAKE LED2 ON.
           GOTO   CHECK_SW1  ; CHECK SW1
                             ; BUTTON.

LED2_ON
           BSF    GPIO, 1    ; MAKE LED2 ON.
           RETURN

           END               ; END OF PROGRAM.


Thanks a lot in advance. Please reply (cc) to:
spam_OUTemrah_bozkurtTakeThisOuTspamyahoo.com

Emrah Bozkurt


NOT: I disabled WDT, BODEN, MCLR, CP, CDP and used
Internal RC Oscillator GP4. This created 3194h for the
CONFIG WORD. I tried to do this setting on the program
and the IC-Prog's FUSES menu alone. Also I disabled
the Comparators and A/D converters to have a whole set
of digital I/Os.

The IC-Prog verifies after it downloads, but PIC never
works on the breadboard. I dont know why!
Also, IC-Prog is giving "Internal Oscillator Value is
missing! Do you want me to take the value from address
'3FFFh'?" message during the download. And I choose,
YES. Then it goes ahead sucessfully, but it still does
not work on the breadboard as I said before.





__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2004\06\23@223428 by Peter van Hoof

picon face
I think the calibration instruction on 3ff is wiped
add following instructions to end of your program
   org 3ffh
   retlw 80h
if this is missing your code will not return

Peter


{Original Message removed}

2004\06\23@223835 by Peter van Hoof

picon face
Your program does not seem to have any debounce , this might make the button
response very querky

Peter

{Original Message removed}

2004\06\24@073413 by Peter van Hoof

picon face
Forget about the debounce , thought you where toggling on button push but
you are just switching the outputs on.
Check out the retlw on top of memory though (calibration instruction) like i
stated in my other email

Peter
{Original Message removed}

2004\06\24@074905 by Emrah Bozkurt

picon face
Hello,

How can I make debunce in the code? And what is it
exactly?

And where will I exactly put
    org 3ffh
    retlw 80h
instructions in my code ? Thanks a lot.

Emrah Bozkurt

--- Peter van Hoof <pvhspamKILLspamADELPHIA.NET> wrote:
> Your program does not seem to have any debounce ,
> this might make the button
> response very querky
>
> Peter
>
> {Original Message removed}

2004\06\24@074906 by Emrah Bozkurt

picon face
Hello,

How can I make debunce in the code? And what is it
exactly?

And where will I exactly put
    org 3ffh
    retlw 80h
instructions in my code ? Thanks a lot.

Emrah Bozkurt

--- Peter van Hoof <.....pvhKILLspamspam.....ADELPHIA.NET> wrote:
> Your program does not seem to have any debounce ,
> this might make the button
> response very querky
>
> Peter
>
> {Original Message removed}

2004\06\24@075526 by Emrah Bozkurt

picon face
Hello,

I did not understand the recommendations. Sorry for
that. So, I came up with new questions.

How can I make debunce in the code? And what is it
exactly?

And where will I exactly put
    org 3ffh
    retlw 80h
instructions in my code ? Thanks a lot.

Emrah Bozkurt

--- Peter van Hoof <EraseMEpvhspam_OUTspamTakeThisOuTADELPHIA.NET> wrote:
> Your program does not seem to have any debounce ,
> this might make the button
> response very querky
>
> Peter
>
> {Original Message removed}

2004\06\24@075526 by Emrah Bozkurt

picon face
Hello,

I did not understand the recommendations. Sorry for
that. So, I came up with new questions.

How can I make debunce in the code? And what is it
exactly?

And where will I exactly put
    org 3ffh
    retlw 80h
instructions in my code ? Thanks a lot.

Emrah Bozkurt

--- Peter van Hoof <pvhspamspam_OUTADELPHIA.NET> wrote:
> Your program does not seem to have any debounce ,
> this might make the button
> response very querky
>
> Peter
>
> {Original Message removed}

2004\06\24@081641 by Peter van Hoof

picon face
If you look in section 9.2.5.1 in the datasheet of the 12f629 you see that
to calibrate the oscilator there is a instruction near the beginnig of your
program "call 3FFh" this calls a subroutine at location 3HHh in program
memory where it expects to find the factory programmed oscilator calibration
factor programmer in a retlw instruction.

The retlw instruction returns from a subroutine with the value in the w
register, example retlw 80h will return with 80h in the w register

If you have erased the pic complete at some point in time you will have lost
this factory programmed instruction. Your programmer complains about this in
the message you described.

If this retlw instruction is not there the pic will happily go about it's
business and execute whatever is in this program location and never returns
to the code you want it to execute.

The retlw 80h i suggested programming in this location is just the center
value of the calibration and if your timing is not critical this will work
just fine.

You would put the
   org 3FFh
   retlw 80h
just before the end statement in your program.

Kind regards
Peter
{Original Message removed}

2004\06\24@081848 by Peter van Hoof

picon face
replace programmer in the following by programmeD
----- Original Message -----
From: "Peter van Hoof" <@spam@pvhKILLspamspamADELPHIA.NET>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Thursday, June 24, 2004 8:16 AM
Subject: Re: [PIC:] Driving 2 LEDs using PIC 12F675


> If you look in section 9.2.5.1 in the datasheet of the 12f629 you see that
> to calibrate the oscilator there is a instruction near the beginnig of
your
> program "call 3FFh" this calls a subroutine at location 3HHh in program
> memory where it expects to find the factory programmed oscilator
calibration
> factor programmer in a retlw instruction.
>
> The retlw instruction returns from a subroutine with the value in the w
> register, example retlw 80h will return with 80h in the w register
>
> If you have erased the pic complete at some point in time you will have
lost
> this factory programmed instruction. Your programmer complains about this
in
> the message you described.
>
> If this retlw instruction is not there the pic will happily go about it's
> business and execute whatever is in this program location and never
returns
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamspamspamBeGonemitvma.mit.edu

2004\06\24@082508 by Byron A Jeff

face picon face
On Thu, Jun 24, 2004 at 04:48:34AM -0700, Emrah Bozkurt wrote:
> Hello,
>
> How can I make debunce in the code? And what is it
> exactly?

Let's talk about bounce. As must as designers would like for mechanical
switches to cleanly transition from one state to the other, due to simple
physics, it doesn't happen that way. When you switch a switch, the metal
will make contact, then separate, then make contact again, then separate
again until eventually the contacts finally settle together. This transistion
period will generate a lot of make/break transistions. So instead of a clean:


00000000001111111111111111

Where 0 is the previous state of the switch and 1 is the new state you get
instead

00000000000X1010011000110011001111111111Y11111111

The intermediate state is called bounce.

Now if your software is tracking that switch and doesn't take bounce into
account, it'll look like you pressed the switch a bunch of times when in fact
it has only been pressed (or switched) once with bounce.

The vast majority of tools to get rid of bounce, called debouncing, relies
on the fact that it is transitory and that bounce will eventually stop. The
simplest and most effect way to debounce is to simply wait after the 1st
transistion and check the switch again after it should be stable. It involves
creating a delay between first contact detection and actual checking. So
in the sample above the delay would start at point X and the switch would
be checked at point Y when it's clear that any bounce has cleared.

A second way which I use mostly, is to act upon the first transistion, but
then create a timeout where the switch won't be checked again until the timeout
has elasped. I like this way because then switch response is instanteaneous.
The problem is that this way is a bit more susceptable to noise. But a good
stiff pullup/pulldown usually will hold the input pin stable until the actual
switch is manipulated. So my code will act at point X but set a timeout
such that the switch cannot be checked again until point Y. So again the bounce
is skipped and only on transistion is seen.

Now delays and timeout can be a challenge. The naive way of handling it is
to actually delay and have the PIC do nothing else. However a slight more
sophisticated way to do it is to have a big main loop that checks everything
that you're tracking (switches, displays, sensors, etc.) run by a timer
that ticks. When a certain number of ticks elapse go through the loop and
check everything. But for the switches (and other items) if there is a timeout
in play, don't do the check and decrease the timeout. Eventually the timeout
goes to zero, and you can check again.

I used this technique in my sunrise/sunset outdoor light controller here:

http://www.finitesite.com/d3jsys/clock.asm

Check out the settick/main/dodisplay section which defines the main tick
loop attached to timer 1 (32768 Hz crystal driven with a 16 second timeout)
The loop runs every 4 ticks of the timer which ends up being very close to
1ms. When the switch transistions, switchdelay is set to 64 counts which
means that the switch won't be checked for 64 ms after a transistion.

I hope this gives you some insight into the process.

>
> And where will I exactly put
>      org 3ffh
>      retlw 80h
> instructions in my code ? Thanks a lot.

Just before the END and the END will be fine.

BAJ

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestKILLspamspammitvma.mit.edu

2004\06\26@051725 by dr. Imre Bartfai

flavicon
face
Hello,

yet another principal problem of your code is: it is not possible to set
the configuration word in runtime. It must be set in compilation time and
then programmed ("burned") into the appropriate location. Obviously your
config is not set therefore the PIC won't run. Try to set the fuses!

Regards,
Imre

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...