; ***** U13_syn universele synthesiser-sturing voor atv-RX ***** ; ; ***** Ver 1.1 met save freq routine 20-9-'97 ***** ; ***** Ver 1.2 met motorola synthesiser-aansturing LIST P=16C84 ; include "C74_reg.h" include "lcd.h" include "RX_UNI.h" ; LCD_DATA EQU PORTB LCD_DATA_TRIS EQU TRISB LCD_CNTL EQU PORTA ; freq_hi EQU 0x00C freq_lo EQU 0x00D freq_fractional EQU 0x00E D_0 EQU 0x00F D_1 EQU 0x010 D_2 EQU 0x011 MSD EQU 0x012 LSD EQU 0x013 TEMP EQU 0x014 TEMP1 EQU 0x015 CHAR EQU 0X016 dly_teller EQU 0x017 iic_teller EQU 0x018 tdata EQU 0x019 syn_lo EQU 0x01A syn_hi EQU 0x01B ctrl EQU 0x01C ports EQU 0x01D eefreq equ 0x00 ; ; ; LCD Display Commands and Control Signal names. ; E EQU 0 ; LCD Enable control line R_W EQU 1 ; LCD Read/Write control line RS EQU 2 ; LCD Register Select control line ; ; org 0 ; init BSF STATUS, RP0 ; Bank 1 bsf OPTION_R,RBPU ; disable pull-ups clrf TRISA ; port a als outputs movlw 0xF0 movwf TRISB ; port b4-7 als input,0-3 als output BCF STATUS, RP0 ; Bank 0 CLRF PORTA ; ALL PORT output should output Low. CLRF PORTB CLRF LCD_CNTL ; ALL PORT output should output Low. clrf freq_fractional ; tijdelijk CALL DISPLAY_INIT ; lcd display initialisatie ; goto MAIN ; ;************************************************************************** ; dispmsg movwf TEMP1 ;TEMP1 holds start of message address call Table andlw 0FFh ;Check if at end of message (zero btfsc STATUS,Z ;returned at end) return call SEND_CHAR ;Display character movf TEMP1,w ;Point to next character addlw 1 goto dispmsg ; ;********************************************************************** ; delay movlw .10 ; ca 32 us delay movwf dly_teller dly1 decfsz dly_teller,F goto dly1 return ; delay_1ms movlw .30 ; ca 1000 us delay dly2 movwf TEMP dly3 call delay decfsz TEMP,F goto dly3 return ; delay_5ms movlw .150 ; ca 5000 us delay goto dly2 ; ;*********************************************************************** ; ; DISPLAY_INIT call delay_5ms ; Wacht 15 ms voor init start call delay_5ms call delay_5ms ; MOVLW 0x03 ; Power up sequence (1) HD 44780 ; MOVWF LCD_DATA ; ; BSF LCD_CNTL, E ; ; BCF LCD_CNTL, E ; ; ; CALL delay_5ms ; Wacht 5 ms ; ; MOVLW 0x03 ; Power up sequence (2) HD 44780 ; MOVWF LCD_DATA ; ; BSF LCD_CNTL, E ; ; BCF LCD_CNTL, E ; ; ; CALL delay_1ms ; Wacht 1 ms (100us moet genoeg zijn) ; ; MOVLW 0x03 ; Power up sequence (3) HD 44780 ; MOVWF LCD_DATA ; ; BSF LCD_CNTL, E ; ; BCF LCD_CNTL, E ; ; MOVLW 0x02 ; RGKCommand for 4-bit interface low nibble MOVWF LCD_DATA ; BSF LCD_CNTL, E ; BCF LCD_CNTL, E ; ; CALL delay_5ms ; Wacht 5 ms (datash. hd44780) ; ; Command sequence for 2 lines of 5x7 characters =0x28h ; MOVLW 0X02 ; 4-bit hi nibble xfer ; MOVWF LCD_DATA ; This code for both 4-bit and 8-bit modes BSF LCD_CNTL, E ; nop BCF LCD_CNTL, E ; ; MOVLW 0x08 ; 4-bit low nibble xfer MOVWF LCD_DATA ; BSF LCD_CNTL, E ; nop BCF LCD_CNTL, E ; ; ; Busy Flag should be valid after this point ; MOVLW DISP_ON ; CALL SEND_CMD ; MOVLW CLR_DISP ; CALL SEND_CMD ; MOVLW ENTRY_INC ; CALL SEND_CMD ; MOVLW DD_RAM_ADDR ; CALL SEND_CMD ; return ; ;******************************************************************* ;* SEND_CHAR - Sends character to LCD * ;* This routine splits the character into the upper and lower * ;* nibbles and sends them to the LCD, upper nibble first. * ;* The data is transmitted on the PORT<3:0> pins * ;******************************************************************* ; SEND_CHAR MOVWF CHAR ; Character to be sent is in W CALL BUSY_CHECK ; Wait for LCD to be ready SWAPF CHAR, W ANDLW 0x0F ; Get upper nibble MOVWF LCD_DATA ; Send data to LCD BCF LCD_CNTL, R_W ; Set LCD to read BSF LCD_CNTL, RS ; Set LCD to data mode BSF LCD_CNTL, E ; toggle E for LCD nop BCF LCD_CNTL, E MOVF CHAR, W ANDLW 0x0F ; Get lower nibble MOVWF LCD_DATA ; Send data to LCD BSF LCD_CNTL, E ; toggle E for LCD nop BCF LCD_CNTL, E RETURN ; SEND_CMD MOVWF CHAR ; Character to be sent is in W CALL BUSY_CHECK ; Wait for LCD to be ready SWAPF CHAR, W ANDLW 0x0F ; Get upper nibble MOVWF LCD_DATA ; Send data to LCD BCF LCD_CNTL, R_W ; Set LCD to read BCF LCD_CNTL, RS ; Set LCD to command mode BSF LCD_CNTL, E ; toggle E for LCD nop BCF LCD_CNTL, E MOVF CHAR, W ANDLW 0x0F ; Get lower nibble MOVWF LCD_DATA ; Send data to LCD BSF LCD_CNTL, E ; toggle E for LCD nop BCF LCD_CNTL, E RETURN ; ;******************************************************************* ;* This routine checks the busy flag, returns when not busy * ;* Affects: * ;* TEMP - Returned with busy/address * ;******************************************************************* ; BUSY_CHECK BSF STATUS, RP0 ; Bank 1 MOVLW 0xFF ; Set PortB for input MOVWF LCD_DATA_TRIS ; set tris-b register (bank1 is selected) BCF STATUS, RP0 ; Bank 0 BCF LCD_CNTL, RS ; Set LCD for Command mode BSF LCD_CNTL, R_W ; Setup to read busy flag BSF LCD_CNTL, E ; Set E high BCF LCD_CNTL, E ; Set E low SWAPF LCD_DATA, W ; Read upper nibble busy flag, DDRam address ANDLW 0xF0 ; Mask out lower nibble MOVWF TEMP ; BSF LCD_CNTL, E ; Toggle E to get lower nibble BCF LCD_CNTL, E MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address ANDLW 0x0F ; Mask out upper nibble IORWF TEMP, F ; Combine nibbles BTFSC TEMP, 7 ; Check busy flag, high = busy GOTO BUSY_CHECK ; If busy, check again BCF LCD_CNTL, R_W BSF STATUS, RP0 ; Bank 1 MOVLW 0xF0 ; MOVWF LCD_DATA_TRIS ; RB7 - 4 = inputs, RB3 - 0 = output BCF STATUS, RP0 ; Bank 0 RETURN ; ;************************************************************************ ; freq_2_bcd movfw freq_hi movwf MSD movfw freq_lo movwf LSD bcf STATUS,RP0 movlw .16 movwf TEMP1 clrf D_0 clrf D_1 clrf D_2 loop16 rlf LSD,F rlf MSD,F rlf D_2,F rlf D_1,F rlf D_0,F decfsz TEMP1,F goto adjDEC retlw 0 ; adjDEC movlw D_2 movwf FSR call adjBCD ; movlw D_1 movwf FSR call adjBCD ; movlw D_0 movwf FSR call adjBCD ; goto loop16 ; adjBCD movlw 3 addwf 0,W movwf TEMP btfsc TEMP,3 movwf 0 movlw 30 addwf 0,W movwf TEMP btfsc TEMP,7 movwf 0 retlw 0 ; ;********************************************************************** ; dis_freq clrf TEMP1 movlw 0xC0 ; cursor pos voor de frequentie call SEND_CMD movfw D_0 ; alle vijf digits afdrukken call digit swapf D_1,W call digit movfw D_1 call digit swapf D_2,W call digit movfw D_2 call digit return ; digit andlw 0x0F ; mask hi nibb. en set zero-flag btfsc TEMP1,0 ; temp,0=clear> test op leading zero goto dig_2 ; temp,0=set > karakter afdrukken btfss STATUS,Z ; zero-flag=set>onderdruk leading-zero goto dig_1 ; zero-flag=clr>zero wel afdrukken movlw 0xF0 ; onderdruk 0> -10h + 30h = 20h goto dig_2 ; druk karakter af dig_1 bsf TEMP1,0 ; er is een niet-0 karakter geweest dig_2 addlw 0x30 ; bcd to ascii call SEND_CHAR ; naar LCD return ; ; *********************************************************************** ; Table addwf PCL, F ;Jump to char pointed to in W reg retlw 'R' retlw 'X' retlw ' ' retlw 'F' retlw 'R' retlw 'E' retlw 'Q' retlw ':' retlw 0 retlw ' ' retlw ' ' retlw ' ' retlw ' ' retlw 0 ; eind marker regel 1 ; regel twee retlw ' ' retlw ' ' retlw ' ' retlw ' ' retlw ' ' retlw 'M' retlw 'H' retlw 'z' retlw 0 retlw ' ' retlw ' ' retlw ' ' retlw ' ' retlw ' ' retlw ' ' Table_End retlw 0 ; eind marker regel 2 ; ; if ( (Table & 0x0FF) >= (Table_End & 0x0FF) ) MESSG "Warning - User Definded: Table Table crosses page boundry in computed jump" endif ; ; ;************************************************************************ ; ; MAIN org 0x100 ; start main programma clrf PORTA movlw 0x80 ; cursor op eerste regel call SEND_CMD movlw 0 ; eerste txt startadres call dispmsg ; movlw 0xC0 ; cursor op tweede regel call SEND_CMD ; movlw .14 ; tweede txt startadres call dispmsg call lees_eefreq ; haal freq uit eeprom call freq_2_bcd ; zet freq om in bcd waarden call dis_freq ; display freq call reken call set_syn scan_inp btfss PORTB,6 ; rotary encoder up kanaal call up btfss PORTB,7 ; rotary encoder dwn kanaal call dwn btfss PORTB,4 ; toets 1 call key_1 btfss PORTB,5 ; toets 2 call key_2 goto scan_inp ; ;********************************************************************* ; up call delay_1ms ; Is de puls een blijvertje? btfsc PORTB,6 ; return up_90 btfsc PORTB,7 ; wacht op puls van kanaal2 goto up_90 call freq_up ; voer taak uit up_270 btfsc PORTB,7 ; puls van kanaal2 weg? return goto up_270 ; dwn call delay_1ms ; Is de puls een blijvertje? btfsc PORTB,7 ; return dwn_90 btfsc PORTB,6 ; wacht op puls van kanaal1 goto dwn_90 call freq_dwn ; voer taak uit dwn_270 btfsc PORTB,6 ; puls van kanaal1 weg? return goto dwn_270 ; ;************************************************************************* ; freq_up movlw 0x01 ; haal stapgroote addwf freq_lo,F ; en tel op bij freq_lo btfsc STATUS,C ; carry ? incf freq_hi,F ; dan freq_hi ook ophogen call chk_max ; test of max. freq is bereikt call freq_2_bcd ; hex > bcd call dis_freq ; bcd > LCD display call reken ; bepaal synthesiser settings call set_syn return ; freq_dwn movlw 0x01 ; haal stapgroote subwf freq_lo,F ; en trek af van freq_lo btfss STATUS,C ; carry ? decf freq_hi,F ; dan freq_lo ook verlagen call chk_min ; test of min. freq is bereikt call freq_2_bcd ; hex > bcd call dis_freq ; bcd > LCD call reken call set_syn return ; ;********************************************************************* ; chk_max movlw max_hi ; haal max_hi movwf TEMP ; max_hi in temp decf TEMP,F ; correctie subwf movfw freq_hi ; haal freq_hi subwf TEMP,F ; (max_hi-1)-freq_hi btfsc STATUS,C ; > 0: check ook freq_lo return movlw max_lo ; voorlopig max_lo movwf TEMP ; max_lo in temp movfw freq_lo ; haal freq_lo subwf TEMP,F ; max_lo-freq_lo btfsc STATUS,C return movlw min_hi ; freq = minimum movwf freq_hi movlw min_lo movwf freq_lo return ; chk_min movfw freq_hi ; haal freq_hi movwf TEMP ; freq_hi in temp decf TEMP,F ; correctie subwf movlw min_hi ; voorlopig min_hi subwf TEMP,F ; (freq_hi-1)-min_hi btfsc STATUS,C ; > 0: check ook freq_lo return movfw freq_lo movwf TEMP movlw min_lo ; haal min_lo subwf TEMP,F ; freq_lo-min_lo btfsc STATUS,C return movlw max_hi ; freq = maximum movwf freq_hi movlw max_lo movwf freq_lo return ; ;************************************************************************** ; tx_data bcf _rp0 ; naar poort schrijven movf PORTA,W ; oude poort a toestand ophalen andlw 0x03 ; bit 2,3,4 laag movwf PORTA ; bsf _rp0 bcf scl call delay movlw 8 ; acht databits te verzenden movwf iic_teller loop_tx rlf tdata,F ; haal data en schuif een bit in de carry call tx_bit ; verstuur het bit decfsz iic_teller,F ; alle acht gedaan ? goto loop_tx ; volgende bit bsf _rp0 ; scl > laag bcf scl bcf sda bcf _rp0 ; bij verlaten routine naar page 0 terug! return ; tx_bit btfss STATUS,C ; carry=0 > clear sda bcf sda btfsc STATUS,C ; carry=1 > set sda bsf sda bsf scl ; scl hoog > inklokken databit call delay ; bit-tijd bcf scl ; scl laag > einde bit transfer return ; ;****************************************************************************** ; reken movfw freq_lo ; freq naar syn movwf syn_lo movfw freq_hi movwf syn_hi movlw if_lo ; get if low byte addwf syn_lo,F ; tel op bij syn low byte btfsc STATUS,C ; carry =1 > doorschuiven naar incf syn_hi,F ; syn_hi byte movlw if_hi ; get if hi byte addwf syn_hi,F ; tel op bij syn high byte ; ; vermenigvuldiging met 8 ; bcf STATUS,C rlf syn_lo,F ; het is simpel omdat er rlf syn_hi,F ; geen overflow kan optreden. rlf syn_lo,F ; syn mag nooit meer dan 16 bits zijn rlf syn_hi,F rlf syn_lo,F rlf syn_hi,F movlw 0xF8 andwf syn_lo,F ; voor de zekerheid (niet echt nodig) ; ; return ; **************************************************************************** ; set_syn bcf PORTA,2 movfw syn_hi ; verzend de 4 data-bytes movwf tdata call tx_data movfw syn_lo movwf tdata call tx_data bsf PORTA,2 call delay bcf PORTA,2 return ; ;******************************************************************************** ; key_1 call delay_5ms ; dender onderdrukking btfsc PORTB,4 return ; puls was geen blijvertje call save_eefreq _los1 btfsc PORTB,4 ; wacht op loslaten van de toets return goto _los1 ; ;******************************************************************************** ; key_2 call delay_5ms ; dender onderdrukking btfsc PORTB,5 return ; puls was geen blijvertje btfsc ports,4 goto reset_vpol bsf ports,4 _los2 btfss PORTB,5 ; wacht op loslaten van de toets goto _los2 call set_syn return ; reset_vpol bcf ports,4 goto _los2 ; ;************************************************************************ save_eefreq movlw eefreq ; haal adres freq in eeprom movwf eeadr ; set eeprom adres movf freq_lo,w ; haal lo byte freq movwf eedata ; naar eeprom call ee_wr ; schrijfroutine incf eeadr,f ; eeprom volgende adres movf freq_hi,w ; haal hi byte freq movwf eedata call ee_wr ; freq-hi ook wegschrijven return ; ;************************************************************************ ; lees_eefreq movlw eefreq ; adres van freq_lo movwf eeadr ; set eeprom adres call ee_rd ; data nu in eedata movf eedata,w ; data in w movwf freq_lo ; naar freq_lo incf eeadr,f call ee_rd ; nu freq_hi halen movf eedata,w ; data in w movwf freq_hi return ; ; ************************ read eedata ************************************** ee_rd bsf STATUS,RP0 ; page 1 bsf eecon1,rd ; initiate read action bcf STATUS,RP0 return ; return with data in eedata ; ; ************************ write eedata ************************************* ee_wr bsf STATUS,RP0 ; page 1 bsf eecon1,wren ; enable write to eeprom bcf eecon1,eeif ; clear write ready flag movlw 0x55 movwf eecon2 movlw 0xaa movwf eecon2 bsf eecon1,wr ee_wait btfss eecon1,eeif ; wait until write complete goto ee_wait bcf eecon1,wren ; disable writing to eeprom bcf STATUS,RP0 ; back to page 0 again return ; return-data is written in eeprom loc eeadr ; ;******************************************************************************** ; org 2007 db 0x00,0x01 ; set fuses, cp=on,pwrt=on,wdt=off,osc=xt ; org 2100 ; vul eeprom db 0x00,0x05 ; freq 1285 MHz als default db 0x00,0x05 ; END