;------------------------------------------------------------------------------
; Program entry point
;------------------------------------------------------------------------------
ProgramEntryPoint:
ldi r16, LOW(RAMEND) ; Initialize stack pointer
out SPL, r16 ;
rcall LCD_Init ; Initialize LCD
ldi r16, (HD44780_LINE0 + 1) ;
rcall LCD_SetAddressDD ; Set Display Data address to (0,1)
ldi ZL, LOW(Text1 << 1) ; Load string address to Z
ldi ZH, HIGH(Text1<< 1) ;
rcall LCD_WriteString ; Display string
ldi r16, (HD44780_LINE1 + 1) ;
rcall LCD_SetAddressDD ; Set Display Data address to (1,1)
ldi ZL, LOW(Text2 << 1) ;
ldi ZH, HIGH(Text2<< 1) ; Load string address to Z
rcall LCD_WriteString ; Display string
MainLoop:
rcall OWReset ; One wire reset
brts MainLoop ; If device not present go to MainLoop
ldi r16, 0x33 ; Write ReadRom command
rcall OWWriteByte ;
rcall CRC8Init ; Initialize CRC8 value
rcall OWReadByte ; Read first byte (Family ID)
cpi r16,0 ; If first byte equal to zero, go to MainLoop
breq MainLoop ; (short circuit on one wire bus)
rcall CRC8Update ; Update the CRC
ldi YL, LOW(SerialNumber) ;
ldi YH, HIGH(SerialNumber) ; Load to Y address of SerialNumber table
st Y+, r16 ; Store first byte to table, and increment pointer
ldi r17, 7 ; 7 bytes remaining
StoreLoop:
rcall OWReadByte ; read next byte
rcall CRC8Update ; update the CRC
st Y+, r16 ; store next byte to table, and increment pointer
dec r17 ; decrement loop counter
brne StoreLoop ; if greater than zero, jump to StoreLoop
rcall GetCRC8 ; Read computed CRC8
cpi r16,0 ; copmare it with zero
brne MainLoop ; if not equal, jump to MainLoop (bad CRC)
; else
ldi r16, (HD44780_LINE1 + 0) ;
rcall LCD_SetAddressDD ; Set DisplayData address to (0,1)
ldi YL, LOW(SerialNumber) ;
ldi YH, HIGH(SerialNumber) ; Load to Y address of SerialNumber table
ldi r17,8 ; 8 digits to display
LoadLoop:
ld r16, Y+ ; load to r16 byte from table
rcall LCD_WriteHex8 ; display it on LCD in HEX
dec r17 ; decrement loop conouter
brne LoadLoop ; if not zero, jump to LoadLoop
rjmp MainLoop ; jump to MainLoop
;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------
|