Då jag inte är särdeles bra på att programmera behöver jag hjälp med att felsöka denna kod:
Alla operationer med temp2 är bara för att se om koden där körs överhuvudtaget.
RTCn är en DS1302.
Kod: Markera allt
.include "8515def.inc"
.org $0000
rjmp reset
.def temp=r16
.def rtcdat=r17
.def cnt=r18
.def temp2=r19
.equ rtc = portd
.equ btn = portd
.equ select = 0
.equ plus1 = 1
.equ ok = 2
.equ rst = 7
.equ io = 6
.equ clk = 5
.equ iopin = pind6
reset:
;initiera stackpekaren
ldi temp, HIGH(RAMEND)
out SPH, temp
ldi temp, LOW(RAMEND)
out SPL, temp
;Sätt upp portar
ser temp
out ddra, temp
out ddrb, temp
out ddrc, temp
ldi temp, 0b11111000
out ddrd, temp
rjmp main
;initiera interrupts
; ldi temp, 0b00000010
; out timsk, temp
; sei
;initiera timer0
; ldi temp, 0b00000010
; out tccr0, temp
;Sätt1
;ldi rtcdat, 0b10000000
;sbi PORTD, PIND7
;rcall txrtc
;ldi rtcdat, 0x00
;rcall txrtc
;cbi PORTD, PIND7
;Sätt2
;sbi PORTD, PIND7
;ldi rtcdat, 0b10001000
;rcall txrtc
;ldi rtcdat, 0x10
;rcall txrtc
;cbi PORTD, PIND7
;sei
main:
;ldi temp2, 0x33
;out portb, temp2
;ldi temp, 0x86
;out porta, temp
;out portb, temp
;out portc, temp
;sbis PIND, 0
;rjmp sethr
rcall sweep
ldi temp2, 0x99
out portb, temp2
rcall main
Sweep:
ldi rtcdat, 0b10000001
rcall txrtc
nop
nop
rcall rxrtc
out porta, rtcdat
ret
;****************************************************************************
;'txrtc'
;Aim
; Function to write a byte to rtc. Value to be written is passed from
; calling function in register rtcdat.
;Registers used
; cnt to store no of bits
; rtcdat to store the data
;Functions called
; none
;*****************************************************************************
txrtc: ldi cnt, $08 ; load counter
sbi ddrd, 6
sbi rtc, rst ; set RST
txbck: ror rtcdat ; rotate data right through carry
cbi rtc, clk ; clear SCLK
brcc txnxt ; if carry set
ldi temp2, 0x44
out portc, temp2
sbi rtc, io ; set I/O
rjmp txnxt1 ; else
txnxt: cbi rtc, io ; clear I/O
txnxt1: sbi rtc, io ; set SCLK
dec cnt ; decrement counter
brne txbck ; if counter not zero, go back
nop
cbi rtc, io ; clear SCLK
;cbi rtc, rst ; clr rst
ret
;******************************************************************************
;'rxrtc'
;Aim
; Function to read a byte from rtc. Value read is returned in register
; rtcdat
;Registers used
; cnt to store no of bits
; rtcdat to store the data read
;Functions called
; none
;*****************************************************************************
rxrtc: ldi cnt,$08 ; load counter
cbi ddrd, 6
clr rtcdat
rxbck: sbi rtc, clk ; set SCLK
sbic rtc, pind6 ; if I/O set then
sec ; set carry
sbis rtc, pind6 ; else
clc ; clear carry
ror rtcdat
cbi rtc, clk ; clear SCLK
dec cnt ; decrement counter
brne rxbck ; if counter equals zero, goto calling function
cbi rtc, rst
ret ; else jump back