movlw b'11110110' ;configure timer0:...
;--1-----
;----0---
;-----110
option
movlw 1<<TOCS|0<<PSA|b'110'
option
So to check my understanding, in the the delay program you posted, the formula for msecs is defined as a constant. 'msecs' can then be used with the Assembly operator for mulltiply (*) in later instructions like, 'delay (100*msecs)', but you cannot use that operator in an instruction like, 'delay (register_a* msecs)', because the contents of register_a cannot be evaluated at assembly. I hope that is correct.
movlw 1<<TOCS|0<<PSA|b'110'<<PS0
option
movlw (0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
#define LED_Port PORTB
#define Key1 7
#define Key2 6
movlw 1<<Key1 | 1<<Key2
iorwf LED_Port ;Set key1 & 2 high
or,
bsf LED_Port,Key1
The second example is more portable and is self commenting.
...
You simply change 0s to 1s to set/clear bits. You don't need to know where the bits are.Code:movlw (0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
movlw b'11110110' ;configure timer0:...
;1------- ; PORTB pullups OFF
;--1----- ; TMR0 on external clock
;----0--- ; prescaler assigned to TMR0
;-----110 ; prescaler set to 128:1
option
Wow Pommie you stunned me! Do you really think that is a better way to write assemble for hardware register setupsr?
To me assembler is always a very vertical language, and the very best coding style keeps it vertical and well commented. Portability has it's value but when porting a PIC assembler project you always have to spend some time checking PIC hardware differences anyway, and then only a small % of projects get ported and checking the hardware registers only takes a few minutes (and has to be done anyway as I said).
To me the best code would look like this;
Code:movlw b'11110110' ;configure timer0:... ;1------- ; PORTB pullups OFF ;--1----- ; TMR0 on external clock ;----0--- ; prescaler assigned to TMR0 ;-----110 ; prescaler set to 128:1 option
Wow Pommie you stunned me! Do you really think that is a better way to write assemble for hardware register setupsr?
[/code]
movlw 8 ;load w with 8
movwf v ;put in v
l2 bsf PORTB,2 ;set clock pin
nop
bcf PORTB,2 ;clear clock pin
decfsz v,f ;decrement v
goto l2 ;loop
return ;return from subroutine
#define ClockPin PORTB,2
movlw 8
movwf PulseCount
SendPulse bsf ClockPin
nop
bcf ClockPin
decfsz PulseCount,f
goto SendPulse
return
That's a Great book looks like I read chapter 5 and the contents at his website got to order me onef you get a chance, read Code Complete by Steve Maconnell,
movlw (0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
movlw b'00000000'
That's a Great book looks like I read chapter 5 and the contents at his website got to order me one
Yes I do, why use 7 lines of code (you missed bits 6 & 4) to write something when one line works as well if not better.
...
As for commenting, I hate seeing things like,
Code:movlw 8 ;load w with 8 movwf v ;put in v l2 bsf PORTB,2 ;set clock pin
...
I like code to be vertical and you will not find any code of mine (C or asm) with more than one instruction/function on a line. The reason I don't like abundant comments is that the really important comments get lost.
...
...
I think you would like Code Complete as the authors philosophy makes perfect sense. For example, he believes that if code is so complex it needs a lot of commenting then, if possible, you should rewrite the code to be more understandable.
...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?