.device AT90S2313 .include "2313def.inc" .equ A0 = PB3 .equ A1 = PB2 .equ A2 = PB1 ; .equ PWR = PD0 ; (in) raw 5V .equ ST1 = PD1 ; (out) latch pll1 .equ rot1 = PD2 ; (in) rotary sw1 to ground .equ ST2 = PD3 ; (out) latch pll2 .equ rot2 = PD4 ; (in) rotary sw2 to ground .equ RS = PD5 ; (out) LCD RS .equ E = PD6 ; (out) LCD E .def data = r16 .def latch = r17 .def temp = r18 .def count = r19 .def updn = r20 .dseg .equ pll10 = 0x60 .equ pll11 = 0x61 .equ pll20 = 0x62 .equ pll21 = 0x63 .cseg .org 0 rjmp main rjmp int0r main: ldi temp,RAMEND out SPL,temp ldi temp,0xff out DDRB,temp ; data output ldi temp,0b11101010 out DDRD,temp ; control port ldi temp,0b00010100 ; PD2,4 internal pull-up out PORTD,temp ldi data,0xf9 ; pll1 = 0x2f9 (761) sts pll10,data ldi data,0x02 sts pll11,data ldi data,0x6f ; pll2 = 0x16f (367) sts pll20,data ldi data,0x01 sts pll21,data rcall initlcd ; ; rcall display ; display frequency rcall initpll ; and set pll ldi temp,(1< X --> pll1 (fr = 10.05025 kHz) ; ; ^ ; | ; | ; ; VCO2 (51.6 - 51.9) --> X --> pll2 (fr = 9.95025 kHz) ; ; ^ ; | ; | ; ; XTAL (48.0) ; ; ; ;************************************************************************** initpll: ldi data,0xd2 ; latch4 10MHz/9.95025kHz = 1005=0x3ed rcall wrpll1 ldi data,0xea ; latch5=0xe rcall wrpll1 ldi data,0x36 ; latch6=0x3 rcall wrpll1 ldi data,0x32 ; latch4 10MHz/10.05025kHz = 995=0x3e3 rcall wrpll2 ldi data,0xea ; latch5=0xe rcall wrpll2 ldi data,0x36 ; latch6=0x3 rcall wrpll2 setfreq: lds data,pll10 ; write pll1 swap data andi data,0xf0 rcall wrpll1 ; latch0 lds data,pll10 andi data,0xf0 ori data,0x08 rcall wrpll1 ; latch1 lds data,pll11 swap data andi data,0xf0 ori data,0x04 rcall wrpll1 ; latch2 ldi data,0x0c rcall wrpll1 ; latch3 lds data,pll20 ; write pll2 swap data andi data,0xf0 ; ori data,0x00 rcall wrpll2 ; latch0 lds data,pll20 andi data,0xf0 ori data,0x08 rcall wrpll2 ; latch1 lds data,pll21 swap data andi data,0xf0 ori data,0x04 rcall wrpll2 ; latch2 ldi data,0x0c rcall wrpll2 ; latch3 ret wrpll1: out PORTB,data sbi PORTD,ST1 nop nop cbi PORTD,ST1 ret wrpll2: out PORTB,data sbi PORTD,ST2 nop nop cbi PORTD,ST2 ret ;************************************************************************** ; ; read/write eeprom routines ; ;************************************************************************** ;************************************************************************** ; ; lcd routines ; ;************************************************************************** initlcd: ldi data,0x20 ; 4bit, 1 line rcall lcdcmd ldi data,0x14 ; shift mode rcall lcdcmd ldi data,0x0c ; display on rcall lcdcmd ldi data,0x06 ; rcall lcdcmd ldi data,0x01 ; clear display rcall lcdcmd rcall delay20ms ldi count,16 ldi ZH,HIGH(lcdtxt*2) ldi ZL,LOW(lcdtxt*2) txtlp: cpi count,8 brne txtlp1 ldi data,0xc0 rcall lcdcmd txtlp1: lpm mov data,r0 rcall lcddata inc ZL brne txtlp2 inc ZH txtlp2: dec count brne txtlp ret lcdcmd: cbi PORTD,RS ; command push data andi data,0xf0 rcall lcdnib pop data swap data andi data,0xf0 rcall lcdnib ret lcddata: sbi PORTD,RS ; data push data andi data,0xf0 rcall lcdnib pop data swap data andi data,0xf0 rcall lcdnib ret lcdnib: sbi PORTD,E out PORTB,data rcall delay1ms cbi PORTD,E ret lcdtxt: .db "FM 70.xxx.x MHz" ;************************************************************************** ; ; other routines ; ;************************************************************************** delay1ms: push r17 push r18 ldi r17,13 ; 13*256*3= 9984 ticks = 1ms del2: ldi r18,0xff del1: dec r18 brne del1 dec r17 brne del2 pop r18 pop r17 ret delay20ms: push r17 ldi r17,20 del3: rcall delay1ms dec r17 brne del3 pop r17 ret bcd2hex