*** funky.a: dcf77 tester code equ EEPROM code location (RAM or EEPROM) lcdhome equ $80 home position on lcd lcdclr equ $01 clear display, cursor home DAY_ equ $3 1=monday, 7=sunday DATE_ equ $01 day of month (bcd) MONTH_ equ $01 month (bcd) YEAR_ equ $94 year within century (bcd) FLAGS_ equ %00100100 x, x, start=1, ls, mesz, mez, ly, r *** initializing code may be used as storage area org RAM varbeg equ * csecs rmb 1 seconds/100 (bcd) hours rmb 1 hours (bcd) mins rmb 1 minutes (bcd) secs rmb 1 seconrmb(bcd) day rmb 1 day of week (bcd) date rmb 1 day of month (bcd) month rmb 1 month (bcd) year rmb 1 year within century (bcd) flags rmb 1 x, x, start=1, ls, mesz, mez, ly, r dcfbuf rmb 1 buffer for dcf data parity rmb 1 for parity calculation longp rmb 1 0 = short, 1 = long pulse secchg rmb 1 flag from toc1 interrupt keytim rmb 1 key timer keybuf rmb 1 key buffer varend equ * *** this is where the program starts: org code lds #$01ff clr spcr dwom off lcdinit ldaa #$3C outputs D5=res, D4=RS, D3=E, D2=R/W staa ddrd ldx #lcdtab begin inittable lcdini1 ldaa 0,x commands from table bsr lcdcmd inx cpx #lcdtabe end inittable? bne lcdini1 ldaa #$80 ddra7 = output staa pactl ldaa #$7e write the interrupt vector (jmp) staa toc1vec ldd #toc1int std toc1vec+1 ldaa #$80 enable oc1 interrupt staa tmsk1 ldx #varbeg varinit clr 0,x inx cpx #varend bne varinit ldaa #DAY_ staa day ldaa #DATE_ staa date ldaa #MONTH_ staa month ldaa #YEAR_ staa year ldaa #FLAGS_ staa flags cli unmask all interrupts jmp main lcdtab fcb $30 init table fcb $30 1 line, 5x7 dots fcb $08 display off fcb $01 display on (clear) fcb $06 increment, no shift fcb $0C display on, cursor off lcdtabe equ * *** write cmd A to LCD or set cursor position lcdcmd clrb prepare cmd write bra lcdput1 *** write character A to LCD lcdput ldab #$10 prepare data write lcdput1 clr ddrc portc all inputs psha lcdbsy ldaa #$04 command, read, E low staa portd ldaa #$0C E high staa portd tst portc busy? bmi lcdbsy pula lcdwr psha stab portd cmd/data write, E low orab #$08 E high stab portd ldaa #$ff portc all outputs staa ddrc pula data to write staa portc andb #$f7 E low stab portd rts *** write bcd A $00..$99 wrbcd psha lsra lsra lsra lsra adda #'0' jsr lcdput pula *** write decimal A 0..9 wrdec psha anda #$0f adda #'0' jsr lcdput pula rts *** clear key input updkey tst keybuf beq updkeye jsr incmins clr keybuf updkeye rts *** timer output compare 1 interrupt handler toc1int ldd toc1 addd #20000 next interrupt in 10ms std toc1 ldaa csecs update csecs adda #1 daa staa csecs bne toc1in1 inc secchg .0 sec ldab secs cmpb #$58 pa7 on exept before sec 59 beq toc1in1 ldab #$80 stab porta toc1in1 cmpa #$10 .1 sec pa7 off exept longp bne toc1in2 ldaa longp beq toc1in3 toc1in2 cmpa #$20 .2 sec pa7 always off bne toc1in4 toc1in3 clr porta toc1in4 jsr keychk ldaa #$80 reset flag staa tflg1 rti *** --- gap for interrupt vectors --- * org toc1vec+code * fcb $01,$01,$01 int vector $df: put in a gap! *** poll for key input keychk ldaa porte read keyport coma anda #$80 bne keychk1 clr keytim no key pressed rts keychk1 inc keytim ldab keytim cmpb #8 key press stable? beq keychk3 cmpb #80 begin auto repeat? beq keychk2 rts keychk2 subb #5 auto repeat rate stab keytim keychk3 staa keybuf store key rts *** increment secs, update of mins and hours updtim ldaa secs adda #1 daa staa secs cmpa #$60 bne updtime incmins clr secs ldaa mins adda #1 daa staa mins cmpa #$60 bne updtime clr mins ldaa hours adda #1 daa staa hours cmpa #$24 bne updtime clr hours updtime * jsr dsptim * rts *** display current time dsptim ldaa #lcdhome jsr lcdcmd ldx #hours dsptim1 ldaa 0,x jsr wrbcd inx cpx #hours+3 beq dsptim2 cpx #hours+4 bne dsptim3 dsptim2 ldaa #' ' jsr lcdput dsptim3 cpx #hours+7 bne dsptim1 rts *** set longp if the current dcf bit is 1, clear otherwise upddcf clr longp ldaa secs updcf0 cmpa #$0 bit 0? (start) bhi updcf14 dec longp rts updcf14 cmpa #$14 bits 1 to 14? (reserved) bhi updcf15 rts updcf15 cmpa #$15 bit 15? (flags) bhi updcf20 ldab flags stab dcfbuf updcf20 cmpa #$20 bits 16 to 20? bhi updcf21 jmp getbit updcf21 cmpa #$21 bit 21? (mins) bhi updcf27 ldab mins stab dcfbuf clr parity updcf27 cmpa #$27 bits 22 to 27? bhi updcf28 bra getbit updcf28 cmpa #$28 bit 28? (p1: mins) bhi updcf29 ldab parity stab longp rts updcf29 cmpa #$29 bit 29? (hours) bhi updcf34 ldab hours stab dcfbuf clr parity updcf34 cmpa #$34 bits 30 to 34? bhi updcf35 bra getbit updcf35 cmpa #$35 bit 35? (p2: hours) bhi updcf36 ldab parity stab longp rts updcf36 cmpa #$36 bit 36? (date) bhi updcf41 ldab date stab dcfbuf clr parity updcf41 cmpa #$41 bits 37 to 41? bhi updcf42 bra getbit updcf42 cmpa #$42 bit 42? (day) bhi updcf44 ldab day stab dcfbuf updcf44 cmpa #$44 bits 43 to 44? bhi updcf45 bra getbit updcf45 cmpa #$45 bit 45? (month) bhi updcf49 ldab month stab dcfbuf updcf49 cmpa #$49 bits 46 to 49? bhi updcf50 bra getbit updcf50 cmpa #$50 bit 50? (year) bhi updcf57 ldab year stab dcfbuf updcf57 cmpa #$57 bhi updcf58 bra getbit updcf58 ldab parity bit 58! (p3: date, day, month, year) stab longp rts getbit lsr dcfbuf read from dcfbuf, parity update bcc getbite com parity dec longp getbite rts main jsr updkey tst secchg beq main clr secchg jsr updtim jsr upddcf bra main