caramoan tour package

caramoan tour package

Author Topic: Patulong po sa code (assembly)  (Read 1569 times)

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Patulong po sa code (assembly)
« on: July 17, 2010, 02:29:30 PM »


Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

bsf STATUS,5
movlw 0x01
movwf TRISA
movlw 0x00
movwf TRISB
bcf STATUS,5
START
btfss PORTA,0
  movlw 0x0f
movwf PORTB
btfsc PORTA,0
movlw 0xf0
movwf PORTB


end

Nagablink po yung pins ng RB7 to RB5. Pano po iyan gawin na hindi na magblink yung ilaw niyan.
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Philippine Electronics Forum

Patulong po sa code (assembly)
« on: July 17, 2010, 02:29:30 PM »

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #1 on: July 17, 2010, 04:59:49 PM »
Ok na po pala hehe... here's a revision na ginawa ko:

Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

bsf STATUS,5
movlw 0x01
movwf TRISA
movlw 0x00
movwf TRISB
bcf STATUS,5
START
btfss PORTA,0
  movlw 0x0f
movwf PORTB
btfsc PORTA,0
movlw 0xf0
movwf PORTB
goto START

end

goto START lang pala... hehe...

Mga sir patulong po ulit ako paano po paglagay ng delay sa assembly on MPlab? Yung tut kasi na andito sa akin ibang compiler ang gamit pagtinatry ko yung delay nagaerror na po... Or pahingi na din po nang mga basic source codes na pwedeng pag-aralan pwede sa MPlab... TY :)
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Philippine Electronics Forum

Re: Patulong po sa code (assembly)
« Reply #1 on: July 17, 2010, 04:59:49 PM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Patulong po sa code (assembly)
« Reply #2 on: July 17, 2010, 05:24:57 PM »
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: Patulong po sa code (assembly)
« Reply #2 on: July 17, 2010, 05:24:57 PM »

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #3 on: July 17, 2010, 05:52:09 PM »
STACK UNDERFLOW DAW PO SIR simulated sa proteus.

Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

bsf STATUS,5
movlw 0x02
movwf TRISA
movlw 0x00
movwf TRISB
bcf STATUS,5
START

movlw 0xff
movwf PORTB
call delay
movlw 0x00
movwf PORTB
call delay

delay
movlw 0x85
movwf 0x08
decfsz 0x08
RETURN

end
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Philippine Electronics Forum

Re: Patulong po sa code (assembly)
« Reply #3 on: July 17, 2010, 05:52:09 PM »

Offline motion55

  • Technical People
  • Diesel Generator
  • *****
  • Posts: 1881
  • Pogi/Ganda Points: 244
  • Gender: Male
  • Been at this longer than you've been alive.
Re: Patulong po sa code (assembly)
« Reply #4 on: July 17, 2010, 07:02:18 PM »
After the second delay call, a "goto START" must be added. This will prevent the program from falling through to the delay subroutine.

Quote
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

      bsf STATUS,5
      movlw 0x02
      movwf TRISA
      movlw 0x00
      movwf TRISB
      bcf STATUS,5
START

      movlw 0xff
      movwf PORTB
      call delay
      movlw 0x00
      movwf PORTB
      call delay
     goto START
delay
      movlw 0x85
      movwf 0x08
      decfsz   0x08
      RETURN

end
"Set your mind free!"

Philippine Electronics Forum

Re: Patulong po sa code (assembly)
« Reply #4 on: July 17, 2010, 07:02:18 PM »

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #5 on: July 17, 2010, 07:31:06 PM »
Parang walang delay :D DI nagblink :D
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #6 on: July 17, 2010, 08:54:03 PM »
Pano ko po mapapatagal delay nito... halos walang delay yung ginawa ko :D
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline updated

  • Lead Acid Battery
  • *******
  • Posts: 761
  • Pogi/Ganda Points: 22
  • Gender: Female
Re: Patulong po sa code (assembly)
« Reply #7 on: July 17, 2010, 11:12:59 PM »

Code: [Select]
delay_2sec
movlw .8
movwf 0x20
call msec
decfsz 0x20,f
goto $-2
return

msec movlw .250
nmsec movwf 0x21
msecloop
movlw .248
call micro4
nop

decfsz 0x21,f
goto msecloop
return
onemsec movlw .249
micro4 addlw h'ff'
btfss status,z
goto $-2
return

2sec delay yan, 250msec delay yung msec ehh. try mo po yan sir.
"DO YOUR ORDINARY DUTIES EXTRAORDINARILY WELL."

Offline updated

  • Lead Acid Battery
  • *******
  • Posts: 761
  • Pogi/Ganda Points: 22
  • Gender: Female
Re: Patulong po sa code (assembly)
« Reply #8 on: July 17, 2010, 11:17:57 PM »
decfsz   0x08
      RETURN

end

decfsz
 if 1
 if 0

tama po ba sir?
"DO YOUR ORDINARY DUTIES EXTRAORDINARILY WELL."

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Patulong po sa code (assembly)
« Reply #9 on: July 18, 2010, 12:00:26 AM »
Code: [Select]
cblock 0x0C
delay1
delay2
endc

org 0x00
start
.
.
call delay_routine
.
.


.
.


delay_routine
loop
decfsz delay1,f
goto loop
decfsz delay2,f
goto loop
return



end

try mo nga to... ;)
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #10 on: July 18, 2010, 05:44:32 AM »
TY po :)
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #11 on: July 18, 2010, 05:48:55 AM »
Code: [Select]
cblock 0x0C
delay1
delay2
endc

org 0x00
start
.
.
call delay_routine
.
.


.
.


delay_routine
loop
decfsz delay1,f
goto loop
decfsz delay2,f
goto loop
return



end

try mo nga to... ;)

Working na po! :D Gaano po katagal ito? Pano po pag gusto ko ng specified time
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #12 on: July 18, 2010, 08:58:13 AM »
Mga pogi :D Patulong ulit... di kasi swabe yung pagswitch ng lights :D

Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON
org 0x00
  cblock 0x0C
  count1
  count2
  endc
      bsf STATUS,5
      movlw 0x03
      movwf TRISA
      movlw 0x00
      movwf TRISB
      bcf STATUS,5


START
;if RA0 is high then do running lights
  btfsc PORTA,0
  movlw 0x01
  movwf PORTB
  call delay_routine
      rlf PORTB,1
  call delay_routine
  movwf PORTB
      rlf PORTB,1
  call delay_routine
  rlf PORTB,1
  call delay_routine
  rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine
    rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine 
;if RA0 is low then light up all led
  btfss PORTA,0   
  call delay_routine
  movlw 0xff
  movwf PORTB
goto START
delay_routine
loop
decfsz count1,f
goto loop
decfsz count2,f
goto loop
return

end


Sa unang switch nung RA0 nagablink pa din yung unang led(RB0).
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Patulong po sa code (assembly)
« Reply #13 on: July 18, 2010, 11:04:29 AM »
Working na po! :D Gaano po katagal ito? Pano po pag gusto ko ng specified time

count2 and count1 are initialized to zero however when it decremented on the delay_routine function, it becomes 255 hence making the condition always false causing it to decrement further until such time it reaches 0.

The inner loop will take 256 * 3 inst cyc plus 3 inst cyc. and it will be executed for another 256. so parang

((256*3)+3)*256  = 197376 instruction cycle.

kung 4Mhz ang oscillator mo, e di may 4Mhz/4 = 1Mhz ka na instruction frequency or 1us na instruction period.
it follows that...

197367 x 1us = 0.197367s or ~197ms ang magiging delay mo.

you could play with the values of count1 and count2 variables. You could initialize it inside the delay_routine, just before the loop "label". I suggest you calculate it so that you could follow. Try it first on Proteus and verify it with the oscilloscope tool - check the delay you wanted.

I also suggest that you'd consider using the TIMER0 module since this is available with F84a.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #14 on: July 18, 2010, 11:44:55 AM »
Code: [Select]

delay_routine
loop
decfsz count1,f
goto loop
decfsz count2,f
goto loop
return


Pwede din po ba ito sa ibang pic?

Code: [Select]

((256*3)+3)*256  = 197376 instruction cycle


Paano po naging ganyan yung formula? :D
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Patulong po sa code (assembly)
« Reply #15 on: July 18, 2010, 11:46:48 AM »
oo naman.. we call it software delay.

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #16 on: July 18, 2010, 12:07:01 PM »
Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

org 0x00
cblock 0x0C
count1
count2
endc
bsf STATUS,5
movlw 0x00
movwf TRISB
bcf STATUS,5

main
movlw 0x80
movwf PORTB
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
goto main

delay_routine
 loop
    decfsz count1,0xff
   goto loop
 decfsz count2,0xff
 goto loop
return

end

yung second turn ng running lights dalawa na yung umiilaw :( Panu yun gawin isa lang?
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Patulong po sa code (assembly)
« Reply #17 on: July 18, 2010, 12:58:11 PM »
Try this... note di ko to na try

Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON


cblock 0x0C
count1
count2
endc

org 0x00

bsf STATUS,5
movlw 0x00
movwf TRISB
bcf STATUS,5
movlw 0x80
movwf PORTB

main

rrf PORTB,1
call delay_routine
goto main

delay_routine
loop
decfsz count1,0xff
goto loop
decfsz count2,0xff
goto loop
return

end
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #18 on: July 18, 2010, 01:15:56 PM »
Ty po kuya :)
God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Offline your most RIDICULOUS man :)

  • Diesel Generator
  • *
  • Posts: 1840
  • Pogi/Ganda Points: 53
  • Gender: Male
Re: Patulong po sa code (assembly)
« Reply #19 on: July 18, 2010, 01:31:54 PM »
Paano po ito? ang haba pano toh mas mapapaikli may way pa ata para mapaikli toh...

Code: [Select]
#include <p16F84A.inc>
__CONFIG _WDT_OFF & _LP_OSC & _PWRTE_ON

org 0x00
cblock 0x0C
  count1
  count2
 endc

      bsf STATUS,5
      movlw 0xff
      movwf TRISA
      movlw 0x00
      movwf TRISB
      bcf STATUS,5



main
movlw 0x00
movwf PORTB
btfss PORTA,0
goto sw1
btfss PORTA,1
goto sw2
btfss PORTA,2
  goto sw3
goto main

sw1
;if RA0 is high then do running lights rlf
  btfss PORTA,0
  movlw 0x01
      movwf PORTB
  call delay_routine
      rlf PORTB,1
  call delay_routine
  movwf PORTB
      rlf PORTB,1
  call delay_routine
  rlf PORTB,1
  call delay_routine
  rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine
    rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine
  rlf PORTB,1
      call delay_routine 
    btfsc PORTA,0
  goto main     
goto sw1
; ON OFF
sw2
btfss PORTA,1
movlw 0xff
movwf PORTB
btfsc PORTA,1
goto main
goto sw2
; running lights rrf
sw3
movlw 0x80
movwf PORTB
btfss PORTA,2
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
rrf PORTB,1
call delay_routine
btfsc PORTA,2
goto main
goto sw3

delay_routine
  loop
      decfsz count1,0xff
    goto loop
  decfsz count2,0xff
  goto loop
return

end


God give us the grace to accept with serenity the things that cannot be changed, courage to change the things which should be changed and the wisdom to distinguish the one from the other [Reinhold Niebuhr]

Philippine Electronics Forum

Re: Patulong po sa code (assembly)
« Reply #19 on: July 18, 2010, 01:31:54 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com