Cheerful regards, Mike
Code: Select all
;******************************************************************
; Homework #1: 8x8 Smiley Face Mike McLaren, 05-Jan-2013 *
;******************************************************************
include "P16f648a.inc"
__config _WDT_OFF&_LVP_OFF&_MCLRE_OFF&_BOREN_OFF&_INTOSC_OSC_NOCLKOUT
list st=off ; turn symbol table off in LST file
errorlevel -302 ; disable bank warning messages
radix dec ; use decimal numbers
;
; variables
;
cblock 0x20
delayhi ; delay sub variable
endc
;******************************************************************
; main init *
;******************************************************************
org 0x000
init
clrf STATUS ; bank 0 |B0
movlw h'07' ; |B0
movwf CMCON ; comparator off, digital I/O |B0
movwf PORTA ; preset 7442 address to 7 |B0
bsf STATUS,RP0 ; bank 1 |B1
clrf TRISA ; porta all outputs, except RA5 |B1
clrf TRISB ; portb all outputs |B1
bcf STATUS,RP0 ; bank 0 |B0
;******************************************************************
; main loop *
;******************************************************************
loop
clrf PORTB ; blank the display |B0
incf PORTA,W ; bump 7442 address (and index) |B0
andlw 7 ; keep in 0..7, inclusive |B0
movwf PORTA ; select new column |B0
addwf PCL,F ; jump into the "in-line" table |B0
xorlw 0^b'00111100'^(1^b'01000010')
xorlw 1^b'01000010'^(2^b'10101001')
xorlw 2^b'10101001'^(3^b'10000101')
xorlw 3^b'10000101'^(4^b'10000101')
xorlw 4^b'10000101'^(5^b'10101001')
xorlw 5^b'10101001'^(6^b'01000010')
xorlw 6^b'01000010'^(7^b'00111100')
xorlw 7^b'00111100' ;
movwf PORTB ; display new column |B0
;
; delay subsystem range is 7..327682 usecs in 5 usec steps but
; we'll use 1000 usecs per column for a 125 Hz refresh rate
;
movlw high((1000-7)/5)+1
movwf delayhi
movlw low ((1000-7)/5)
v2delay addlw -1 ; subtract 5 cycle loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto v2delay ; do another 5 cycle loop |B0
goto loop ; branch (loop forever) |B0
;******************************************************************
end