; $Id: 99bottlesofbeer.asm,v 1.3 2003/10/23 10:17:21 thilo Exp thilo $ ; ; 99 bottles of beer on the wall for any recent midrange Microchip MCU with 14bit ; programm word (PIC16CXXX/PIC16FXXX family) and USART module, e.g. all PIC16F87x ; ; written by Thilo Manske ; ; needs 3 GP registers and 158 words (~277 bytes) of program memory ; use gpasm to assemble (see http://gputils.sourceforge.net/) ; adjust the following lines for your CPU list p=16f873 include "p16f873.inc" __config _WDT_OFF & _XT_OSC ; GP registers, since they are in [0x70..0x7f] they are available in all banks ; and we don't have to care about bank switching when we access them cblock 0x70 pointer bottles10 bottles1 endc ;; macro to select the correct bank for
;; The default BANKSEL macro always sets/clears both bank bits, but we only ;; use bank 0 and 1 and don't have to take care of RP1 SELBANK macro address if address < 0x80 bcf STATUS,RP0 else bsf STATUS,RP0 endif endm ; start org 0 SELBANK SPBRG movlw d'38' ; adjust this for your clock freq/baud rate movwf SPBRG movlw (1< end of string call charout incf pointer,w goto stringout getchar ; this will look weird to people who don't know how movwf PCL ; you read data out of a PICs program memory ;) ;; writes "1 bottle of beer" onebottleofbeer movlw '1' call charout movlw bottletxt call stringout goto ofbeer ;; writes "on the wall" onthewall movlw onthewalltxt goto stringout ; "data subroutines" bottletxt dt " bottle\0" ofbeertxt dt " of beer\0" onthewalltxt dt " on the wall\0" takeonedowntxt dt "Take one down, pass it around\0" nomoretxt dt "No more\0" end