Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
movwf EEDAT ; Writes data to temporary register
banksel EECON1
bcf EECON1,EEPGD
bsf EECON1,WREN ; Write enabled
bcf INTCON,GIE ; All interrupts disabled
btfsc INTCON,GIE
goto $-2
movlw 55h
movwf EECON2
movlw H'AA'
movwf EECON2
bsf EECON1,WR
btfsc EECON1,WR ; Wait for write to complete
goto $-1
bsf INTCON,GIE ; Interrupt enabled
bcf EECON1,WREN
goto Loop ; Tests push-buttons again
end ; End of program
EXAMPLE 13
Two-digit LED counter, multiplexing
In this example, the microcontroller operates as a two-digit counter. Concretely, the variable Dval is decremented (slow
enough to be visible) and its value is displayed on twodigit LED display (99-0). The challenge is to enable binary number to
be converted in decimal one and split it in two digits (tens and ones). Besides, since the LED display segments are
connected in parallel, it is necessary to ensure that they change fast in order to make impression of simultaneous light
emission (time-division multiplexing). Remember that in electronics, multiplexing allows several analog signals to be
processed by one analog-todigital converter (ADC). In this very case, time-division multiplexing is performed by the timer
TMR0, while binary to decimal number conversion is performed in macro "digbyte". Counter may be reset to its starting
value (99) at any moment by pressing the pushbutton "COUNTER RESET".
http://www.mikroe.com/en/books/picmcubook/appb/ (41 of 54)5/3/2009 11:36:02 AM