Author Topic: Can Any one help?  (Read 1599 times)

Offline Layman

  • Chief squatting Hard
  • *
  • Posts: 18
  • Post quality +1/-0
  • Gender: Male
  • Acidmods User
Can Any one help?
« on: January 09, 2013, 04:03:37 PM »
Hi all i am in the middle of developing a code, the thing i am trying to do is, i want to move 0x08 into data register then i want to read this data register every mili second and then every time my code cycles through the main loop i want to add 1 to that data register, so what i want to know is, is it possible to read this data register and when it goes anything above 0x0A (10) i want it do goto a certain subroutine, i was just wondering if this is possible to do on a 12f683, as i have read the data sheet and seen nothing to do with things like this, i have seen this wrote in C but not in ASM, i would also like to know how you would do if it is greater than lets say 2 and less than ten is this also possible?? if so can anyone help, i will share my code when finished

Offline SethMods

  • Registered BST
  • King of the Wii-tards
  • *
  • Posts: 189
  • Post quality +17/-1
  • Gender: Male
  • Acidmods User
Re: Can Any one help?
« Reply #1 on: January 09, 2013, 07:34:55 PM »
  movlw 0x08      ;Move 0x08 to Working Register
  movwf 0x20      ;Move W to General purpose register

loop:
  call delay1ms
  movlw 0x0B       ;Move .11 to W for subtraction in next command
  subwf 0x20,0     ;Subtract 11 from value in 0x20 and store in W

  btfsc status,2     ;Test the Z bit of STATUS register to see if the subtraction equaled Zero. Skip the next command if NOT zero.
  call subroutine

  incf 0x20, 1         ;Increment 0x20 and store in 0x20
goto loop

Note: This assumes you start out in BANK 0 and end in BANK0 after subroutines are called.


EDIT:
If you are looking for (2 < X < 10) then you will use two "bit test file register" statements...one for the ( > 2 ) and one for the ( < 10 ) part.

But let me go back. In general the btf statements (paired with the STATUS register) are going to be your standard if/else commands for Assembly. Default syntax looks something like this.

  btfs(s/c) f,b       ; 'f' is the file register, and 'b' is the bit you want to test
  goto label1      ; Do this 'else'
  goto label2      ; Do this 'if'

label1:                 ;'else'
  nop                    ;your code here
  goto label3

label2:                 ;'if' the test is true,...
  nop                    ;your code here
  goto label3

label3:                 ;break out of the if/else statement and continue


To test for ( > 2 ) you would add these two lines above the btf statement.
   movlw .3
   subwf  x, W

According to the datasheet (pg 111),...
If x < 2 , then the 'C' bit of STATUS is going to be 0.
If x >= 2, then the 'C' bit of STATUS is going to be 1.

So if you want ONLY greater than 2, then you would really want to test on the number 3. Since it will match for greater or equal to 3. (...which is > 2).

To test again on ( < 10 ) you would nest another btf statement inside of either label1 or label2 depending on whether you used btfsc or btfss.

Maybe something like this,...
   movlw .3
   subwf  x, W
  btfsc f,b             ; 'f' is the file register, and 'b' is the bit you want to test
  goto label1       ; Do this 'else'
  goto label2      ; Do this 'if'

label1:                 ; ( > 2 )
  movlw .10
  subwf x, W
  btfsc STATUS, 2
  goto label4     
  goto label5     
label4:                ;( 2 < X >= 10 )
  ;yourcode
  goto label3
label5:                ;(2 < X < 10 )
  ;yourcode
  goto label3

label2:                 ; ( <= 2 )
  ;yourcode         
  goto label3

label3:                 ;break out of the if/else statement and continue
« Last Edit: January 10, 2013, 07:11:04 AM by SethMods »

 

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