;It was my first working assembly language code and it took two 2-bit binary numbers
;and added them together, lighting up three LEDs to show the output sum (also in binary).
;File: main.asm
;Desc: Lab 2 - 2 bit adder
;Date: 1 - 16 - 13
;Device: PIC18F1220
list p=18F1220
radix hex
config WDT=OFF,LVP=OFF
#include "P18F1220.INC"
NUM1 equ 0x80
org
0x000 ;Initialize I/O pins
CLRF PORTB
MOVLW
0x7F ;Digital
I/O
MOVWF
ADCON1 ;Digital I/O
MOVLW 0x0F
MOVWF
TRISB ;RB<3:0> inputs and RB<7:4> outputs
MOVLW
0x00 ;W=0
MOVWF
NUM1 ;NUM1=0
Loop: MOVF PORTB,W ;Read
PORTB
ANDLW
0x03 ;Clear
upper 6 bits
MOVWF
NUM1 ;NUM1=000000AA
MOVF
PORTB,W ;Read PORTB again
ANDLW
0x0C ;WREG=0000BB00
RRNCF WREG
RRNCF WREG ;WREG=000000BB
ADDWF
NUM1,W ;WREG=A+B
RRNCF WREG
RRNCF WREG
RRNCF WREG ;A+B is in the upper 3 bits of WREG
MOVWF
PORTB
GOTO Loop
end
;Just to show off the beauty of fine engineering, here are a couple pictures of our final circuit:
;Such circuit. Much lights. So wow.

.jpeg)
I'm not an expert on blogs, but if you mouse around your code and change the font to "courier" it will look nice. Back in my day, we just had a machine language simulator written by the teacher, teletype and all that, so I think you're having *much* more fun with a real micro !
ReplyDeleteOoh, that does look cool. Thank you!
Delete