Homework 1 Example...

Post here to discuss the PIC microcontroller tutorials.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Mike M
decided to stick around...
decided to stick around...
Posts: 27
Joined: Thu Dec 13, 2012 3:19 am
Location: Michigan, USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Homework 1 Example...

Post by Mike M » Sun Jan 06, 2013 10:30 am

This may not have been a good idea (lol). I ended up using a number of 'tricks' to optimize the size of the program, like using an in-line table, which, when compared to a traditional table, only saves one word of program memory and one stack level. Anyway, the program uses 30 words of program memory and 1 byte of RAM but it's probably incomprehensible for beginning programmers. Sorry! I can't help myself (lol).

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
Last edited by Mike M on Mon Jan 07, 2013 2:08 am, edited 1 time in total.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Homework 1 Example...

Post by brad » Sun Jan 06, 2013 6:53 pm

Well done Mike - the first person to submit their homework to me in years!

Excellent coding there and now that I have learned a few other languages since writing the ASM tutorials, I can see how my new languages can actually help if I go back to using ASM. Once again, very well done :)

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 5 guests