But, as we can see over and over again in discussions about programming languages, this is a moot point IMHO. Sure it takes more "typing" than a single numeric constant. Some languages have have better support for this than others, but through simple macros, as you showed, this is still very easy to do in C. Writing constants the way you show above is the right way of approaching it IMO. This makes the overall debate about numeric constants pointless, as they are, as you pointed out, the worst possible way of expressing set bits. Get the comparator +ve input from the DAC - set to approx 1.9V V = (DACCON0/32)*5 BANKSEL DACCON0 MOVLW D'12' set the voltage MOVWF DACCON1 MOVLW B'10000000' enable DAC, source Vdd 1 x 0 0 0 0 x x | | | -+- | | | +- 00 = DAC Positive Source Vdd | | +- 0 = DAC not connected to the DACOUT2 pin | +- 0 = DAC not connected to the DACOUT1 pin +- 1 = DAC is enabled MOVWF DACCON0 But in the code where masks were used, hex made sense MOVF PWM,W Add the least significant ADDWF Dithr,F 14 bits of PWM to Dithr MOVF PWM+1,W ANDLW 0x3F truncate to top 6 of 14 bits BTFSC STATUS,C ADDLW 0x01 add in carry ADDWF Dithr+1,W add to the current Dithr BTFSC WREG,6 was there 14 bit overflow BSF STATUS,C ANDLW 0x3F truncate to top 6 of 14 bits MOVWF Dithr+1 MOVF PWM+1,W now work out the top 10 bits ANDLW 0xC0 get least significant two bits of 10 BTFSC STATUS,C ADDLW 0x40 yes, increase duty cycle 1 bit I just use whatever base makes the most sense when I come back to read it later.įully agree. I used binary and decimal constants: - DAC - Analog input on RC2 - all RCx inputs are analog at reset, only RC2 is used as input so no need to change ANSEL. Here's some code I wrote to set up a DAC. Surely it's whatever is appropriate for the use.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |