From: Don Hyde >I once worked with a group of ex-IBM assembler jocks. They had a very >strict rule requiring 2 comments for every 3 lines of assembler code. > >One of these guys was a poetry buff. The right-hand column of his listings >had neat lines of iambic pentameter. The poetry had nothing to do with the >source code, but it was always passed by the official code-checkers. BTW -- >he was a fantastic coder and produced lots of good code in spite of all the >time he spent writing (bad) poetry on company time. [Shields Up] This man was a bad programmer and a bad employee :-) BECAUSE - - His undocumented code would have been hard to follow by anyone else trying to maintain it after him, trying to add to it or trying to understand its finer intentions. - He failed to explain his cleverness so those-who-came-after would benefit - He failed to discern the important spirit of the pedantically put official edict and did not (apparently) meet the spirit in some other way. - He stole from his employer by constantly writing poetry in company time. His code will probably have cost IBM dear if it was worth writing. BECAUSE. If it was worth writing it will probably have had a lifetime exceeding his time on the project and the points above will, at the least have wasted another programmers time subsequently and at worst may have been the reason why IBM took a bath on two large projects in this country in recent years :-) (one for NZ telecom on its billing/accounting systems, the other for the NZ Police where the project did a fully classic crash-and-burn-after-10's-of-millions-have-been-spent-with-no-deliverables-w hatsoever. I take it that he (and you?) would be appalled at the documentation level of the code snippet below. Note that not every line has a comment [I make no claims for the goodness of the code] [You may find some instructions (documented elsewhere:-)) a little unfamiliar :-)] It has - 31 non blank lines of which 13 are code lines 17 are documentation (with or without label) lines Is there something WRONG with doing this??? Note that using meaningful label names can count as documentation. eg, what do you think GOTO WAIT4END does ? Do you think that MOVLW KPWMMAX is loading a valid constant? What do you think its function is. provocatively yours, Russell McMahon [Shields still up] ---------------------------------------------------------------------------- ---- ;;* Now clear PWM output ; ********************** ;;* PWM trigger point has been reached. Now set output low. ; Technically this action is unneeded in STOP mode but it is an added safety feature ; to ensure PWM is off (provided that SHADOWB/KPWMOUT is low, as it should be, having ; been cleared a few lines back.) This also allows beeper resetting and anything else ; that is using the port. When Beeper-AC is running it will update the port frequently. BCF ShadowB, KPWMOUT ; set shadow PWM bit low. MOVF ShadowB, W ; get shadow port (with PWM bit set low already) MOVWF PORTB ; output it ; Now for assessment (again) of where the non-critical code should run. BTFSS FLAGS, FSpareTime GOTO LoNonCrit GOTO SkipLoNC LoNonCrit ; Start of once per cycle non time critical code ; which should be run CALL DoNonCrit SkipLoNC ;;* WAIT FOR END OF PWM CYCLE: ; **************************** ;;* Now we can set and wait until the timer cycle finishes. ;;* At 100% duty cycle this will be immediate. ;;* Endpoint occurs when timer2 (PBF5.2) reaches the max allowed PWM value. WAIT4END: ; Loop to here until PWM output ready to be set to off. CLRWDT ; Clear watchdog timer MOVLW KPWMMAX ; Get maximum timer value ; PBF5.2: SUBWF TIMER, W ; See if yet up to max value SUBWF TIMER2, W ; See if yet up to max value ;; debug PBF4A2 - replace with carry bit check - BTFSS STATUS, ZERO ; B if trigger point reached, BTFSS STATUS, CARRY ; Finish when Timer-Tmax goes positive. GOTO WAIT4END ; , else loop again ;;* PWM is low, we are at the end of the cycle. Go back and start again. ;;* All done - go round power. GOTO LOOPIT ; ***********************************************