Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
; tant to have it all on one page
Bcdto7seg
addwf PCL, f
DT 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f
;****************************************************************************
END ; End of program
Macro "digbyte":
digbyte MACRO arg0
LOCAL Exit0
LOCAL Exit1
LOCAL Exit2
clrf Dig0
clrf Dig1
clrf Dig2
clrf Dig3
movf arg0, w
movwf Digtemp
movlw .100
Exit2
incf Dig2, f
subwf Digtemp, f
btfsc STATUS, C
goto Exit2
decf Dig2, f
addwf Digtemp, f
Exit1
movlw .10
incf Dig1, f
subwf Digtemp, f
btfsc STATUS, C
goto Exit1
decf Dig1, f
addwf Digtemp, f
Exit0
movf Digtemp, w
movwf Dig0
ENDM
Macro digbyte is used to convert the number from digital to decimal format. Besides, digits of such decimal number are
stored into special registers in order to enable them to be displayed on LED displays.
EXAMPLE 14
Sound generating, using macros
The generation of sound is a task commonly assigned to the microcontroller. Basically, it all comes to generating a pulse
sequence on one output pin. While doing so, the proportion of logic zero (0) to logic one (1) duration determines the tone
pitch and by changing different tones, different melodies arise.
In this example, any press on push-buttons T1 and T2 generates a sound. The appropriate instructions are stored in macro
"beep" containing two arguments.
http://www.mikroe.com/en/books/picmcubook/appb/ (44 of 54)5/3/2009 11:36:02 AM