Sunteți pe pagina 1din 3

;********************************MACROS***********************************

; PORTB is control lines in following order


; NC NC NC NC /CE WR RD C/D

; PORTA is data

; DDR* = 0 ==> input pin


; when used to read status, doesn't matter if pull up is active or not

;checks the status of the LCD display


;takes as input what a valid status is
.MACRO statusi

; ldi temp2, 0b01010101


; out PORTB, temp2

clr temp ;set PORTA to all inputs


out DDRA, temp
; ser temp
; out PORTA, temp ;set pull ups, why the hell not???
statuswait:
ldi temp, 0b00010101
out PORTB, temp ;set control lines
in temp, PINA ;read data
nop
nop
andi temp, @0
ldi temp1, 0b00011101
out PORTB, temp1 ;set control lines
cpi temp, @0 ;compare
brne statuswait ;if status check fails, try again

ldi temp, 0b00011010 ;return chip to read status to avoid double writing
(VERY bad)
out PORTB, temp
.ENDMACRO

;checks the status of the LCD display


;takes as input what a valid status is
.MACRO status

; ldi temp2, 0b01010101


; out PORTB, temp2

clr temp ;set PORTA to all inputs


out DDRA, temp
; ser temp
; out PORTA, temp ;set pull ups, why the hell not???
statuswait:
ldi temp, 0b00010101
out PORTB, temp ;set control lines
in temp, PINA ;read data
nop
nop
and temp, @0
ldi temp1, 0b00011101
out PORTB, temp1 ;set control lines
cp temp, @0 ;compare
brne statuswait ;if status check fails, try again

ldi temp, 0b00011010 ;return chip to read status to avoid double writing
(VERY bad)
out PORTB, temp
.ENDMACRO

;writes data to the LCD display


;takes as input the data to be written
.MACRO writei
ser temp ;set PORTA to all outputs
out DDRA, temp
ldi temp, @0
out PORTA, temp ;put data on PORTA
ldi temp, 0b00010010
out PORTB, temp ;set control lines
ldi temp, 0b00011010
out PORTB, temp ;bring /CE back up
.ENDMACRO

;writes data to the LCD display


;takes as input the data to be written
.MACRO write
ser temp ;set PORTA to all outputs
out DDRA, temp
out PORTA, @0 ;put data on PORTA
ldi temp, 0b00010010
out PORTB, temp ;set control lines
ldi temp, 0b00011010
out PORTB, temp ;bring /CE back up
.ENDMACRO

;writes a command to LCD display


;takes as input the command to be written
.MACRO commandi
ser temp ;set PORTA to all outputs
out DDRA, temp
ldi temp, @0
out PORTA, temp ;put command on PORTA
ldi temp, 0b00010011
out PORTB, temp ;set control lines
ldi temp, 0b00011011
out PORTB, temp ;pulse /CE back up
.ENDMACRO

;writes a command to LCD display


;takes as input the command to be written
.MACRO command
ser temp ;set PORTA to all outputs
out DDRA, temp
out PORTA, @0 ;put command on PORTA
ldi temp, 0b00010011
out PORTB, temp ;set control lines
ldi temp, 0b00011011
out PORTB, temp ;pulse /CE back up
.ENDMACRO
;***********************************16 bit
math**********************************************
;adds two 16 bit numbers, takes in add1h, add1l, add2h, add2l
.MACRO add16
add @1,@3 ;Add low bytes
adc @0,@2 ;Add high bytes with carry
.ENDMACRO

;compares two 16 bit numbers, takes in cp1h, cp1l, cp2h, cp2l


.MACRO cp16
cp @1,@3 ;Compare low byte
cpc @0,@2 ;Compare high byte with carry from
;previous operation
.ENDMACRO

;add a 16 bit number to a 16 bit immediate, takes in addh, addl, addi


.MACRO addi16
subi @1, low(-@2) ;Add low byte ( x -(-y)) = x + y
sbci @0, high(-@2) ;Add high byte with carry
.ENDMACRO

;compares a 16 bit number with an immediate, takes in cp1h, cp1l, cpi


.MACRO cpi16
cpi @1, low(@2) ;Compare low byte
ldi temp, high(@2) ;
cpc @0, temp ;Compare high byte
.ENDMACRO

;subtract constant from 16 bit number, takes in subh, subl, subi


.MACRO subi16
subi @1,low(@2) ;Subtract low bytes
sbci @0,high(@2) ;Subtract high byte with carry
.ENDMACRO

S-ar putea să vă placă și