Author Topic: Carnt get pins to change? HELP!!  (Read 2416 times)

Offline Layman

  • Chief squatting Hard
  • *
  • Posts: 18
  • Post quality +1/-0
  • Gender: Male
  • Acidmods User
Carnt get pins to change? HELP!!
« on: November 25, 2012, 05:04:46 AM »
hi guys i need some help/advise i carnt seem to get anything working on my program, my program is to turn an led on then turn it off after a set period of time, in this case about 1 second but unfortunately i carnt seem to make my pin go low or set to input, can any one help is it me or what am i doing something wrong?? ive tried looking at other codes that work but no help, any one got any ideas????

this is my code:
Code: [Select]
Mainloop
bsf STATUS, RP0 ;select bank 1
bcf TRISIO, led
bcf STATUS, RP0 ;select bank 0
clrf Datareg1
movlw 0x64
movwf Datareg1
bsf GPIO, led
loop1
pause1
call Delay
decfsz Datareg1
goto pause1
clrf Datareg1
movlw 0x64
movwf Datareg1
bcf GPIO, led
pause2
call Delay
decfsz Datareg1
goto pause2
clrf Datareg1
movlw 0x64
movwf Datareg1
bsf GPIO, led
goto loop1

Offline SethMods

  • Registered BST
  • King of the Wii-tards
  • *
  • Posts: 189
  • Post quality +17/-1
  • Gender: Male
  • Acidmods User
Re: Carnt get pins to change? HELP!!
« Reply #1 on: November 25, 2012, 09:45:22 PM »
Ok, so a few things that I noticed.

First of all, where is "Delay" defined? I think you can probably omit those two lines as you seem to be creating the delay yourself?

And more importantly I do NOT think you are delaying long enough. Currently you are delaying ~300 instructions for turning the LED off and then ~300 instructions for turning the LED on.

If you are using a 12f683 then the default oscillator frequency is 4Mhz. Divide that by 4 and you get the number of instructions that are executed a second. (1,000,000).

So the LED would be turning on for 300/1,000,000 (or .3 Milliseconds) and then turning off for .3 Milliseconds. To the naked eye the LED would just look like it was On all the time. (...probably just a little bit dim.)

So really instead of counting to 0x64 (100) you need to be counting to a million. (...unless you have changed the oscillator frequency.)

Tangent: When did Gooligum start charging for their tutorials? I was going to point you to some of their code. It's quite excellent.

Because you are limited to 8 bit variables in Assembly, you will have to use two or maybe three to accomplish what you want. And you will want to nest them.

It roughly looks something like this.

;Set initial values
        movlw .100
        movwf data1
        movlw .100
        movwf data2
        movlw .33
        movwf data3
delay1
        decfsz data1
        goto delay1
        ;Reset data1
        movlw .100
        movwf data1
delay2
        decfsz data2
        goto delay1
        ;Reset data2
        movlw .100
        movwf data2
delay3
        decfsz data3
        goto delay1
 
This should give you a little over a second. You can tweak the numbers to get a little closer.

Alternatively you can add a bunch of NOP's to avoid using a 3rd delay loop.


What I recommend though is to write a subroutine that will take the W register and delay that many milliseconds. That's what I do. I use one of the on-board timers to do that though. It takes more effort, but it's something that you can build once and keep using for years.

I hope this helps.

I know there are a couple other guys on here that will probably want to chime in as well.

Good luck!

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal