.INCLUDE"M32DEF.INC"
.EQU SS1 = 0
.EQU SS2 = 1
.EQU RS = 1
.EQU EN = 0
.EQU LCD_PORT = PORTD
LDI R16,HIGH(RAMEND) ;STACK SETTINGS
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
;=================IO SETTINGS=================
LDI R16,0xFF ;LCD
OUT DDRD,R16
SBI DDRC,0
SBI DDRC,1
SBI DDRB,7 ;SPI
CBI DDRB,6
SBI DDRB,5
SBI DDRA,0 ;SLAVE SELECT
SBI DDRA,1
;=================SPI SETTINGS=====================
SBI PORTA,SS1 ;SLAVES OFF
SBI PORTA,SS2
LDI R16,(1<< SPE | 1<< MSTR )
OUT SPCR,R16
;================LCD SETTINGS=================
CBI PORTC,EN
CALL DELAY2MS
LDI R16,0x38
CALL CW
CALL DELAY2MS
LDI R16,0x0E
CALL CW
LDI R16,0x01
CALL CW
CALL DELAY2MS
CALL DELAY2MS
CALL DELAY2MS
TRANSMIT:
CBI PORTA,SS1 ;ENABLE SLAVE1
LDI R16,0xFF
OUT SPDR,R16 ;START THE TRANSMITION
WAIT1:
SBIS SPSR,SPIF ;CHECK FOR TRANSMITION COMPLETION.
RJMP WAIT1
IN R20,SPDR
SBI PORTA,SS1 ;DISABLE SLAVE1
CBI PORTA,SS2 ;ENABLE SLAVE2
LDI R16,0xFF
OUT SPDR,R16 ;START THE TRANSMITION
WAIT2:
SBIS SPSR,SPIF ;CHECK FOR TRANSMITION COMPLETION.
RJMP WAIT2
IN R21,SPDR
SBI PORTA,SS2 ;DISABLE SLAVE2
ADD R21,R20
LSR R21
CALL DISP
RJMP TRANSMIT
;===============SUB-ROUTINES==================================
CW:
OUT LCD_PORT,R16
CBI PORTC,RS
SBI PORTC,EN
CALL SDELAY
CBI PORTC,EN
CALL DELAY100US
RET
DW:
OUT LCD_PORT,R16
SBI PORTC,RS
SBI PORTC,EN
CALL SDELAY
CBI PORTC,EN
CALL DELAY100US
RET
SDELAY:
NOP
NOP
RET
DELAY100US:
PUSH R17
LDI R17,60
L1: CALL SDELAY
DEC R17
BRNE L1
POP R17
RET
DELAY2MS:
PUSH R17
LDI R17,20
L2: CALL DELAY100US
DEC R17
BRNE L2
POP R17
RET
DISP:;==============EXTRACT DIGIGTS , CONVERT TO ASCII AND DISPLAY================
CLR R11
MOV R24,R21
DL1:CPI R24,10
BRLO NEXT
SUBI R24,10
INC R25
RJMP DL1
NEXT:
LDI R16,48
ADD R24,R16
ADD R25,R16
LDI R16,0x01
CALL CW
LDI R16,'T'
CALL DW
LDI R16,'E'
CALL DW
LDI R16,'M'
CALL DW
LDI R16,'P'
CALL DW
LDI R16,':'
MOV R16,R11
CALL DW
MOV R16,R10
CALL DW
RET