;list P=18f87K90

    INCLUDE "p18f87K90.inc"
    INCLUDE "LCD.inc"
    INCLUDE "obrazek.inc"
    INCLUDE "menu.inc"
    INCLUDE "obr Pic.inc"
    INCLUDE "Podklad.inc"
    INCLUDE "pouzdro.inc"

; PIC18F87K90 Configuration Bit Settings

; CONFIG1L
  CONFIG  RETEN = ON            ; VREG Sleep Enable bit (Enabled)
  CONFIG  INTOSCSEL = HIGH      ; LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
  CONFIG  SOSCSEL = HIGH        ; SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
  CONFIG  XINST = OFF          ; Extended Instruction Set (Enabled)

; CONFIG1H
  CONFIG  FOSC = INTIO2         ; Oscillator (Internal RC oscillator)
  CONFIG  PLLCFG = OFF          ; PLL x4 Enable bit (Disabled)
  CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor (Disabled)
  CONFIG  IESO = OFF            ; Internal External Oscillator Switch Over Mode (Disabled)

; CONFIG2L
  CONFIG  PWRTEN = OFF          ; Power Up Timer (Disabled)
  CONFIG  BOREN = SBORDIS       ; Brown Out Detect (Enabled in hardware, SBOREN disabled)
  CONFIG  BORV = 3              ; Brown-out Reset Voltage bits (1.8V)
  CONFIG  BORPWR = ZPBORMV      ; BORMV Power level (ZPBORMV instead of BORMV is selected)

; CONFIG2H
  CONFIG  WDTEN = OFF           ; Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
  CONFIG  WDTPS = 8192          ; Watchdog Postscaler (1:8192)

; CONFIG3L
 CONFIG  RTCOSC = SOSCREF    ; RTCC Clock Select (RTCC uses INTRC)

; CONFIG3H
  CONFIG  CCP2MX = PORTC        ; CCP2 Mux (RC1)
  CONFIG  ECCPMX = PORTH        ; ECCP Mux (Enhanced CCP1/3 [P1B/P1C/P3B/P3C] muxed with RH7/RH6/RH5/RH4)
  CONFIG  MSSPMSK = MSK7        ; MSSP address masking (7 Bit address masking mode)
  CONFIG  MCLRE = ON            ; Master Clear Enable (MCLR Enabled, RG5 Disabled)

; CONFIG4L
  CONFIG  STVREN = ON           ; Stack Overflow Reset (Enabled)
  CONFIG  BBSIZ = BB2K          ; Boot Block Size (2K word Boot Block size)

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protect 00800-03FFF (Disabled)
  CONFIG  CP1 = OFF             ; Code Protect 04000-07FFF (Disabled)
  CONFIG  CP2 = OFF             ; Code Protect 08000-0BFFF (Disabled)
  CONFIG  CP3 = OFF             ; Code Protect 0C000-0FFFF (Disabled)
  CONFIG  CP4 = OFF             ; Code Protect 10000-13FFF (Disabled)
  CONFIG  CP5 = OFF             ; Code Protect 14000-17FFF (Disabled)
  CONFIG  CP6 = OFF             ; Code Protect 18000-1BFFF (Disabled)
  CONFIG  CP7 = OFF             ; Code Protect 1C000-1FFFF (Disabled)

; CONFIG5H
  CONFIG  CPB = OFF             ; Code Protect Boot (Disabled)
  CONFIG  CPD = OFF             ; Data EE Read Protect (Disabled)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Table Write Protect 00800-03FFF (Disabled)
  CONFIG  WRT1 = OFF            ; Table Write Protect 04000-07FFF (Disabled)
  CONFIG  WRT2 = OFF            ; Table Write Protect 08000-0BFFF (Disabled)
  CONFIG  WRT3 = OFF            ; Table Write Protect 0C000-0FFFF (Disabled)
  CONFIG  WRT4 = OFF            ; Table Write Protect 10000-13FFF (Disabled)
  CONFIG  WRT5 = OFF            ; Table Write Protect 14000-17FFF (Disabled)
  CONFIG  WRT6 = OFF            ; Table Write Protect 18000-1BFFF (Disabled)
  CONFIG  WRT7 = OFF            ; Table Write Protect 1C000-1FFFF (Disabled)

; CONFIG6H
  CONFIG  WRTC = OFF            ; Config. Write Protect (Disabled)
  CONFIG  WRTB = OFF            ; Table Write Protect Boot (Disabled)
  CONFIG  WRTD = OFF            ; Data EE Write Protect (Disabled)

; CONFIG7L
  CONFIG  EBRT0 = OFF           ; Table Read Protect 00800-03FFF (Disabled)
  CONFIG  EBRT1 = OFF           ; Table Read Protect 04000-07FFF (Disabled)
  CONFIG  EBRT2 = OFF           ; Table Read Protect 08000-0BFFF (Disabled)
  CONFIG  EBRT3 = OFF           ; Table Read Protect 0C000-0FFFF (Disabled)
  CONFIG  EBRT4 = OFF           ; Table Read Protect 10000-13FFF (Disabled)
  CONFIG  EBRT5 = OFF           ; Table Read Protect 14000-17FFF (Disabled)
  CONFIG  EBRT6 = OFF           ; Table Read Protect 18000-1BFFF (Disabled)
  CONFIG  EBRT7 = OFF           ; Table Read Protect 1C000-1FFFF (Disabled)

; CONFIG7H
  CONFIG  EBRTB = OFF           ; Table Read Protect Boot (Disabled)

errorlevel -226

;LCD piny
;POCET_RAD EQU	64
LCD_DATA EQU LATE
#define RS_LCD	LATA,6	    ;CD B,4
#define CLK_LCD	LATB,5
#define RW_LCD LATD,0
#define RST_LCD LATH,3
#define CS_LCD LATH,2
#define BMI0_LCD LATF,1
#define BMI1_LCD LATH,5
 
;Analog piny
;RELÉ
#define REL_ANTIAL LATG,0
#define REL_DESET_STO LATC,7
#define REL_JEDNA_DESET LATC,6
#define REL_50Z LATH,0
#define REL_AC_DC LATB,2
#define REL_X5 LATB,3
#define REL_X2 LATD,2
#define REL_GND LATB,4 
;signály
#define SIG_SCK LATD,6	;x
#define SIG_SDI LATD,4
#define SIG_NEG_CS_DAC LATD,7 ;SS2

#define SIG_NEG_LDAC LATD,3
#define SIG_NEG_CS_CLK LATD,1
#define SIG_OE_CLK LATG,1
#define RSEL_AD LATA,7

AD_DATA EQU LATJ

    CBLOCK	0x00
    ;96bajt 
    Si
    H
    cita
    G
    Je
    u
    poc
    RCOUNT
    PET
    ckl
    POZI
    PLICH
    PLICH0
    RADEK
    bayt
    T_base_v
    T_base_n
    Menu_osc
    LCDon
    MEZ1
    X
    Xl
    Y
    MEZ
    STAT
    STACKH
    STACKH0
    POS
    TEplota
    T_Base_ML
    T_Base_MH
    VERTIZES
    VERTIZES2
    bin0
    bin1
    CRAD
    DecCount
    BitCount
    digit0
    digit1
    digit2
    digit3
    digit4
    cant
    soucet
    soucetH
    soucetU
    PWMl
    PWMh
    paml
    pamh
    pamu
    svetloH
    svetloL
    znaminko
    BSR_TEMP
    STATUS_TEMP
    W_TEMP
    Adresa
    svetRh
    svetRl
    obrC
    obrR
    konfi
    konfi1
    CAR
    TLACIT
    PRIZNAK
    BAR
    vzorek0
    nastav0
    COUNT
    COUNTH
    vzorek
    vzorekH
    STACKHP
    PLICHP
    RAD
    SLOUP
    TRIGR
    contL
    contH
    PAMFSR0L
    PAMFSR0H
    PFSR0L
    PFSR0H
    TRIGRH
    zobrazT
    zdtrig
    optiontrig
    CONTRAST
    casovka
    vzorek1
    rozdil
    opakovac
    TLACITKA1
    POSS
    POSUN

 ;data
    tlac1
    tlac2
    tlac3
    tlac4
    tlac5
    tlac6
    POSUVNIK
    del1l
    del1h
    del2l
    del2h
    Lpoz
    Ppoz
    SHIFT
    Sdel
    obrmenu
    Menul
    Menuh
    Menur
    offset_H
    offset_L
    TB_SET
    PMP_CNT
    OPT_set
    RUN_MODE
    SHIFT_sig
    TRIG_lvl
    Menu_osc2
    X2
    RADEK2
    DRUH
    TB_SET2
    DATA_MULTI
    DATA_MULTI_STRED
    DATA_MULTI_MAX
    DATA_MULTI_MIN
    DATA_MULTI_OV
	ENDC


    ORG	0x00
	goto Next

    ORG	0x08   ;high
	MOVWF	W_TEMP ; W_TEMP is in virtual bank
	MOVFF	STATUS, STATUS_TEMP ; STATUS_TEMP located anywhere
	MOVFF	BSR, BSR_TEMP ; BSR_TMEP located anywhere
	goto	Prerus

    ORG	0x18    ;low

	MOVWF	W_TEMP ; W_TEMP is in virtual bank
	MOVFF	STATUS, STATUS_TEMP ; STATUS_TEMP located anywhere
	MOVFF	BSR, BSR_TEMP ; BSR_TMEP located anywhere
;	BRA	PrerusL

;OBSLUHA PRERUSENI
;-------------------------------------------------------
PrerusL
    bcf	    PIR1,ADIF
    
    btfsc   PIR1,SSP1IF
    goto    SPI
    goto    kon

;;    btfsc   ADRESL,0
;;    clrf    ADRESH
;
;;0,64V
;    movf    ADRESH,0
;    btfsc   ADRESH,7
;    movlw   01111111b
;
;;    btfss    optiontrig,0
;;1,28V
;;    RRNCF   ADRESH,0
;;  nabez
;;    btfss   PORTA,7
;;    goto    nabez
;;  sestup
;;    btfsc   PORTA,7
;;    goto    sestup
;    ;-----------
;    andlw   01111111b
;    addlw   1
;   
;    movwf   POSTINC0
;    movwf   POSTINC1
;
;    incf    vzorek,1
;    btfsc   STATUS,C
;    incf    vzorekH,1
;
;;   btfss   vzorekH,1
;    movf    vzorekH,0
;    xorlw   3
;    btfss   STATUS,Z
;    goto    kon
;
;    clrf    vzorekH
;    clrf    vzorek
;    bcf     PIE1,ADIE   ;zakáze přerusení od AD
;    bcf     ADCON0,0
;
;    bcf     T1CON,TMR1ON
;
;    INCF    COUNT,1
;    BTFSC   STATUS,C
;    INCF    COUNTH,1
;    goto    kon

Prerus
    btfsc   INTCON,INT0IF
    goto    PMP 
;    btfsc   PIR1,TMR1IF
;    goto    TMR
    goto    kon

SPI
    MOVFF   FSR0L,PFSR0L
    MOVFF   FSR0H,PFSR0H
    bcf	    PIR1,SSP1IF
    MOVLB   0
    MOVF    POSUN,0,1
    ADDLW   tlac1   ;zacatek adresy pro príjem dat
    MOVWF   FSR0L
    CLRF    FSR0H

    btfsc   POSS,1
    goto    tlact

    btfsc   POSS,0
    goto    posuvs

    MOVF    SSP1BUF, W
    xorlw   00000000b
    btfsc   STATUS,Z
    reset

    MOVF    SSP1BUF, W
    xorlw   11111111b
    btfsc   STATUS,Z
    goto    vyp

    MOVF    SSP1BUF, W
    xorlw   11100000b
    btfsc   STATUS,Z
    bsf	    POSS,1

    MOVF    SSP1BUF, W 
    xorlw   00011100b
    btfsc   STATUS,Z
    goto    adresuj
    goto    konec
    
vyp
    bcf RST_LCD
    goto    konec

    bcf	    RS_LCD
    movlw   10101110b	;8b ;se mirorors
    call    CL
    bsf	    RS_LCD
    clrf    CCPR4,1
    goto    konec
    
tlact
    MOVF    SSP1BUF, W 
    MOVWF   TLACITKA1 
    clrf    SSP1BUF
    clrf    POSS
    goto    konec

adresuj
    bsf	    POSS,0
    CLRF    POSUN,1
    clrf    SSP1BUF
    goto    konec

posuvs
     MOVF   SSP1BUF,W	;WREG reg = contents of SSP1BUF
     MOVWF  INDF0	;POSTINC0 ;Save
     INCF   POSUN,1,1
     clrf   SSP1BUF

     movf   POSUN,0,1
     xorlw  15		;pocet bajtu
     btfsc  STATUS,Z
     goto   potak
     goto   konec

potak
     MOVF   SHIFT,0,1
     MOVWF  TLACITKA1
     clrf   POSS
     goto   konec

;TMR
;    bcf     PIR1,TMR1IF
;    movf    contH,0
;    movwf   TMR1H
;    movf    contL,0       ;9C
;    movwf   TMR1L
;    
;    decfsz    COUNT,1
;    goto konec
;    
;    movlw   5
;    movwf   COUNT
;    clrf    vzorekH
;    clrf    vzorek
;    bcf	    TB_SET,1,1
;    LFSR    0,0x400
;    LFSR    1,0x700
;;    bsf	    Si,2
;
;;    bcf     INTCON,INT0IE
;;    bsf     PIE1,SSP1IE
;    ;--------------------------------
;    bcf     T1CON,TMR1ON
;    goto konec
    
PMP
    setf    TRISJ  
    bcf     INTCON,INT0IF
    MOVLB	0

    btfsc   PORTB,1 ;pokud je nastaveno odesilani
    goto    TB_send ;odesle data
    
    btfsc   TB_SET,1,1
    goto    AD_READ
    
    btfsc   TB_SET2,0,1
    goto    MULTI_READ
    
    btfsc   TB_SET2,1,1
    goto    MULTI_READ_STRED
    
    btfsc   TB_SET2,2,1
    goto    MULTI_READ_MAX
    
    btfsc   TB_SET2,3,1
    goto    MULTI_READ_MIN
    
    btfsc   TB_SET2,4,1
    goto    MULTI_READ_OV
    
    clrf    TB_SET,1  ;vymaze příznak primu
    clrf    TB_SET2,1
    clrf    PMP_CNT,1

PMP_start 
    
    movf    PORTJ,0
    xorlw   01010101b	;ZJISTÍ DRUH PRIKAZU - TB
    btfsc   STATUS,Z
    goto    kon_1  
    
    movf    PORTJ,0
    xorlw   100		;ZJISTÍ DRUH PRIKAZU - trigr
    btfsc   STATUS,Z
    goto    kon_2  
    
    movf    PORTJ,0
    xorlw   99		;ZJISTÍ DRUH PRIKAZU - Run mode
    btfsc   STATUS,Z
    goto    kon_3  
    
    movf    PORTJ,0
    xorlw   98		;ZJISTÍ DRUH PRIKAZU - shift
    btfsc   STATUS,Z
    goto    kon_4  
    
    movf    PORTJ,0
    xorlw   97		;ZJISTÍ DRUH PRIKAZU - trig-lvl
    btfsc   STATUS,Z
    goto    kon_5  
    
    movf    PORTJ,0
    xorlw   96		;ZJISTÍ DRUH PRIKAZU - odesli DRUH
    btfsc   STATUS,Z
    goto    kon_6  
    
    movf    PORTJ,0
    xorlw   95		;ZJISTÍ DRUH PRIKAZU - prijmi RMS 
    btfsc   STATUS,Z
    goto    kon_7  
    
    movf    PORTJ,0
    xorlw   94		;ZJISTÍ DRUH PRIKAZU - prijmi AVG  
    btfsc   STATUS,Z
    goto    kon_8 
    
    movf    PORTJ,0
    xorlw   93		;ZJISTÍ DRUH PRIKAZU - prijmi MAX 
    btfsc   STATUS,Z
    goto    kon_9
    
    movf    PORTJ,0
    xorlw   92		;ZJISTÍ DRUH PRIKAZU - prijmi MIN 
    btfsc   STATUS,Z
    goto    kon_10
    
    movf    PORTJ,0
    xorlw   91		;ZJISTÍ DRUH PRIKAZU - prijmi OV 
    btfsc   STATUS,Z
    goto    kon_11
    
    movf    PORTJ,0
    xorlw   10101010b	 ;ZJISTÍ DRUH PRIKAZU - posli data z AD
    btfss   STATUS,Z
    goto    kon
    
;    bsf     T1CON,TMR1ON
    bsf	    TB_SET,1,1
    goto    kon
    
MULTI_READ_MAX
    movf    PORTJ,0
    movwf   DATA_MULTI_MAX,1
    bcf	    TB_SET2,2,1
    goto    kon
    
MULTI_READ_OV
    movf    PORTJ,0
    movwf   DATA_MULTI_OV,1
    bcf	    TB_SET2,4,1
    bsf	    DATA_MULTI_OV,2,1
    
    bcf     INTCON,INT0IE
    goto    kon
    
MULTI_READ_MIN
    movf    PORTJ,0
    movwf   DATA_MULTI_MIN,1
    bcf	    TB_SET2,3,1   
    goto    kon
    
MULTI_READ_STRED
    movf    PORTJ,0
    movwf   DATA_MULTI_STRED,1
    bcf	    TB_SET2,1,1   
    goto    kon
    
MULTI_READ
    movf    PORTJ,0
    movwf   DATA_MULTI,1
    bcf	    TB_SET2,0,1
    goto    kon
    
AD_READ     
 ;externí a/d
    RRCF    PORTJ,0
    btfsc   Si,6    ;prepne rozsah z 2V na 1V (7b)
    goto    Rozsah_1V
    
Rozsah_2V_SHIFT   
    movf    PORTJ,0
    movwf   bayt
       
    btfss   bayt,7
    bra	    dole
    
    btfsc   bayt,6
    bra	    nahore_7
    bra	    nahore_6
dole    
    btfss   bayt,6
    bra	    dole_76
nahore_6    
    bcf	    bayt,6
    btfsc   bayt,7
    bsf	    bayt,6
Rozsah_2V    
    bcf	    bayt,7

    movlw   2
    addwf   bayt,1
    movf    bayt,0
    SUBLW   127
    movf    bayt,0
    BTFSS   STATUS,C
nahore_7
    MOVLW   10000000b
    bra	    nacti
dole_76
    MOVLW   00000000b
    andlw   01111111b
       
Rozsah_1V   
    andlw   01111111b
    addlw   1
    
nacti
    movwf   POSTINC0
    movwf   POSTINC1

    incf    vzorek,1
    btfsc   STATUS,C
    incf    vzorekH,1

    movf    vzorek,0
    xorlw   202
    btfss   STATUS,Z
    goto    kon

    clrf    vzorekH
    clrf    vzorek
    bcf	    TB_SET,1,1
   ; bcf     PIE1,ADIE   ;zaká?e přeru?ení od AD

;    bcf     T1CON,TMR1ON
;    movf    contH,0 
;    movwf   TMR1H
;    movf    contL,0       ;9C
;    movwf   TMR1L
;    
;    bsf	    Si,2

    bcf     INTCON,INT0IE
    bsf     PIE1,SSP1IE

kon
    MOVFF   BSR_TEMP, BSR ; Restore BSR
    MOVF    W_TEMP, W ; Restore WREG
    MOVFF   STATUS_TEMP, STATUS ; Restore STATUS
    retfie
    
kon_1
    bsf	    TB_SET,0,1
    bsf	    TB_SET,2,1
    goto    kon
    
kon_2
    bsf	    TB_SET,3,1
    bsf	    TB_SET,0,1
    goto    kon
    
kon_3
    bsf	    TB_SET,4,1
    bsf	    TB_SET,0,1
    goto    kon
    
kon_4
    bsf	    TB_SET,5,1
    bsf	    TB_SET,0,1
    goto    kon
    
kon_5
    bsf	    TB_SET,6,1
    bsf	    TB_SET,0,1
    goto    kon
    
kon_6
    bsf	    TB_SET,7,1
    bsf	    TB_SET,0,1
    goto    kon
    
kon_7
    bsf	    TB_SET2,0,1
    goto    kon
    
kon_8 
    bsf	    TB_SET2,1,1
    goto    kon
    
kon_9 
    bsf	    TB_SET2,2,1
    goto    kon
    
kon_10
    bsf	    TB_SET2,3,1
    goto    kon
    
kon_11
    bsf	    TB_SET2,4,1
    goto    kon
    
TB_send
    bcf	    TB_SET,1,1
    clrf    TRISJ
	
;    btfss   TB_SET,0,1
;    GOTO    PMP_START
    
    btfsc   TB_SET,3,1
    GOTO    PMP_TRIG
    
    btfsc   TB_SET,4,1
    GOTO    RUN_MOD
    
    btfsc   TB_SET,5,1
    GOTO    SHIFT_s
    
    btfsc   TB_SET,6,1
    GOTO    TRIGG_lvl
    
    btfsc   TB_SET,7,1
    GOTO    DRUH_send
    
    btfsc   TB_SET,2,1
    goto    VA_con
    
        GOTO    PMP_START
    
    clrf    LATJ
    GOTO    kon
VA_con 
    incf    PMP_CNT,1,1
    
    movf    PMP_CNT,0,1
    xorlw   2
    btfsc   STATUS,Z
    goto    T_B_n
;    
;    
    movf    T_base_v,0
    movwf   LATJ
    goto    kon
T_B_n    
    movf    T_base_n,0
    movwf   LATJ
    goto    kon
    
PMP_TRIG
    movf    zdtrig,0
    movwf   LATJ
    goto    kon
    
PMP_START
    movlw   150
    movwf   LATJ
    goto    kon
    
RUN_MOD
    movf    RUN_MODE,0,1
    movwf   LATJ
    goto    kon
    
SHIFT_s
    movf    SHIFT_sig,0,1
    movwf   LATJ
    goto    kon
    
TRIGG_lvl
    movf    TRIG_lvl,0,1
    movwf   LATJ
    goto    kon
    
DRUH_send
    movf    DRUH,0,1
    movwf   LATJ
    goto    kon
    
konec
    MOVFF  PFSR0L,FSR0L
    MOVFF  PFSR0H,FSR0H

    MOVFF BSR_TEMP, BSR ; Restore BSR
    MOVF W_TEMP, W ; Restore WREG
    MOVFF STATUS_TEMP, STATUS ; Restore STATUS
    retfie
  
 
    
;INYCIALIZACE
Next
    movlb   0
    CLRF    PORTA   ; Initialize PORTA by
    CLRF    PORTJ
    CLRF    PORTB
    CLRF    PORTC
    CLRF    PORTD
    CLRF    PORTE
    CLRF    PORTH
    CLRF    PORTG
    CLRF    PORTF   ; Initialize PORTF by
    CLRF    LATA    ; Alternate method to
    setf    LATJ
    CLRF    LATE
    CLRF    LATB
    CLRF    LATD
    CLRF    LATC
    CLRF    LATH
    CLRF    LATG
    CLRF    LATF    ; Alternate method
    clrf    TLACITKA1
    clrf    POSUVNIK
    clrf    POSS
    
    clrf    offset_H,1
    clrf    offset_L,1
    CLRF    DRUH,1
    clrf    zobrazT
    
    clrf    T_Base_ML
    clrf    T_Base_MH
    
    clrf    TB_SET,1
    clrf    TB_SET2,1
    clrf    OPT_set,1
    bsf	    OPT_set,0,1
    clrf    RUN_MODE,1
    bsf	    RUN_MODE,2,1    
    movlw   127
    movwf   TRIG_lvl,1
    clrf    DATA_MULTI_STRED,1
    clrf    DATA_MULTI,1
    clrf    DATA_MULTI_MAX,1
    clrf    DATA_MULTI_OV,1
    clrf    DATA_MULTI_MIN,1
    
    movlw   5
    movwf   COUNT
    
    clrf    Menu_osc2,1
    bsf	    Menu_osc2,0,1
    
    movlw   0
    movwf   SHIFT_sig
    
    movlw   4
    movwf   T_base_v
    clrf    T_base_n
    clrf    Menu_osc
    bsf     Menu_osc,4
    
    BCF REL_ANTIAL
    BCF REL_50Z
    BCF REL_AC_DC
    BCF REL_X5
    BCF REL_X2
    BCF REL_DESET_STO
    BCF REL_JEDNA_DESET
    BsF	REL_GND
      
    bsf RST_LCD
    bsf	CS_LCD
    bsf	BMI0_LCD
    bsf	BMI1_LCD
    
    bcf	RSEL_AD
 
    bsf SIG_SCK 
    bsf SIG_SDI

    BsF SIG_NEG_CS_DAC	;off
    BSF SIG_NEG_LDAC	;lath
    BsF SIG_NEG_CS_CLK	;off
    ;zapnout na 3,3V
    BsF SIG_OE_CLK  ;1-on , 0-off

    
    clrf    VERTIZES
    clrf    VERTIZES2
    bsf	    VERTIZES2,2
    
    BANKSEL	ANCON1
    MOVLW	10111111b   ; Configure A/D; 11111101b
    MOVWF	ANCON0,1    ; for digital inputs
    MOVLW	11011111b   ; Configure A/D; 11111101b
    MOVWF	ANCON1,1    ; for digital inputs
    MOVLW	11001111b   ; Configure A/D
    MOVWF	ANCON2,1    ; Set PORTF as anal I/O
    movlw	00111111b
    MOVWF	TRISA
;    clrf	TRISJ
    setf	TRISJ
    movlw	01010010b
    MOVWF	TRISH
    movlw	00100000b
    MOVWF	TRISD
    movlw	11111001b
    MOVWF	TRISF
    movlw	00011111b
    MOVWF	TRISC
    movlw	11110000b
    MOVWF	TRISG
    MOVLW	10000011b
    MOVWF	TRISB
    clrf	TRISE

    CLRF	PRIZNAK
    movlw	6	;dekla znaku
    movwf	PET
    

    
;nastavení hodin
;   BSF		OSCCON2,MFIOSEL
    bsf		OSCCON,IRCF0
    bsf		OSCTUNE,PLLEN	;zapne PLL (x4)
;   bsf		OSCTUNE,INTSRC	;zdroj 31khz
;   bcf		OSCCON,IRCF2
;   bcf		OSCCON,IRCF1

;natsavení SPI 1
    movlw   00110101b ;s SS, idle to high
    movwf   SSP1CON1
    bsf     PIE1,SSP1IE ;zapne přerąení od SPI
    bcf     IPR1,SSP1IP ; low priority
;natsavení SPI 2
    movlb   14
    movlw   00110001b ;s SS, idle to high
    movwf   SSP2CON1,1

;nastaveni hodin pro ex. AD na 10khz
    
    movlb	15
    BCF		SIG_NEG_CS_CLK
    call	smycka
    movlw	0x75
    MOVWF	SSP2BUF,1
    call	smycka

    movlw	0x6A
    MOVWF       SSP2BUF,1
    call	smycka
    BSF		SIG_NEG_CS_CLK
    movlb	0
;***********************************
    CLRF    STAT
    CLRF    Si
    bsf Si,6
    bsf	    Si,2
    CLRF    TLACIT
    BSF	    TLACIT,0
    bsf     INTCON2,7	;pull-upp 0-on,1-off

;pwm pro LCD podsvit
    MOVLB	15
    movlw	00001111b
    movwf	CCP4CON,1	;banka 15  nutná zmena na jiný port

;   bcf		PADCFG1,RJPU,1
    bcf		CCPTMRS1,0,1
    bcf		CCPTMRS1,1,1
;   bcf		CONFIG3H,ECCPMX
    movlw	255	
    movwf	PR2
    movlw	00000101b
    movwf	T2CON

    movlw	170
    movwf	CONTRAST

    movlw	110
    movwf	svetloL
    movlw	1
    movwf	svetloH

    CLRF	vzorek0
    clrf	vzorekH

    movf	svetloL,0
    movwf	CCPR4,1

    movlw   0xFF
    movwf   contL
    movlw   0xFF
    movwf   contH
    movlw   5
    movwf   casovka

    movlw 0x55
    movwf EECON2
    movlw 0xAA
    movwf EECON2
    bsf RTCCFG,RTCWREN,1

;    nop
;    nop
    bsf	RTCCFG,7,1
    bsf	RTCCFG,2,1
;   bsf	RTCCFG,0,1
;   bcf	RTCCFG,1,1
    
;nastaveni casu RTC
    bsf	RTCCFG,0,1
    bsf	RTCCFG,1,1
    movlw	0x16	;rok
    movwf	RTCVALL,1
;   movlw	0x42	;mesic
    movwf	RTCVALH,1
    movlw	0x26	;den
    movwf	RTCVALL,1
    movlw	0x2	;mesic
    movwf	RTCVALH,1

    movlw	0x15	;hodiny
    movwf	RTCVALL,1
    bcf		RTCCFG,0,1
    movlw	0x30	;minuty
    movwf	RTCVALH,1
    movlw	0x00	;sekundy
    movwf	RTCVALL,1

    movlw	10000000b	;kalibrace
    movwf	RTCCAL,1

;nastavení PMP    
    movlw   11000000b
    movwf   INTCON
    bcf	    INTCON,INT0IF
    
;NASTAVENÍ TIMER1

    MOVLW   00110110b          ; CLK PRE 1:1
    MOVWF   T1CON

    MOVLW   01001000b
    MOVWF   T1GCON
    bcf     T1CON,TMR1ON
    BSF	    RCON,IPEN     ;zapne priorytu prerus

;    movlw   11000000b
;    movwf   INTCON

    BSF     PIE1,TMR1IE
    BSF     IPR1,TMR1IP     ;high prioritz TMR1
    BCF     IPR1,ADIP     ;low prioritz AD

    LFSR    0,0x400
    clrf    nastav0
    movlw   00001000b
    movwf     zdtrig
    clrf    optiontrig
    MOVLB 0
    bcf obrmenu,0,1
    movlw   240
    movwf    Menuh,1
    movlw   160
    movwf    Menul,1
    bcf      Menur,0,1
    call	smyckaL
    
    movlw   10
    movwf   T_Base_ML
    call    odesli_SPI2_off
    
;    call	VA_10m
;	movlw	10000100b
;	movwf	T0CON
;	bsf	RCON,IPEN
;	bsf	INTCON2,TMR0IP	;high prioryty

;Program
;----------------------------------------------------
Start
    
    call	LCD
    CALL	VYCISTIT

    movlw	0x35		;adresa
    call	obrazek
    call	smyckaLL	;délka zobrazení

    movlw	0x65		;adresa
    call	obrazek
    call	smyckaLL	;délka zobrazení
    call	smyckaLL

Program
    movlb   0
    call	Zobraz
    call	Tlacitka
    goto	Program
;-------------------------------------------------------
Zobraz

    btfsc	TLACIT,0
    goto	MENU

    btfsc	TLACIT,1
    GOTO	OSCILOSKOP
      	
    btfsc	TLACIT,2
    GOTO	Multimetr

    btfsc	TLACIT,3
    GOTO	Posuv	    ;FFT

    btfsc	TLACIT,4
    GOTO	Napaj

    btfsc	TLACIT,5
    GOTO	zkouska

    btfsc	TLACIT,6
    GOTO	Paraler
;
    return
;-------------------------------------------------------
Napaj
    btfss	PRIZNAK,7
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,7

    bCf		RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf		RS_LCD

    MOVLB	0
    btg		obrmenu,0,1

    call	PISARI
    de		8,15,80,"Napajeni"

    call	PODTRHNI
    de		239,13,0,3  ;po?et,?ádek,start,typ


    call	PISM
    de		16,10,40,"Napětí baterie: "
    call	napeti
;	movf	digit3,0
;	call	PI
    movf	digit2,0
    call	PI
    movlw	","
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	"V"
    call	PI

    call	PISM
    de		18,9,40,"Max. napětí: 8,4V "

    call	PISM
    de		18,8,40,"Min. napětí: 6,0V "

    call	smyckaL
    call	smyckaL
    return

FFT
    btfss	PRIZNAK,6
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,6

    bCf	    	RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf		RS_LCD
	
    MOVLB	0
    btg		obrmenu,0,1

    call	PISARI
    de		3,15,100,"FFT"

    call	PODTRHNI
    de		239,13,0,3  ;pocet,rádek,start,typ

    call	PISM
    de		23,11,50,"Funkce není k dispozici"
    return

Multimetr
    btfss	PRIZNAK,5
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,5

    bCf		RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf		RS_LCD
   
    MOVLB	0
    btg		obrmenu,0,1

    call	PISARI
    de		9,15,80,"Multimetr"

    call	PODTRHNI
    de		240,13,0,3  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		117,3,2,3  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		117,3,121,3  ;pocet,rádek,start,typ
    
    
    call	PODTRHNI
    de		117,0,2,192  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		117,0,121,192  ;pocet,rádek,start,typ
    
    
    call	PODTRHNI
    de		2,3,119,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,2,119,255  ;pocet,rádek,start,typ 
    
    call	PODTRHNI
    de		2,1,119,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,0,119,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,3,0,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,2,0,255  ;pocet,rádek,start,typ 
    
    call	PODTRHNI
    de		2,1,0,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,0,0,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,3,238,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,2,238,255  ;pocet,rádek,start,typ 
    
    call	PODTRHNI
    de		2,1,238,255  ;pocet,rádek,start,typ
    
    call	PODTRHNI
    de		2,0,238,255  ;pocet,rádek,start,typ
    
    call	PISM
    de	14,12,77,"Měření napětí "
    
    call	PISARI
    de		4,12,5,"RMS:"

;    call	PODTRHNI
;    de		239,13,0,3  ;pocet,rádek,start,typ
    
    bsf	    DRUH,0,1
    bcf	    INTCON,INT0IF
    bsf	    INTCON,INT0IE
    
    
    btfss   DATA_MULTI_OV,2,1
    return
    bcf	    DATA_MULTI_OV,2,1
    
    btfsc   DATA_MULTI_OV,1,1
    call    VA_set_P
    
    btfsc   DATA_MULTI_OV,0,1
    call    VA_set_L
    
    movlw   5
    movwf   RADEK2,1
    movlw   0
    movwf   X2,1
    
    movlw   25
    btfsc   VERTIZES,2
    movlw   50
    btfsc   VERTIZES,5
    movlw   50
    btfsc   VERTIZES2,0
    movlw   50
    btfsc   VERTIZES2,3
    movlw   50

    mulwf   DATA_MULTI,1
    
    movf    PRODL,0 
    movwf   soucet 
    movf    PRODH,0
    movwf   soucetH
    movlw   0
    btfsc   VERTIZES,3
    movlw   1
    btfsc   VERTIZES,6
    movlw   1
    btfsc   VERTIZES2,1
    movlw   1
    movwf   cant
    call    posun1
    
    call    cisla
    
    call	PISM
    de	5,2,20,"Avg: "

    movf	DATA_MULTI_STRED,0,1
    btfss	DATA_MULTI_STRED,7,1
    comf	DATA_MULTI_STRED,0,1 
    btfss	DATA_MULTI_STRED,7,1
    addlw	1
    andlw    01111111b
    
    mullw   25
    btfsc   VERTIZES,2
    mullw   50
    btfsc   VERTIZES,5
    mullw   50
    btfsc   VERTIZES2,0
    mullw   50
    btfsc   VERTIZES2,3
    mullw   50
    
    movf    PRODL,0 
    movwf   soucet 
    movf    PRODH,0
    movwf   soucetH
    movlw   0
    btfsc   VERTIZES,3
    movlw   1
    btfsc   VERTIZES,6
    movlw   1
    btfsc   VERTIZES2,1
    movlw   1
    movwf   cant
    call    posun1

    call    covert

    movlw	"-"
    btfss	DATA_MULTI_STRED,7,1
    call	PI
    movf	digit3,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,6
    call	PI
    btfsc   VERTIZES,7
    call	PI	
    btfsc   VERTIZES2,0
    call	PI
    
    movf	digit2,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    btfsc   VERTIZES2,3
    call	PI
    btfsc   VERTIZES2,1
    call	PI	
    btfsc   VERTIZES2,2
    call	PI
    
    movf	digit1,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    
    movf	digit0,0
    call	PI
    
    movlw	"m"
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    
    movlw	"V"
    call	PI
    movlw	" "
    call	PI
    
    call	PISM
    de	5,2,140,"Max: "
    
    movf	DATA_MULTI_MAX,0,1
    btfss	DATA_MULTI_MAX,7,1
    comf	DATA_MULTI_MAX,0,1 
    btfss	DATA_MULTI_MAX,7,1
    addlw	1

    andlw    01111111b
    mullw   25
    btfsc   VERTIZES,2
    mullw   50
    btfsc   VERTIZES,5
    mullw   50
    btfsc   VERTIZES2,0
    mullw   50
    btfsc   VERTIZES2,3
    mullw   50
    
    movf    PRODL,0 
    movwf   soucet 
    movf    PRODH,0
    movwf   soucetH
    movlw   0

    btfsc   VERTIZES,3
    movlw   1
    btfsc   VERTIZES,6
    movlw   1
    btfsc   VERTIZES2,1
    movlw   1
    movwf   cant
    call    posun1
    
    call    covert

    movlw	"-"
    btfss	DATA_MULTI_MAX,7,1
        call	PI
    movf	digit3,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,6
    call	PI
    btfsc   VERTIZES,7
    call	PI	
    btfsc   VERTIZES2,0
    call	PI
    
    movf	digit2,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    btfsc   VERTIZES2,3
    call	PI
    btfsc   VERTIZES2,1
    call	PI	
    btfsc   VERTIZES2,2
    call	PI
    
    movf	digit1,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    
    movf	digit0,0
    call	PI
    
    movlw	"m"
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    
    movlw	"V"
    call	PI
    movlw	" "
    call	PI

    call	PISM
    de	5,1,140,"Min: "
    
    movf	DATA_MULTI_MIN,0,1
    btfss	DATA_MULTI_MIN,7,1
    comf	DATA_MULTI_MIN,0,1 
;    btfss	DATA_MULTI_MIN,7,1
;    addlw	1
;    btfsc   STATUS,C
;    addlw   2
    
    andlw    01111111b
    mullw   25
    btfsc   VERTIZES,2
    mullw   50
    btfsc   VERTIZES,5
    mullw   50
    btfsc   VERTIZES2,0
    mullw   50
    btfsc   VERTIZES2,3
    mullw   50
    
    movf    PRODL,0 
    movwf   soucet 
    movf    PRODH,0
    movwf   soucetH
    movlw   0
    btfsc   VERTIZES,3
    movlw   1
    btfsc   VERTIZES,6
    movlw   1
    btfsc   VERTIZES2,1
    movlw   1
    movwf   cant
    call    posun1
    
    call    covert

    movlw	"-"
    btfss	DATA_MULTI_MIN,7,1
    call	PI
    movf	digit3,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,6
    call	PI
    btfsc   VERTIZES,7
    call	PI	
    btfsc   VERTIZES2,0
    call	PI
    
    movf	digit2,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    btfsc   VERTIZES2,3
    call	PI
    btfsc   VERTIZES2,1
    call	PI	
    btfsc   VERTIZES2,2
    call	PI
    
    movf	digit1,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    
    movf	digit0,0
    call	PI
    
    movlw	"m"
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    
    movlw	"V"
    call	PI
    movlw	" "
    call	PI
    
;    movf	DATA_MULTI_OV,0,1
;    andlw	3
;    call	PI
    
    movlw	" "
    call	PI
    
    call	PISM
    de	6,1,20,"Vp-p: "
    
    movf	DATA_MULTI_MIN,0,1
    subwf	DATA_MULTI_MAX,0,1
    
;    andlw    01111111b
    mullw   25
    btfsc   VERTIZES,2
    mullw   50
    btfsc   VERTIZES,5
    mullw   50
    btfsc   VERTIZES2,0
    mullw   50
    btfsc   VERTIZES2,3
    mullw   50
    
    movf    PRODL,0 
    movwf   soucet 
    movf    PRODH,0
    movwf   soucetH
    movlw   0

    btfsc   VERTIZES,3
    movlw   1
    btfsc   VERTIZES,6
    movlw   1
    btfsc   VERTIZES2,1
    movlw   1
    movwf   cant
    call    posun1
    
    call    covert

    movf	digit4,0
    call	PI
    
    movf	digit3,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,6
    call	PI
    btfsc   VERTIZES,7
    call	PI	
    btfsc   VERTIZES2,0
    call	PI
    
    movf	digit2,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    btfsc   VERTIZES2,3
    call	PI
    btfsc   VERTIZES2,1
    call	PI	
    btfsc   VERTIZES2,2
    call	PI
    
    movf	digit1,0
    call	PI
    
    movlw	","
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    
    movf	digit0,0
    call	PI
    
    movlw	"m"
    btfsc   VERTIZES,3
    call	PI
    btfsc   VERTIZES,4
    call	PI	
    btfsc   VERTIZES,5
    call	PI
    btfsc   VERTIZES,0
    call	PI
    btfsc   VERTIZES,1
    call	PI	
    btfsc   VERTIZES,2
    call	PI
    
    movlw	"V"
    call	PI
    movlw	" "
    call	PI
    return
    
   
Paraler
    btfss	PRIZNAK,4
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,4
	
;    movlb   15
;;    BCF SIG_NEG_CS_CLK
;;    call	smyckaL
;;    movlw 11111011b
;;    MOVWF SSP2BUF,1
;;    nop
;;    call	smyckaL
;;
;;    movlw 01101010b
;;    MOVWF SSP2BUF,1
;;    call    smycka
;;    BSF SIG_NEG_CS_CLK

    bCf		RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf		RS_LCD

    MOVLB	0
    btg		obrmenu,0,1

    call	PISARI
    de	    	25,15,10,"Paralerni komunikace 8bit"

    call	PODTRHNI
    de		240,13,0,3  ;po?et,?ádek,start,typ

    call	PISM
    de		18,11,40,"Hodnota registru: "

   ; movf    PORTJ,0
   
    RRCF   PORTJ,0
;    andlw   01111111b
;    addlw   1
    
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
	call	PI
	movf	digit1,0
	call	PI
	movf	digit0,0
	call	PI

    return

MENU
	clrf	PRIZNAK
	bCf	RS_LCD
	movlw	11001101b	;8b ;se mirorors
	call	CL
	bsf	RS_LCD

	call	LCD
	
	MOVLB 0
	btg obrmenu,0,1

	movlw	0x95	;adresa
	call	obrazek
	call	smyckaL5	;délka zobrazení
	call    svetlo
    return

Posuv
    btfss	PRIZNAK,3
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,3

    bCf		RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf		RS_LCD

    MOVLB	0
    ;//////////////////////////
    call	PISM
    de		3,15,0,"T1:"

    movf    tlac1,0,1
    movwf   bin0
    clrf    bin1
    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    ;////////////////////////	
    call	PISM
    de	3,15,40,"T2:"

    movf    tlac2,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI  
    ;////////////////////////	
    call	PISM
    de	3,15,80,"T3:"

    movf    tlac3,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI 
        ;////////////////////////	
    call	PISM
    de	3,15,120,"T4:"

    movf    tlac4,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI  
    ;////////////////////////	
    call	PISM
    de	3,15,160,"T5:"

    movf    tlac5,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI  
    ;////////////////////////	
    call	PISM
    de	3,15,200,"T6:"

    movf    tlac6,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI  
    ;////////////////////////	
     
    call	PISM
    de	15,13,60,"Hodnota posuvu:"

    movf    POSUVNIK,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    call	PISM
    de	5,12,60,"del1:"

    movf	del1l,0,1
    movwf	bin0
    movf	del1h,0,1
    movwf	bin1

    call	covert

    movf	digit3,0
    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

     call	PISM
    de	5,11,60,"del2:"

    movf	del2l,0,1
    movwf	bin0
    movf	del2h,0,1
    movwf	bin1

    call	covert

    movf	digit3,0
    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    call	PISM
    de	5,10,60,"Lpoz:"

    movf    Lpoz,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    call	PISM
    de	5,9,60,"Ppoz:"

    movf    Ppoz,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    call	PISM
    de	5,8,60,"Sdel:"

    movf    Sdel,0,1
    movwf   bin0
    btfsc   Sdel,7
    negf    bin0
    clrf    bin1

    call	covert

    movlw   "-"
    btfsc   Sdel,7
    call    PI

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    movlw   " "
    call	PI

    call	PISM
    de	6,7,60,"SHIFT:"

    movf    SHIFT,0,1
    movwf   bin0
    clrf    bin1

    call	covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    call    smyckaL
    return


zkouska     ;new
    btfss	PRIZNAK,1
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,1

    BCF		nastav0,0

    movlb   15
    movlw   0
    btfsc   RTCCFG,HALFSEC,1
    addlw   1

    xorwf   zobrazT,0
    btfsc   STATUS,Z
    return

    btg   zobrazT,0

;    call    smyckaL ;brzda,
;    call    smyckaL ;brzda,
;    call    smyckaL ;brzda,

    bCf	RS_LCD
    movlw	11001101b	;8b ;se mirorors
    call	CL
    bsf	RS_LCD
	
    call    LCD

    call    malyobr  ;malý obrázek

    call	PISM
    de	13,6,0,"Teplota CPU: "

    call	teplota
    
    movf	digit3,0
    call	PI
    movf	digit2,0
    call	PI
;	movf	digit1,0
;	call	PI
;	movlw	","
;	call	PI
;	movf	digit0,0
;	call	PI
    movlw	"°"
    call	PI
    movlw	"C"
    call	PI

    call	PISM
    de	13,10,0,"Napětí Vbat: "
    call	napeti
;	movf	digit3,0
;	call	PI
    movf	digit2,0
    call	PI
    movlw	","
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	"V"
    call	PI

    call	PISM
    de	12,9,0,"Napětí CPU: "

    CALL    napetiCPU
    movf	digit3,0
    call	PI
    movlw	","
    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	"V"
    call	PI


    call	PISM
    de	11,7,0,"Proud LCD: "

    call	PROUD
    movf	digit3,0
    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movlw	"m"
    call	PI
    movlw	"A"
    call	PI
    
    call	PISM
    de	11,8,0,"Proud CPU: "

    call	PROUDC
;    movf	digit3,0
;    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	"m"
    call	PI
    movlw	"A"
    call	PI
    
    call	PISM
    de	12,5,0,"Proud 3,3V: "

    call	PROUDV
    movf	digit3,0
    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	"m"
    call	PI
    movlw	"A"
    call	PI

    call	PISM
    de		9,3,0,"Jas LCD: "

    call	svetloR
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
 
    call	PISM
    de		13,4,0,"Contrast LCD:"

    clrf    bin1
    movf    CONTRAST,0
    movwf   bin0
    call	covert

    movlw   "<"
    btfsc   RTCCFG,HALFSEC,1
    movlw   " "
    call	PI

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI

    movlw   ">"
    btfsc   RTCCFG,HALFSEC,1
    movlw   " "
    call	PI

    call	PISARI
    de	11,15,70,"PIC18F87K90"

    call	PISARI
    de	18,13,35,"LCD 240x128 UC1608"

    call    PISARI
    de	5,2,0,"Cas: "

;=============================
	bcf	RS_LCD

	movlw   50
    movwf   X
    andlw   00001111b
	call	CL

    swapf    X,0
    andlw   00001111b
    addlw   00010000b
	call	CL

	movlw   2    ;radek
    andlw   00001111b
    addlw   10110000b
    call	CL

	bsf	RS_LCD
;===============================

    MOVLB 15
	bsf	RTCCFG,1,1

	swapf	RTCVALL,0,1
	andlw	00000111b
	call	CIS

	movf	RTCVALL,0,1
	andlw	00001111b
	call	CIS

	movlw	"."
	call	PI

	swapf	RTCVALH,0,1
	andlw	00000111b
	call	CIS

	bsf	RTCCFG,1,1
	bcf	RTCCFG,0,1

	movf	RTCVALH,0,1
	andlw	00001111b
	call	CIS

	movlw	"."
	call	PI

	bsf	RTCCFG,1,1
	bsf	RTCCFG,0,1

	movlw	"2"
	call	PI
	movlw	"0"
	call	PI

	swapf	RTCVALL,0,1
	andlw	00000111b
	call	CIS

	movf	RTCVALL,0,1
	andlw	00001111b
	call	PI

;=============================
	bcf	RS_LCD

	movlw   56
    movwf   X
    andlw   00001111b
	call	CL

    swapf    X,0
    andlw   00001111b
    addlw   00010000b
	call	CL

	movlw   1  ;radek
    andlw   00001111b
    addlw   10110000b
    call	CL

	bsf	RS_LCD
;===============================

	bcf	RTCCFG,1,1
	bsf	RTCCFG,0,1

	swapf	RTCVALL,0,1
	andlw	00000111b
	call	CIS

	movf	RTCVALL,0,1
	andlw	00001111b
	call	CIS

	movlw	":"
	call	PI

	bcf	RTCCFG,0,1

	swapf	RTCVALH,0,1
	andlw	00000111b
	call	CIS

	movf	RTCVALH,0,1
	andlw	00001111b
	call	CIS

	movlw	":"
	call	PI

	swapf	RTCVALL,0,1
	andlw	00000111b
	call	CIS

	movf	RTCVALL,0,1
	andlw	00001111b
	call	CIS

	RETURN
;--------------------------------
T_ok
    clrf    TLACITKA1
    btfss   TLACIT,0
    goto    backMenu

    movlw   10b
    movwf   TLACIT

    movf    Menul,0,1
    xorlw   80
    btfsc   STATUS,Z
    RLNCF   TLACIT,1

    movf    Menul,0,1
    movlw   8
    btfss   STATUS,Z
    movf    TLACIT,0
    movwf   TLACIT

    movlw   8
    btfss   Menur,0,1
    movlw   1
    MULWF   TLACIT
    movf    PRODL,0
    movwf   TLACIT
    return

backMenu
    movlw   1
    movwf   TLACIT
    return

tplus
    clrf    TLACITKA1

    btfsc   TLACIT,0
    goto    menplus

    btfsc   TLACIT,5
    goto    conplus
    
    btfss   TLACIT,1
    return

    btfss   OPT_set,0,1   
    goto    LIST2_L
;list1    
    btfsc   Menu_osc,0
    goto    anit_aliazing
    
    btfsc   Menu_osc,1
    goto    vazba
    
    btfsc   Menu_osc,2
    goto    impedance
    
    btfsc   Menu_osc,3
    goto    Offset_up
    
    btfsc   Menu_osc,4
    goto    TB_set_L
    
    btfsc   Menu_osc,5
    goto    VA_set_L
    
    btfsc   Menu_osc,6
    goto    TRIGR_set_L

 ;list2    
LIST2_L

    btfsc   Menu_osc2,0,1
    goto    RUN_set_L
    
    btfsc   Menu_osc2,1,1
    goto    Trig_lvl_set_L
    
    btfsc   Menu_osc2,2,1
    goto    SHIFT_set_L
    
    return

RUN_set_L
    RLNCF   RUN_MODE,0,1
    andlw   111b
    movwf   RUN_MODE,1
    btfsc   STATUS,Z
    bsf     RUN_MODE,0,1
    
    clrf   TLACITKA1
    return
    
RUN_set_P
    RRNCF   RUN_MODE,0,1    
    andlw   111b
    movwf   RUN_MODE,1
    btfsc   STATUS,Z
    bsf     RUN_MODE,2,1
    
    clrf   TLACITKA1
    return
    
   
Offset_up
;nastevení offsetu
    movlb   0
    movlw   10
    addwf   offset_L,1,1
    btfsc   STATUS,C
    incf    offset_H,1,1
    
    movf    offset_H,0,1
    movwf   T_Base_MH
    movf    offset_L,0,1
    movwf   T_Base_ML
    goto    odesli_SPI2_off
    return
   
menplus
    movf    Menul,0,1
    btfsc   STATUS,Z
    return
    movlw   80
    subwf   Menul,1,1
    subwf   Menuh,1,1
    bcf     obrmenu,0,1
    return

conplus
    btg	    zobrazT,0
    btfss   TLACIT,5
    RETURN
    incf    CONTRAST,1
    call    LCD
    return
;--
tminus
    clrf    TLACITKA1

    btfsc   TLACIT,0
    goto    menminus

    btfsc   TLACIT,5
    goto    conminus
    
    btfss   TLACIT,1
    return
    
    btfss   OPT_set,0,1   
    goto    LIST2_P
;list1   

    btfsc   Menu_osc,0
    goto    anit_aliazing
    
    btfsc   Menu_osc,1
    goto    vazba
    
    btfsc   Menu_osc,2
    goto    impedance
    
    btfsc   Menu_osc,3
    goto    Offset_down
    
    btfsc   Menu_osc,4
    goto    TB_set_P
    
    btfsc   Menu_osc,5
    goto    VA_set_P
    
    btfsc   Menu_osc,6
    goto    TRIGR_set_P
    
LIST2_P    
    
    btfsc   Menu_osc2,0,1
    goto    RUN_set_P
    
    btfsc   Menu_osc2,1,1
    goto    Trig_lvl_set_P
        
    btfsc   Menu_osc2,2,1
    goto    SHIFT_set_P

    return
    
Trig_lvl_set_P
    decf    TRIG_lvl,1,1
    btfsc   STATUS,Z
    incf    TRIG_lvl,1,1
    
    clrf   TLACITKA1
    return
    
Trig_lvl_set_L
    incf    TRIG_lvl,1,1
    btfsc   STATUS,C
    setf    TRIG_lvl,1
    
    clrf   TLACITKA1
    return
    
SHIFT_set_P
    decf    SHIFT_sig,1,1
    btfsc   STATUS,OV
    incf    SHIFT_sig,1,1
    
    clrf   TLACITKA1
    return
    
SHIFT_set_L
    incf    SHIFT_sig,1,1
    btfsc   STATUS,OV
    decf    SHIFT_sig,1,1
    
    clrf   TLACITKA1
    return
    
    
Offset_down
    movlb   0
    movlw   10
    subwf   offset_L,1,1
    btfss   STATUS,C
    decf    offset_H,1,1
    
    movf    offset_H,0,1
    movwf   T_Base_MH
    movf    offset_L,0,1
    movwf   T_Base_ML
    goto    odesli_SPI2_off
    return
     
anit_aliazing
    btg	 REL_ANTIAL
    return

menminus
    movf    Menul,0,1
    xorlw   160
    btfsc   STATUS,Z
    return
    movlw   80
    addwf   Menul,1,1
    addwf   Menuh,1,1
    bcf     obrmenu,0,1
    return

conminus
    btg	    zobrazT,0
    btfss   TLACIT,5
    RETURN
    decf    CONTRAST,1
    call    LCD
    return
    
jasdown
    btg	    zobrazT,0
    movlb	15
    movlw	5
    subwf	svetloL,1
    movf	svetloL,0
    movwf	CCPR4,1		;banka 15
    movlb	0
    RETURN
    
jasup
    btg	    zobrazT,0
    movlb	15
    movlw	5
    addwf	svetloL,1
    movf	svetloL,0
    movwf	CCPR4,1
    movlb	0
    RETURN

T_down
;    btg	    zobrazT,0
    clrf    TLACITKA1
    
    btfsc   TLACIT,1
    goto    Men_shift_down
    
    btfsc   TLACIT,5
    goto    jasdown

    btfsc   TLACIT,0
    goto    mundown
    RETURN
   
Men_shift_down 
    btfss   OPT_set,0,1 
    RLNCF    Menu_osc2,1,1
    btfsc   OPT_set,0,1 
    RLNCF    Menu_osc,1 
    return
    
impedance
    btg	 REL_50Z 
    return
    
mundown
    bsf	    Menur,0,1
    bcf     obrmenu,0,1
    return

T_up
;    btg	    zobrazT,0
    clrf    TLACITKA1
    
    btfsc   TLACIT,1
    goto    Men_shift_up
    
    btfsc   TLACIT,5
    goto    jasup

    btfsc   TLACIT,0
    goto    menup
    return
    
    
Men_shift_up 
    
    btfss   OPT_set,0,1 
    RRNCF    Menu_osc2,1,1
    btfsc   OPT_set,0,1 
    RRNCF    Menu_osc,1 
    return
    
vazba
    btg	  REL_AC_DC 
    return
    
vert
    clrf   TLACITKA1
    
    btfss   TLACIT,1
    RETURN
VA_set_L
    BCF		STATUS,C
    RLCF	VERTIZES,1
    RLCF	VERTIZES2,1
    BTFSC	VERTIZES2,4
    MOVLW	8
    BTFSC	VERTIZES2,4
    MOVWF	VERTIZES2
    BRA		VA_10m
VA_set_P    ;LEVA
    BCF		STATUS,C
    RRCF	VERTIZES2,1
    BTFSC	STATUS,Z
    RRCF	VERTIZES,1
    BTFSC	STATUS,Z
    MOVLW	1
    BTFSC	STATUS,Z
    MOVWF	VERTIZES
    
    CLRF    T_Base_MH
    CLRF    T_Base_ML
;
VA_5m
    ;5m, RSEL=1V, s LSB
    btfsc   VERTIZES,0    
    bcf	    RSEL_AD
    btfsc   VERTIZES,0
    bcf     Si,6
    btfsc   VERTIZES,0
    BSF     REL_X5
    btfsc   VERTIZES,0
    BSF     REL_X2
    btfsc   VERTIZES,0
    BSF     REL_DESET_STO
    btfsc   VERTIZES,0
    BCF     REL_JEDNA_DESET
    ;    movlw   60
    movlw   0
    movwf   T_Base_ML
    btfsc   VERTIZES,0
    goto    odesli_SPI2_off

VA_10m
    ;10m, RSEL=1V bez LSB
    btfsc   VERTIZES,1    
    bcf	    RSEL_AD
    btfsc   VERTIZES,1
    bsf     Si,6
    btfsc   VERTIZES,1
    BSF     REL_X5
    btfsc   VERTIZES,1
    BSF     REL_X2
    btfsc   VERTIZES,1
    BSF     REL_DESET_STO
    btfsc   VERTIZES,1
    BCF     REL_JEDNA_DESET
    ;    movlw   60
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES,1
    goto    odesli_SPI2_off

    ;20m, RSEL=1V bez LSB
    btfsc   VERTIZES,2    
    bcf	    RSEL_AD
    btfsc   VERTIZES,2
    bsf     Si,6
    btfsc   VERTIZES,2
    BSF REL_X5
    btfsc   VERTIZES,2
    BCF REL_X2
    btfsc   VERTIZES,2
    BSF REL_DESET_STO
    btfsc   VERTIZES,2
    BCF REL_JEDNA_DESET
    ;    movlw   70
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES,2
    goto    odesli_SPI2_off

    ;50m, RSEL=1V bez LSB
    btfsc   VERTIZES,3    
    bcf	    RSEL_AD
    btfsc   VERTIZES,3
    bsf     Si,6
    btfsc   VERTIZES,3
    BsF REL_X2
    btfsc   VERTIZES,3
    BcF REL_X5
    btfsc   VERTIZES,3
    BSF REL_DESET_STO
    btfsc   VERTIZES,3
    BCF REL_JEDNA_DESET
    ;    movlw   50
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES,3
    goto    odesli_SPI2_off

    ;100m, RSEL=1V bez LSB
    btfsc   VERTIZES,4    
    bcf	    RSEL_AD
    btfsc   VERTIZES,4
    bsf     Si,6
    btfsc   VERTIZES,4
    BCF REL_X2
    btfsc   VERTIZES,4
    BCF REL_X5
    btfsc   VERTIZES,4
    BSF REL_DESET_STO
    btfsc   VERTIZES,4
    BCF REL_JEDNA_DESET
    ;    movlw   50
    movlw   0
    movwf   T_Base_ML
    btfsc   VERTIZES,4
    goto    odesli_SPI2_off

    ;200m, RSEL=2V bez LSB
    btfsc   VERTIZES,5   
    bsf	    RSEL_AD
    btfsc   VERTIZES,5
    bsf     Si,6
    btfsc   VERTIZES,5
    BCF REL_X2
    btfsc   VERTIZES,5
    BCF REL_X5
    btfsc   VERTIZES,5
    BSF REL_DESET_STO
    btfsc   VERTIZES,5
    BCF REL_JEDNA_DESET
    ;    btfsc   VERTIZES,5
    ;    setf    T_Base_MH
    ;    movlw   -10
    movlw   20
    movwf   T_Base_ML
    btfsc   VERTIZES,5
    goto    odesli_SPI2_off
    CLRF    T_Base_MH

    ;500m RSEL=1V bez LSB
    btfsc   VERTIZES,6    
    bcf	    RSEL_AD
    btfsc   VERTIZES,6
    bsf     Si,6
    btfsc   VERTIZES,6
    BSF REL_X2
    btfsc   VERTIZES,6
    BCF REL_X5
    btfsc   VERTIZES,6
    BSF REL_DESET_STO
    btfsc   VERTIZES,6
    BSF REL_JEDNA_DESET
    ;    movlw   80
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES,6
    goto    odesli_SPI2_off

    ;1V RSEL=1V bez LSB
    btfsc   VERTIZES,7    
    bcf	    RSEL_AD
    btfsc   VERTIZES,7
    bsf     Si,6
    btfsc   VERTIZES,7
    BCF REL_X2
    btfsc   VERTIZES,7
    BCF REL_X5
    btfsc   VERTIZES,7
    BSF REL_DESET_STO
    btfsc   VERTIZES,7
    BSF REL_JEDNA_DESET
    ;    movlw   70
    movlw   0
    movwf   T_Base_ML
    btfsc   VERTIZES,7
    goto    odesli_SPI2_off

    ;2V RSEL=2V bez LSB
    btfsc   VERTIZES2,0    
    bsf	    RSEL_AD
    btfsc   VERTIZES2,0
    bsf     Si,6
    btfsc   VERTIZES2,0
    BCF REL_X2
    btfsc   VERTIZES2,0
    BcF REL_X5
    btfsc   VERTIZES2,0
    BSF REL_DESET_STO
    btfsc   VERTIZES2,0
    BSF REL_JEDNA_DESET
    ;    movlw   25
    movlw   20
    movwf   T_Base_ML
    btfsc   VERTIZES2,0
    goto    odesli_SPI2_off

    ;5V, RSEL=1V bez LSB
    btfsc   VERTIZES2,1    
    bcf	    RSEL_AD
    btfsc   VERTIZES2,1
    bsf     Si,6
    btfsc   VERTIZES2,1
    BsF REL_X2
    btfsc   VERTIZES2,1
    BcF REL_X5
    btfsc   VERTIZES2,1
    BcF REL_DESET_STO
    btfsc   VERTIZES2,1
    BcF REL_JEDNA_DESET
    ;    movlw   80
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES2,1
    goto    odesli_SPI2_off
    
    nop

    ;10V RSEL=1V bez LSB
    btfsc   VERTIZES2,2    
    bcf	    RSEL_AD
    btfsc   VERTIZES2,2
    bSf     Si,6
    btfsc   VERTIZES2,2
    BCF REL_X2
    btfsc   VERTIZES2,2
    BCF REL_X5
    btfsc   VERTIZES2,2
    BCF REL_DESET_STO
    btfsc   VERTIZES2,2
    BCF REL_JEDNA_DESET
    ;    movlw   70
    movlw   10
    movwf   T_Base_ML
    btfsc   VERTIZES2,2
    goto    odesli_SPI2_off

    ;20V RSEL=2V bez LSB
    btfsc   VERTIZES2,3    
    bsf	    RSEL_AD
    btfsc   VERTIZES2,3
    bsf     Si,6
    btfsc   VERTIZES2,3
    BCF	    REL_X2
    btfsc   VERTIZES2,3
    BCF	    REL_X5
    btfsc   VERTIZES2,3
    BCF	    REL_DESET_STO
    btfsc   VERTIZES2,3
    BCF	    REL_JEDNA_DESET
    ;    movlw   15
    movlw   20
    movwf   T_Base_ML
    btfsc   VERTIZES2,3
    goto    odesli_SPI2_off
    return
 
T_base    
    clrf   TLACITKA1
    
    btfss   TLACIT,1
    return
    
    
TB_set_P    ;sníženi
    BCF		STATUS,C
    RRCF    T_base_v,1
    BTFSS   T_base_n,7
    RLCF    T_base_n,1
   
    BRA	     T_500ns   
TB_set_L    ;zvýšení
    BCF		STATUS,C
    RRCF    T_base_n,1
    BTFSS   T_base_v,7
    RLCF    T_base_v,1
    
T_500ns
    btfss   T_base_n,7
    BRA     T_1us
; ;500ns/dil - 40Mhz
;
;    movlw   0xf4
;    movwf   T_Base_MH
;    movlw   0xc6
;    movwf   T_Base_ML
;666,7ns/dil - 30Mhz

    movlw   0xED
    movwf   T_Base_MH
    movlw   0xDA
    movwf   T_Base_ML    
    
    goto    odesli_SPI2_clk  
    
T_1us
    btfss   T_base_n,6
    BRA     T_2us
 ;1us/dil - 20Mhz

    movlw   0xE1
    movwf   T_Base_MH
    movlw   0xC6
    movwf   T_Base_ML
    goto    odesli_SPI2_clk  
    
T_2us
    btfss   T_base_n,5
    BRA     T_5us
 ;2us/dil - 10Mhz

    movlw   0xD4
    movwf   T_Base_MH
    movlw   0xC6
    movwf   T_Base_ML
    goto    odesli_SPI2_clk       
    
T_5us
    btfss   T_base_n,4
    BRA     T_10us
 ;5us/dil - 4Mhz

    movlw   0xBE
    movwf   T_Base_MH
    movlw   0xFE
    movwf   T_Base_ML
    goto    odesli_SPI2_clk     
    
T_10us
    btfss   T_base_n,3
    BRA     T_20us
 ;10us/dil - 2Mhz

    movlw   0xAE
    movwf   T_Base_MH
    movlw   0xFE
    movwf   T_Base_ML
    goto    odesli_SPI2_clk       
    
T_20us
    btfss   T_base_n,2
    BRA     T_50us
 ;20us/dil - 1Mhz//*4 = 4 Mhz

    movlw   0xBE
    movwf   T_Base_MH
    movlw   0xFE
    movwf   T_Base_ML
    goto    odesli_SPI2_clk       
    
T_50us
    btfss   T_base_n,1
    BRA     T_100us
 ;50us/dil - 400khz//*4  = 1,6Mhz

    movlw   0xAA
    movwf   T_Base_MH
    movlw   0xBA
    movwf   T_Base_ML
    goto    odesli_SPI2_clk    
    
T_100us
    btfss   T_base_n,0
    BRA     T_200us
 ;100us/dil - 200khz//*4 = 800khz

    movlw   0x9A
    movwf   T_Base_MH
    movlw   0xBA
    movwf   T_Base_ML
    goto    odesli_SPI2_clk
    
T_200us
    btfss   T_base_v,0
    BRA     T_500us
 ;200us/dil - 100khz//*4 = 400khz 

    movlw   0x8A
    movwf   T_Base_MH
    movlw   0xBA
    movwf   T_Base_ML
    goto    odesli_SPI2_clk
    
T_500us
    btfss   T_base_v,1
    BRA     T_1ms
 ;500us/dil - 40khz// *4 = 160khz

    movlw   0x75
    movwf   T_Base_MH
    movlw   0x6A
    movwf   T_Base_ML
    goto    odesli_SPI2_clk

T_1ms
    btfss   T_base_v,2
    BRA     T_2ms
 ;1ms/dil - 20khz//*4 = 80khz 
    movlw   0x65
    movwf   T_Base_MH
    movlw   0x6A
    movwf   T_Base_ML
    goto    odesli_SPI2_clk
    
T_2ms
    btfss   T_base_v,3
    BRA     T_5ms
 ;2ms/dil - 10khz//*4 = 40kz
    movlw   0x55
    movwf   T_Base_MH
    movlw   0x6A
    movwf   T_Base_ML
    goto    odesli_SPI2_clk
    
T_5ms
    btfss   T_base_v,4
    BRA     T_10ms
 ;5ms/dil - 4khz//*4 = 16khz

    movlw   0x3F
    movwf   T_Base_MH
    movlw   0x62
    movwf   T_Base_ML
    goto    odesli_SPI2_clk
    
T_10ms
    btfss   T_base_v,5
    BRA     T_20ms
 ;10ms/dil - 4khz//*4 = 16khz

    movlw   0x3F
    movwf   T_Base_MH
    movlw   0x62
    movwf   T_Base_ML
    goto    odesli_SPI2_clk 
    
T_20ms
    btfss   T_base_v,6
    BRA     T_50ms
 ;20ms/dil - 4khz//*4 = 16khz

    movlw   0x3F
    movwf   T_Base_MH
    movlw   0x62
    movwf   T_Base_ML
    goto    odesli_SPI2_clk 
    
T_50ms
;     btfss   T_base_v,7
;     BRA     T_100ms
 ;50ms/dil - 4khz//*4 = 16khz

    movlw   0x3F
    movwf   T_Base_MH
    movlw   0x62
    movwf   T_Base_ML
    goto    odesli_SPI2_clk 
T_100ms    
    return
    
odesli_SPI2_clk
    movlb	15
    BCF		SIG_NEG_CS_CLK
    call	smyckaS
    movf        T_Base_MH,0
    MOVWF	SSP2BUF,1
    call	smyckaS

    movf	T_Base_ML,0
    MOVWF       SSP2BUF,1
    call	smyckaS
    BSF		SIG_NEG_CS_CLK
    movlb	0
    return
    
odesli_SPI2_off
    movlb	15
    BCF		SIG_NEG_CS_DAC
    call	smycka

    movlw	0
    btfss	T_Base_MH,7
    movf        T_Base_MH,0
    iorlw	10110000b
    ;A 1011 XXXX XXXX XXXX
    MOVWF	SSP2BUF,1
    call	smycka
    
    movlw	0
    btfss	T_Base_MH,7
    movf	T_Base_ML,0
    MOVWF       SSP2BUF,1
    call	smycka
    
    BSF		SIG_NEG_CS_DAC
    call	smycka
    BCF		SIG_NEG_CS_DAC
;----------------------------
    movlw	0
    btfsc	T_Base_MH,7
    comf	T_Base_MH,0
    iorlw	00110000b
    ;B 0011 XXXX XXXX XXXX
    MOVWF	SSP2BUF,1
    call	smycka
    movlw	0
    btfsc	T_Base_MH,7
    comf	T_Base_ML,0
    btfsc	T_Base_MH,7
    addlw	1
    MOVWF       SSP2BUF,1
    call	smycka
    BSF		SIG_NEG_CS_DAC
    movlb	0
    
    bcf	    SIG_NEG_LDAC
    call    smyckaS
    bsf	    SIG_NEG_LDAC
    return
    
menup
    bcf Menur,0,1
    bcf obrmenu,0,1
    return

TRIGR_TL
;TRIGR
    clrf    TLACITKA1
    
    btfss   TLACIT,1
    RETURN
    
    clrf    SHIFT_sig,1
TRIGR_set_L
    RLNCF	zdtrig,0
    BRA		TR_PREP2   
TRIGR_set_P
    RRNCF	zdtrig,0    
TR_PREP    
    andlw   1111b
    movwf   zdtrig
    btfsc   STATUS,Z
    bsf     zdtrig,3
    
    clrf   TLACITKA1
    return
    
TR_PREP2    
    andlw   1111b
    movwf   zdtrig
    btfsc   STATUS,Z
    bsf     zdtrig,0
    
    clrf   TLACITKA1
    return
    
back
    btfss   TLACIT,0
    goto    backMenu
    
    clrf   TLACITKA1
    return
    
OPTION
    btfss   TLACIT,1
    RETURN
    
    RLNCF   OPT_set,0,1  
    andlw   11b
    movwf   OPT_set,1
    btfsc   STATUS,Z
    bsf     OPT_set,0,1
    
    bcf	    PRIZNAK,0
    
    clrf   TLACITKA1
    return
    
Tlacitka

    btfsc   TLACITKA1,0
    goto    T_ok

    btfsc   TLACITKA1,2
    goto    tplus

    btfsc   TLACITKA1,1
    goto    tminus

    btfsc   TLACITKA1,3
    goto    T_down

    btfsc   TLACITKA1,4
    goto    T_up

    btfsc   TLACITKA1,5
    goto    TRIGR_TL

    btfsc   TLACITKA1,6
    goto    back
    
    btfsc   TLACITKA1,7
    goto    OPTION

    return
;-------------------------------------------------------

OSCILOSKOP
    btfss	PRIZNAK,2
    CALL	VYCISTIT
    clrf	PRIZNAK
    bsf		PRIZNAK,2
	
    
;    btfss	T1CON,TMR1ON
    btfsc	INTCON,INT0IE
    goto	menu_osc
;    btfsc	Si,2
;    return
    
    bcf		Si,2
    btfsc	optiontrig,7
    goto	trigrr

    call	svetlo
    movlw	10
    movwf	opakovac

    call	oscil
  return

;-------------------------------------------------------
CIS
	addlw	00110000b
	call	PI
	return

;////////////////////////////////////////////////////////////////////////////////////////////////////////////
PWMs
;    movf    BSR,0
;    movwf    Je
;	bcf		STATUS,C
;	RRCF	PWMh,1
;	RRCF	PWMl,1
;	bcf		STATUS,C
;	RRCF	PWMh,1
;	RRCF	PWMl,0
;
;    movlb   15
;;	movwf	CCPR4L,1
;    movf    Je,0
;    movwf   BSR
	return

;0000000000000000000000000000000000000

PROUD	;proud LCD
	bcf	Si,3
	bcf	Si,4
	movlw	00100000b
	movwf	ADCON1

	movlw	0xBE
	movwf	ADCON2

	movlw	256
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
sztm
	movlw	00101111b
	movwf	ADCON0
rewz	btfsc	ADCON0,1
	goto	rewz

	movf	ADRESH,0
	btfsc	ADRESH,7
	comf	ADRESH,0
	movwf	bin1

	movf	ADRESL,0
	btfsc	ADRESH,7
	comf	ADRESL,0
	movwf	bin0
;	movlw	2	;offset
;	subwf	ADRESL,1
; 	btfss	STATUS,C
;	decf	ADRESH,1

	movf	bin0,0
	addwf	soucet,1
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	bin1,0
	addwf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	decf	cant,1
	bnz	sztm

	movlw	9
	movwf	cant
	call	posun
	return

;------------------------------
PROUDC	;proud CPU //an5 pozitive , an1 negative
	bcf	Si,4
	movlw	00100010b   ;an1 negative
	movwf	ADCON1

	movlw	0xBE
	movwf	ADCON2

	movlw	256
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
szt
	movlw	00010111b   ;an5 pozitive
	movwf	ADCON0
vxs	btfsc	ADCON0,1
	goto	vxs
	btfsc	ADRESH,7
	bsf	Si,4

	movf	ADRESH,0
	movwf	bin1

	movf	ADRESL,0
	movwf	bin0

	movlw	42	;offset
	subwf	bin0,1

	movf	bin0,0
	mullw	3  ;5
	movf	PRODL,0
	addwf	soucet,1
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	PRODH,0
	addwf	soucetH,1
   	btfsc	STATUS,C
	incf	soucetU,1

	decf	cant,1
	bnz	szt

	movlw	9   ;7
	movwf	cant
	
	call	posun
	return
;------------------------------
PROUDV	;proud 3,3V //an10 pozitive , an5 negative
	bcf	Si,4
	movlw	00100110b   ;an5 negative
	movwf	ADCON1

	movlw	0xBE
	movwf	ADCON2

	movlw	256
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
sztt
	movlw	00101011b   ;an10 pozitive
	movwf	ADCON0
vxss	btfsc	ADCON0,1
	goto	vxss
	btfsc	ADRESH,7
	bsf	Si,4

	movf	ADRESH,0
	movwf	bin1

	movf	ADRESL,0
	movwf	bin0

	movlw	41	;offset
	subwf	bin0,1

	movf	bin0,0
	mullw	3  ;5
	movf	PRODL,0
	addwf	soucet,1
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	PRODH,0
	addwf	soucetH,1
   	btfsc	STATUS,C
	incf	soucetU,1

	decf	cant,1
	bnz	sztt

	movlw	9   ;7
	movwf	cant
	
	call	posun
	return
;------------------------------	
;VDD
napeti
	movlw	00100000b
	movwf	ADCON1

	movlw	0xBE
	movwf	ADCON2

	bcf     PIE1,ADIE   ;zaká?e přeru?ení od AD

	movlw	256 ;iterace
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
ghgmj
	movlw	00111011b
	movwf	ADCON0
dda	btfsc	ADCON0,1
	goto	dda

	movlw	20	;offset
	subwf	ADRESL,1
   	btfss	STATUS,C
	decf	ADRESH,1
	decf	ADRESH,1
	decf	ADRESH,1

	movf	ADRESH,0
	mullw	3
	movf	PRODL,0
	movwf	bin1

	movf	ADRESL,0
	mullw	3
	movf	PRODL,0
	movwf	bin0
	movf	PRODH,0
	addwf	bin1,1

	movf	bin0,0
	addwf	soucet,1
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	bin1,0
	addwf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	decf	cant,1
	bnz	ghgmj

	movlw	11
	movwf	cant
	call	posun
    return

;------------------------------
napetiCPU
	movlw	00100000b
	movwf	ADCON1

	movlw	0xBE
	movwf	ADCON2

	movlw   64	;256 iterací
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
ghgm
	movlw	00100011b
	movwf	ADCON0
tqa	btfsc	ADCON0,1
	goto	tqa

	movlw	30	;offset
	addwf	ADRESL,1
   	btfsc	STATUS,C
	incf	ADRESH,1


	movf	ADRESH,0
	movwf	bin1

	movf	ADRESL,0
	movwf	bin0

	movf	bin0,0
	addwf	soucet
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	bin1,0
	addwf	soucetH
	btfsc	STATUS,C
	incf	soucetU,1

	decf	cant,1
	bnz	ghgm

	movlw	6
	movwf	cant
	call	posun
	return

;------------------------------

teplota		;teplota CPU
;Initialize CTMU
	movlw	0x03
	movwf	CTMUICON
	bsf	CTMUCONH,CTMUEN
	bsf	CTMUCONL,EDG1STAT

	movlw	0xBE
	movwf	ADCON2

	movlw	00100000b
	movwf	ADCON1


	movlw	256
	movwf	cant
	clrf	soucet
	clrf	soucetH
	clrf	soucetU
sztmj
	movlw	01110111b
	movwf	ADCON0
llk btfsc	ADCON0,1
	goto	llk
	
	movf	ADRESL,0
	sublw	870	;- hodnata nap?tí v mV na diod? p?i 0°C
	movwf	ADRESL
   	btfsc	STATUS,C
	decf	ADRESH,1
		
	movf	ADRESH,0
	mullw	31
	movf	PRODL,0
	movwf	bin1

	movf	ADRESL,0
	mullw	31  ;sm?rnice  1,25mV/°C (31*4=124)
	movf	PRODL,0
	movwf	bin0
	movf	PRODH,0
	addwf	bin1,1

	movf	bin0,0
	addwf	soucet
	btfsc	STATUS,C
	incf	soucetH,1
	btfsc	STATUS,C
	incf	soucetU,1

	movf	bin1,0
	addwf	soucetH
	btfsc	STATUS,C
	incf	soucetU,1
	
	decf	cant,1
	bnz	sztmj

	movlw	7   ; *4 
	movwf	cant
	call	posun

   	bcf	CTMUCONH,CTMUEN	;CTMUoff
	return

svetloR
	movf	svetloL,0
	movwf	bin0
	;movf	svetloH,0
	movlw	0
	movwf	bin1

	call	covert
	return
;------------------------------
;světlo
svetlo
;	movlw	00100000b
;	movwf	ADCON1
;
;	movlw	10111110b
;	movwf	ADCON2
;
;    movlw	00000011b
;	movwf	ADCON0
;
;uda	btfsc	ADCON0,1
;	goto	uda
;
;
;	movlw	00000011b
;	movwf	ADCON0
;ppo	btfsc	ADCON0,1
;	goto	ppo
;
;	movlw	00000011b
;	movwf	ADCON0
;ppk btfsc	ADCON0,1
;	goto	ppk
;
;	movlw	4	;offset
;	subwf	ADRESL,1
;	btfss	STATUS,C
;	decf	ADRESH,1
;
;	btfsc	ADRESH,7
;	call	null
;
;	bcf	STATUS,C
;	RRCF	ADRESH,1
;	RRCF	ADRESL,1
;	bcf	STATUS,C
;	RRCF	ADRESH,1
;	RRCF	ADRESL,1
;
;pokk
;	movf	ADRESH,0
;	movwf	bin1
;	movwf	svetRh
;	movf	ADRESL,0
;	movwf	bin0
;	movwf	svetRl
;
;	movf svetloL,0
;	subwf	bin0,1
;	movf svetloH,0
;	subwfb	bin1,1
;
;	bcf		znaminko,0
;	btfss	STATUS,C
;	bsf		znaminko,0
;
;	btfsc	znaminko,0
;	negf	bin1
;	btfsc	znaminko,0
;	negf	bin0
;	btfsc	znaminko,0
;	decf	bin1,1
;
;;dolní propust
;	movf	bin0,0
;	mullw	7
;
;	movf	PRODL,0
;	movwf	paml
;
; 	movf	PRODH,0
;	movwf	pamh
;
;	clrf	pamu
;	movf	bin1,0
;	mullw	7
;	movf	PRODL,0
;	addwf	pamh,1
;	btfsc	STATUS,C
;	incf	pamu,1
;
;	movf	paml,0
;	movwf	soucet
;	movf	pamh,0
;	movwf	soucetH
;	movf	pamu,0
;	movwf	soucetU
;fffds
;
;	movlw	6
;	movwf	cant
;	call	filtr
;
;	btfsc	znaminko,0
;	goto	minus
;
;	movf	soucet,0
;	addwf	svetloL,1
;
;	movf	soucetH,0
;	addwfc	svetloH,1
pok
;	movf	svetloH,0
;	movwf	bin1
;	movwf	PWMh
;	movf	svetloL,0
;	movwf	bin0
;	movwf	PWMl

;	call	covert
	goto	PWMs

minus
;	movf	soucet,0
;	subwf	svetloL,1
;	movf	soucetH,0
;	subwfb	svetloH,1
;
;	bcf		znaminko,2
;	btfss	STATUS,C
;	bsf		znaminko,2
;
;	btfsc	znaminko,2
;	negf	svetloH
;	btfsc	znaminko,2
;	negf	svetloL
;	btfsc	znaminko,2
;	decf	svetloH,1

	goto	pok

posun
sztj
	
	bcf	STATUS,C
	RRCF	soucetU,1
	RRCF	soucetH,1
	RRCF	soucet,1
	decf	cant,1
	bnz	sztj

	movf	soucetH,0
	movwf	bin1
	movf	soucet,0
	movwf	bin0
   	call	covert
	return
	
posun1
	movf	cant,1
	btfsc	STATUS,Z
	goto	posun1_0
posun1_fb	
	bcf	STATUS,C
	RRCF	soucetH,1
	RRCF	soucet,1
	decf	cant,1
	bnz	posun1_fb
posun1_0
	movf	soucetH,0
	movwf	bin1
	movf	soucet,0
	movwf	bin0
	return
	
filtr
sztjp
	bcf		STATUS,C
	RRCF	soucetU,1
	RRCF	soucetH,1
	RRCF	soucet,1
	decf	cant,1
	bnz	sztjp

	return
null
	clrf	ADRESH
	clrf	ADRESL
	return

;/////////////////////////////////////////////////////////////////////////////////
;--------------------------------------------------------------------------------
;16bit to BCD Double dabble 731 cycle
covert
    clrf    digit0   ; Clear BCD bytes
    clrf    digit1
    clrf    digit2
    clrf    digit3
    clrf    digit4
    movf    bin1,0
    movwf   digit4
    
    movlw   0x10
    subwf   bin0,0
    btfsc   STATUS,N
    decf    digit4,1
    movlw   0x27
    subwf   digit4,0
    clrf    digit4
    btfsc   STATUS,C
    bsf	    digit4,0
    

    movlw    16        ; Bit count for two bytes of binary
    movwf    BitCount
RET
	swapf	digit2,0
	call	nah
	CPFSLT	digit1
	call	pricti4
	movf	digit2,0
	call	nah
	CPFSLT	digit1
	call	pricti3
	swapf	digit0,0
	call	nah
	CPFSLT	digit1
	call	pricti2
	movf	digit0,0
	call	nah
	CPFSLT	digit1
	call	pricti

	RLCF	bin0,1
	RLCF	bin1,1
	RLCF	digit0,1
	RLCF	digit2,1

   	decfsz	BitCount,1
    bra	RET

	swapf	digit0,0
	andlw	00001111b
	movwf	digit1
	movf	digit0,0
	andlw	00001111b
	movwf	digit0
	swapf	digit2,0
	andlw	00001111b
	movwf	digit3
	movf	digit2,0
	andlw	00001111b
	movwf	digit2
	return

nah
	andlw	00001111b
	movwf	digit1
	RETLW	5
pricti
	movlw	3
	addwf	digit0,1
	return
pricti2
	movlw	48
	addwf	digit0,1
	return
pricti3
	movlw	3
	addwf	digit2,1
	return
pricti4
	movlw	48
	addwf	digit2,1
	return

	
	
	
;/////////////////////////////////////////////////////////////////////////////////
trigi
    movwf   vzorek1
    movlw   240
    movwf    TRIGR
    movlw   2
    movwf   TRIGRH
    movf    vzorek1,0
    return

falltri
    movlw   4
    movwf   TRIGR
    bra     trigg
;-------------------------------------

repet
    bcf   optiontrig,7   ;zaká?e vzarkování
    decf     opakovac,1
    btfss    STATUS,Z
    goto    oscil
    clrf    vzorek0
    clrf    vzorek1
    return

oscil
    bsf   optiontrig,7  ;povolí vzorkování

;call	PISARI
;de	5,8,90,"CHYBA"

    movlw   10
    movwf   rozdil

    movlw   240
    movwf   TRIGR
    movlw   2
    movwf   TRIGRH
    clrf    RAD

;nastavení A/D
;AD off
;    movlw	10100000b
;    movwf	ADCON1
;    movlw	00001110b
;    movwf	ADCON2
;    movlw	00010001b
;    movwf	ADCON0

   LFSR    0,0x400
   LFSR    1,0x700

;ZAPNE VZORKOVAČ A UDeLÁ 3X256 VZORKŮ
;   bcf     PIR1,ADIF   ;smaze príznak prerusení
   bcf	    DRUH,0,1
   bcf	    INTCON,INT0IF
  ; bsf     PIE1,ADIE   ;povolí přeru?ení od AD
;   bsf     T1CON,TMR1ON
  
;   bcf     PIE1,SSP1IE
  
;   bcf	    LATB,1
   bsf	    INTCON,INT0IE
;   bcf	    TRISB,1
   nop
;   bsf	    LATB,1
;     bcf	    TRISB,1
;   nop
;   bsf	    LATB,1



;cEKÁ NA DOKONcENÍ VZORKOVÁNÍ
cekam
;    btfsc   T1CON,TMR1ON
    btfsc   INTCON,INT0IE
;    goto    cekam
    return


;spoustení
trigrr
    LFSR    0,0x40A

trigg
;ochrana proti přetečení
    btfsc   FSR0H,1
    goto    repet

    movf    INDF0,0
    movwf   vzorek0
    movf    PREINC0,0
;none
;    btfsc   zdtrig,3
    goto    zapni
;;RIS
;    btfsc   zdtrig,2
;    goto    FRIS
;;FAl
;    btfsc   zdtrig,1
;    goto    FFAL
;    goto    MMAX
;--------------------------------------------
;TRIG=RISING EDGE
;--------------------------------------------
;FRIS
;  bsf  STATUS,C
;  SUBFWB   vzorek0,0    ;vypočte rozdíl
;
;  btfsc   STATUS,N
;  goto    trigg     ;pokud je zápo
;
;  CPFSGT rozdil
;  goto  zapni   ;pokud je F>W
;
;  goto    trigg
;   
;;--------------------------------------------
;;TRIG=falling EDGE
;;--------------------------------------------
;FFAL
;  bsf  STATUS,C
;  SUBWFB   vzorek0,0    ;vypočte rozdíl
;
;  btfsc   STATUS,N
;  goto    trigg     ;pokud je zápo
;
;  CPFSGT rozdil
;  goto  zapni   ;pokud je F>W
;
;  goto    trigg
;
;;-------------------------------------------
;;TRIG=MAX
;;--------------------------------------------
;MMAX
;    decf     TRIGR,1
;    btfsc    STATUS,Z
;    decf     TRIGRH,1
;    btfsc    STATUS,Z
;
;    call     trigi
;;nalezne nejět?í část signálu pro spou?tění
;    CPFSGT  vzorek1
;    call    trigi
;
;    xorwf   vzorek1,0
;;    xorlw   60
;    btfss   STATUS,Z
;    goto    trigg

;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;--------------------------------------
;///////////////////////////////////
zapni
   bcf   optiontrig,7   ;zaká?e vzarkování
   MOVF    FSR0L,0
;posuv o 10
    addlw   245
    btfss   STATUS,C
    decf    FSR0H,1

    MOVWF   PAMFSR0L
    MOVWF   FSR1L
    ADDLW   1
    MOVWF   FSR0L

    MOVF    FSR0H,0
;    MOVLW   4	;bylo zapoznámkované
    
    MOVWF   PAMFSR0H
    MOVWF   FSR0H
    ADDLW   3
    MOVWF   FSR1H


;NASTAVENÍ POČÁTKU VYKRESLOVÁNÍ
;===============================
    bcf	RS_LCD

    movlw   0
    movwf   X,0
    andlw   00001111b
    call	CL

    swapf   X,0
    andlw   00001111b
    addlw   00010000b
    call	CL

    movlw   15
    addlw   10110000b
    call    CL

    movlw   11000101b	;8b ;se mirorors
    call    CL

;   movlw	10100111b	;8b ;NEGATIV
;   call	CL
    bsf	RS_LCD
;===============================

    movlw   240
    movwf   SLOUP

dalsiSLl
 ;určí vzdálenst sousedních vzorků
    movf    POSTINC1,1
    movf    POSTINC1,0
    subwf   POSTDEC1,0
    movwf   INDF1

    decfsz    SLOUP,1
    goto    dalsiSLl

;zobrazí oscilograf
;PARAMETRY VYKRESLOVÁNÍ 16 ŘÁDKŮ, 240 SLOUPCŮ , PO 8 BITECH
    movlw   16
    movwf   RAD
    movlw   201
    movwf   SLOUP
    movlw   8
    movwf   X
    clrf    BAR

    movlw	0x75 ;+;5	;adresa podkladu
    movwf	TBLPTRH
    CLRF	TBLPTRL

    MOVF    PAMFSR0L,0
    ADDLW   1
    MOVWF   FSR0L
    MOVWF   FSR1L
    MOVF    PAMFSR0H,0
    MOVWF   FSR0H
    ADDLW   3
    MOVWF   FSR1H

dalsiSL
    movf    INDF1,0
    btfsc   STATUS,Z
    goto    semnnn
    btfsc   INDF1,7
    goto    semnn
;kladný víceřádkový proklad
    movf    INDF0,0
    btfsc   STATUS,Z
    goto    inter
semnn
   comf	    INDF1,0
   addlw    1
   xorwf    INDF0,0
   btfsc    STATUS,Z
   goto	    interneg

semnnn
    DCFSNZ	INDF0,1
    goto	interpol

    decfsz	X,1
    goto	dalsiSL

pokracuj
    TBLRD*+
    movf    SLOUP,0

    MOVF    TABLAT,0
    iorwf   BAR,0
    call    CL
beznul

    movlw   8
    movwf   X

    clrf   BAR
    movf    POSTINC0,1
    movf    POSTINC1,1

    decfsz    SLOUP,1
    goto    dalsiSL

    bsf   nastav0,1
    movlw   201
    movwf   SLOUP

    MOVF    PAMFSR0L,0
    ADDLW   1
    MOVWF   FSR0L
    MOVWF   FSR1L
    MOVF    PAMFSR0H,0
    MOVWF   FSR0H
    ADDLW   3
    MOVWF   FSR1H
    
;pocátek rádku
    bcf	RS_LCD
    movlw   0
    call    CL
    movlw   0
    addlw   00010000b
    call    CL
    decf    RAD,0
    addlw   10101111b
    call    CL
    bsf	RS_LCD

    decfsz   RAD,1
    goto    dalsiSL
menu_osc
    
    bcf	RS_LCD

;    movlw   15
;    addlw   10110000b
;    call    CL

    movlw   11000101b	;8b ;se mirorors
    call    CL
    bsf	RS_LCD
    
    bsf     nastav0,5
    bcf		Si,7
    
;trigr
    btfsc   zdtrig,0
    goto    beztrigru
    btfsc   zdtrig,3
    bra     beztrigru

    call	PISM
    de	0,2,7,""       ;NASTAV ZACÁTEK VYPISOVÁNÍ
;VYPÍSE TRIGR
    movlw   19
    btfsc   zdtrig,1
    MOVLW   18
    call    PI

beztrigru
    
;/////////////////////////////////////////////////    
    btfss     OPT_set,0,1   ;přepnutí menu_opt
    goto      OPT_menu2
    
    call	PISM
    de	6,0,201,"      "
    
    call	PISM
    de	0,5,201,""
    
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL

    call	PISM
    de	0,6,201,""
    
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    bcf		Si,7
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
 
    call    PISM
    de	6,5,203,"Offset"
    
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
       
    call    PISM
    de	1,6,203," "
    
    movlb   0
    
    movf	offset_H,0,1
    btfsc	offset_H,7,1
    comf	offset_H,0,1
    movwf   bin1
    
    movf	offset_L,0,1
    btfsc	offset_H,7,1
    comf	offset_L,0,1
    btfsc	offset_H,7,1
    addlw	1
    movwf   bin0
    
    call    covert
    
    movlw	"-"
    btfsc	offset_H,7,1
    call	PI
    
    movf	digit3,0
    call	PI
;    movlw	","
;    call	PI
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	" "
    btfss	offset_H,7,1
    call	PI
    
    movlw	0x00
    btfsc	Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL   	   
    
    btfss   Menu_osc,3  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    OFFSET_neoznac
    
    call    PODTRHNI
    de	39,4,201,15  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,7,201,240  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,13,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,10,201,8  ;pocet,rádek,start,typ
    
OFFSET_neoznac   
        
;nastavení impedance
    btfsc   Menu_osc,0  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    IMPEDANCE_oznac
    btfsc   Menu_osc,1  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    IMPEDANCE_oznac
    btfsc   Menu_osc,7  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    IMPEDANCE_oznac
    btfss   Menu_osc,2  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    IMPEDANCE_neoznac
IMPEDANCE_oznac    
    call    PODTRHNI
    de	39,4,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,7,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,13,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,10,201,8  ;pocet,rádek,start,typ
    
IMPEDANCE_neoznac  
    call	PISM
    de	0,3,201,""
    
    movlw	0x00
    btfsc	Menu_osc,2  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,2  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL

    bcf		Si,7
    btfsc	Menu_osc,2  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
    
    btfsc	REL_50Z
    goto	Z50
    
    call    PISM
    de	6,3,203,"Z:1 M",153   
    bra	    Z1M
Z50   
    call    PISM
    de	6,3,203,"Z:50 ",153
Z1M    
    movlw	0x00
    btfsc	Menu_osc,2  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    bcf		Si,7
;nastavení vazby    
    call	PISM
    de	0,2,201,""
    
    movlw	0x00
    btfsc	Menu_osc,1  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    movlw	0x00
    btfsc	Menu_osc,1  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    bcf		Si,7
    btfsc	Menu_osc,1  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
    
    btfsc   REL_AC_DC
    bra	    C_AC
    
    call    PISM
    de	6,2,203," C:DC "
    bra	    C_DC
C_AC   
    call    PISM
    de	6,2,203," C:AC "
C_DC  
    
    movlw	0x00
    btfsc	Menu_osc,1  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    bcf		Si,7
;Antializingový filtr
    
    call	PISM
    de	0,1,201,""
       
    movlw	0x00
    btfsc	Menu_osc,0  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,0  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL

    bcf		Si,7
    btfsc	Menu_osc,0  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
    
    call    PISM
    de	4,1,203,"AF:O"
    
    btfss   REL_ANTIAL
    bra	    AF_OFF
  
    movlw	"N"
    call	PI
    movlw	" "
    call	PI
    bra		AF_ON
AF_OFF   
    movlw	"F"
    call	PI
    movlw	"F"
    call	PI
       
AF_ON 
    movlw   0x00
    btfsc   Menu_osc,0  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    
    bcf		Si,7
;trigr
    call	PISM
    de	0,14,201,""
    movlw   0x00
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    movlw   0x00
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    
    call	PISM
    de	0,15,201,""
    movlw   0x00
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    movlw   0x00
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    
    bcf	    Si,7
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    bsf	    Si,7

    call    PISM
    de	6,14,203,"Trigg:"
    
    movlw   0x00
    btfsc   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw   0xFF
    call    CL
    
    btfss   Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    bra	    TRIG_neoznac
    
    call    PODTRHNI
    de	39,13,201,15  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,7,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,10,201,8  ;pocet,rádek,start,typ
    call    PODTRHNI
    de	39,4,201,8  ;pocet,rádek,start,typ
    
TRIG_neoznac  
    btfsc   zdtrig,4
    goto mmmj   
    btfsc   zdtrig,3
    goto mmm
    btfsc   zdtrig,2
    goto jjj
    btfsc   zdtrig,1
    goto qqq
    btfss   zdtrig,0
    goto FFF

    call	PISM
    de	6,15,203," MAX  "
    goto FFF
qqq
    call	PISM
    de	6,15,203," FAL  "
    goto FFF
jjj
    call	PISM
    de	6,15,203," RIS  "
    goto FFF
mmmj
    call	PISM
    de	6,15,203," EXT  "
    goto FFF
mmm
    call	PISM
    de	6,15,203," NONE "   
FFF
    movlw	0x00
    btfsc	Menu_osc,6  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    call	PISM
    de	0,8,201,""
    
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL

    call	PISM
    de	0,9,201,""
    
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    bcf		Si,7
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
        
    btfsc   T_base_n,7
    BRA	    B_n500
    btfsc   T_base_n,6
    BRA	    B_u1
    btfsc   T_base_n,5
    BRA	    B_u2
    btfsc   T_base_n,4
    BRA	    B_u5
    btfsc   T_base_n,3
    BRA	    B_u10
    btfsc   T_base_n,2
    BRA	    B_u20
    btfsc   T_base_n,1
    BRA	    B_u50
    btfsc   T_base_n,0
    BRA	    B_u100
    btfsc   T_base_v,0
    BRA	    B_u200
    btfsc   T_base_v,1
    BRA	    B_u500
    btfsc   T_base_v,2
    BRA	    B_m1
    btfsc   T_base_v,3
    BRA	    B_m2
    btfsc   T_base_v,4
    BRA	    B_m5
    btfsc   T_base_v,5
    BRA	    B_m10
    btfsc   T_base_v,6
    BRA	    B_m20
    btfsc   T_base_v,7 
    BRA	    B_m50
    
B_n500    
    call	PISM
	de	6,8,203,"TB:500"
    bra    dalsi_radek        
B_u1    
    call	PISM
	de	6,8,203,"TB: 1 "
    bra    dalsi_radek         
B_u2    
    call	PISM
	de	6,8,203,"TB: 2 "
    bra    dalsi_radek    
B_u5    
    call	PISM
	de	6,8,203,"TB: 5 "
    bra    dalsi_radek    
B_u10    
    call	PISM
	de	6,8,203,"TB: 10"
    bra    dalsi_radek   
B_u20    
    call	PISM
	de	6,8,203,"TB: 20"
    bra    dalsi_radek
B_u50    
    call	PISM
	de	6,8,203,"TB: 50"
    bra    dalsi_radek
B_u100
    call	PISM
	de	6,8,203,"TB:100"
    bra    dalsi_radek
B_u200
    call	PISM
	de	6,8,203,"TB:200"
    bra    dalsi_radek
B_u500
    call	PISM
	de	6,8,203,"TB:500"
    bra    dalsi_radek
B_m1
    call	PISM
	de	6,8,203,"TB: 1 "
    bra    dalsi_radek
B_m2
    call	PISM
	de	6,8,203,"TB: 2 "
    bra    dalsi_radek
B_m5
    call	PISM
	de	6,8,203,"TB: 5 "
    bra    dalsi_radek
B_m10
    call	PISM
	de	6,8,203,"TB:10 "
    bra    dalsi_radek
B_m20
    call	PISM
	de	6,8,203,"TB:20 "
    bra    dalsi_radek
B_m50
    call	PISM
	de	6,8,203,"TB:50 "


dalsi_radek
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL	
	
    btfsc   T_base_n,7
    goto    nS
    
    movf    T_base_v,0
    SUBLW   2
    BNC	    mS
    
    call	PISM
    de	6,9,203,151,"S/div"
    bra	    uS
mS
    call	PISM
    de	6,9,203,"mS/div"
    goto     uS

nS
    call	PISM
    de	6,9,203,"nS/div"
uS   
    movlw	0x00
    btfsc	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    bcf		Si,7
    
    btfss	Menu_osc,4  ;ozna?í p?íslu¨ný nastavení bíle
    bra		TB_neoznac
    call	PODTRHNI
    de		39,7,201,15  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,10,201,240  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,13,201,8  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,4,201,8  ;pocet,rádek,start,typ

TB_neoznac
    call	PISM
    de	0,11,201,""
    
    movlw	0x00
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL

    call	PISM
    de	0,12,201,""
    
    movlw	0x00
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    movlw	0x00
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
    
    bcf		Si,7
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    bsf		Si,7
    
 nop
    btfsc    VERTIZES,0
    goto  m5
    btfsc    VERTIZES,1
    goto  m10
    btfsc    VERTIZES,2
    goto  m20
    btfsc    VERTIZES,3
    goto  m50
    btfsc    VERTIZES,4
    goto  m100
    btfsc    VERTIZES,5
    goto  m200
    btfsc    VERTIZES,6
    goto  m500
    btfsc    VERTIZES,7
    goto  m1V
    btfsc    VERTIZES2,0
    goto  m2V
    btfsc    VERTIZES2,1
    goto  m5V
    btfsc    VERTIZES2,2
    goto  m10V
    btfsc    VERTIZES2,3
    goto  m20V
   
m20V
    call        PISM
    de      6,11,203,"VA:20 "
    goto    dalls
       
m10V
    call        PISM
    de      6,11,203,"VA:10 "
    goto    dalls
       
m5V
    call        PISM
    de      6,11,203,"VA: 5 "
    goto    dalls  

    
m2V
    call        PISM
    de      6,11,203,"VA: 2 "
    goto    dalls
       
m5
    call        PISM
    de      6,11,203,"VA: 5 "
    goto    dalls
       
m10
    call        PISM
    de      6,11,203,"VA:10 "
    goto    dalls
       
m20
    call        PISM
    de      6,11,203,"VA:20 "
    goto    dalls
       
m50
    call        PISM
    de      6,11,203,"VA:50 "
    goto    dalls
       
m200
    call        PISM
    de      6,11,203,"VA:200"

    goto    dalls
       
m500
    call        PISM
    de      6,11,203,"VA:500"
    goto    dalls
    
m1V
    call        PISM
    de      6,11,203,"VA: 1 "
    goto    dalls
    
m100
    call        PISM
    de      6,11,203,"VA:100"


dalls
    movlw	0x00
    btfsc	Menu_osc,5  ;oznací p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL
 
    btfsc    VERTIZES,6
    BRA	     VA_mV
    btfsc    VERTIZES,7
    BRA	     V
    MOVF     VERTIZES2,0
    btfss    STATUS,Z
    BRA	     V
    
VA_mV
    call	PISM
    de	6,12,203,"mV/div"
    BRA	    mV
V
    call	PISM
    de	6,12,203," V/div"
mV
    movlw	0x00
    btfsc	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    movlw	0xFF
    call	CL	
        
    btfss	Menu_osc,5  ;ozna?í p?íslu¨ný nastavení bíle
    bra		VA_neoznac
    call	PODTRHNI
    de		39,4,201,8  ;pocet,rádek,start,typ  
    call	PODTRHNI
    de		39,7,201,8  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,10,201,15  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,13,201,240  ;pocet,rádek,start,typ
VA_neoznac    
    bcf		Si,7
    bcf	    nastav0,5
    bcf	    nastav0,1
    return
    
    
OPT_menu2
    
    bcf	    Si,7
    btfsc   Menu_osc2,0,1  ;ozna?í p?íslu¨ný nastavení bíle
    bsf	    Si,7
    
    call	PISM
    de	6,0,201,"  Run "
    
    call	PISM
    de	0,1,203,""
    movlw	0x00
    call	CL
    
    call	PISM
    de	6,1,204," Mode:"
        
    call	PODTRHNI
    de		39,2,201,0  ;pocet,rádek,start,typ
    
    btfsc    RUN_MODE,2,1
    goto     RUN
    btfsc    RUN_MODE,1,1
    goto     STOP
    btfss    RUN_MODE,0,1
    goto     RUN_DAL

    call	PISM
    de	6,3,201,"  R&S "
    goto RUN_DAL
RUN
    call	PISM
    de	6,3,201,"  RUN "
    goto RUN_DAL
STOP
    call	PISM
    de	6,3,203," STOP "
RUN_DAL
    movlw	0x00
    call	CL
   
    nop
    
    call	PODTRHNI
    de		39,4,201,16  ;pocet,rádek,start,typ
    
    bcf	    Si,7
    btfsc   Menu_osc2,1,1  ;ozna?í p?íslu¨ný nastavení bíle
    bsf	    Si,7

    call	PISM
    de	6,5,201," Trigg"
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL
    
    call	PISM
    de	1,6,201," "
    call	PISM
    de	6,6,204,"level:"
    
    call	PODTRHNI
    de		39,7,201,0  ;pocet,rádek,start,typ
    
    call	PISM
    de	2,8,201,"  "
    
    clrf    bin1
    movf    TRIG_lvl,0,1
    movwf   bin0
    
    call    covert

    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	" "
    call	PI
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL
    
    call	PODTRHNI
    de		39,9,201,16  ;pocet,rádek,start,typ
    
    bcf	    Si,7
    btfsc   Menu_osc2,2,1  ;ozna?í p?íslu¨ný nastavení bíle
    bsf	    Si,7
    
    call	PISM
    de	1,10,201," "

    call	PISM
    de	6,10,204,"Shift:"
    
    call	PISM
    de	2,11,201,"  "
    clrf    bin1
    movf    SHIFT_sig,0,1
    movwf   bin0
    
    clrf   bin1
    
    movf	SHIFT_sig,0,1
    btfsc	SHIFT_sig,7,1
    comf	SHIFT_sig,0,1
    btfsc	SHIFT_sig,7,1  
    addlw	1

    movwf	bin0
    
    call    covert
    
    movlw	"-"
    btfsc	SHIFT_sig,7,1
    call	PI
    
    movf	digit2,0
    call	PI
    movf	digit1,0
    call	PI
    movf	digit0,0
    call	PI
    movlw	" "
    btfss	SHIFT_sig,7,1
    call	PI
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL
    movlw	0x00
    call	CL

    call	PODTRHNI
    de		39,12,201,16  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,13,201,0  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,14,201,0  ;pocet,rádek,start,typ
    call	PODTRHNI
    de		39,15,201,0  ;pocet,rádek,start,typ

    bcf		Si,7
    bcf	    nastav0,5
    bcf	    nastav0,1
    return
    
interpol
    bcf nastav0,2
;vyradí záparná císla
   btfsc   INDF1,7
   goto pokracuj
;odelení 0 a 1 rozdílů
    movf    INDF1,0
    btfsc   STATUS,Z
    goto     koncit

    decf    INDF1,1
    movf    INDF1,0
    btfsc   STATUS,Z
    goto     koncit
;inkrementace
    incf    INDF1,1
    incf    INDF1,1
;kladný základ
kladny
    bsf     STATUS,C
    DCFSNZ  INDF1,1
    bsf     nastav0,2

    btfsc  nastav0,2
    bcf    STATUS,C
    RRCF   BAR,1

    decfsz  X,1
    goto kladny
    goto pokracuj

koncit
;pro nulový rozdíl
    bsf     STATUS,C
konci
    RRCF   BAR,1
    bcf     STATUS,C
    decfsz  X,1
    goto    konci
    bsf INDF1,7
    goto pokracuj

;kladný přídavek nad
inter
    btfsc   INDF1,7
    goto pokracuj

    bcf     nastav0,2
intr
    bsf     STATUS,C
    DCFSNZ  INDF1,1
    bsf     nastav0,2

    btfsc   nastav0,2
    bcf	    STATUS,C

    RRCF   BAR,1

    decfsz  X,1
    goto    intr
    goto pokracuj

;záporný prídavek/základ POD
interneg
    btfsS   INDF1,7
    goto pokracuj

    INCF    INDF1,1
    movf    INDF1,0
    btfsc   STATUS,Z
    goto    koncit

INGB
    decf    INDF1,1
    decf    INDF1,1
    bcf     nastav0,2
intre
    bsf     STATUS,C
    INFSNZ   INDF1,1
    bsf     nastav0,2

    btfsc   nastav0,2
    bcf	    STATUS,C

    RRCF    BAR,1
    decf    INDF0,1
    decfsz  X,1
    goto    intre
;    bsf INDF1,7

    movf    INDF1,0
    btfss   STATUS,Z
    INCF    INDF1,1
    goto pokracuj

nulla
    movlw   0
    call    CL
    goto beznul

;/////////////////////////////////////////////////////////////////////////////////
;nakrelí Bar graf vertikální
kresliV
    MOVFF	TOSL,TBLPTRL
    MOVFF	TOSH,TBLPTRH

    btfsc	Si,0
    decf	TBLPTRL,1
    bsf		Si,0

    TBLRD*+
    ;sloupec
    ;MOVF	TABLAT,0
    movlw   64
    movwf   RADEK

    TBLRD*+
    MOVF	TABLAT,0
    movwf	X           ;sírka

    TBLRD*+
    MOVF	TABLAT,0
    movwf	Y	    ;vstup AD

    TBLRD*+
    MOVF	TABLAT,0
    movwf	konfi	    ;Typ grafu

 ;nactení dat z AD
    RLNCF   Y,1
    RLNCF   Y,0
    andlw   01111100b
    movwf   Y

    movlw	00100000b
    movwf	ADCON1
    movlw	00011010b
    movwf	ADCON2
    movlw	00000011b
    addwf	Y,0
    movwf	ADCON0

ddag	btfsc	ADCON0,1
    goto	ddag

    RRNCF   ADRESH,1
    RRNCF   ADRESH,0
    andlw   00111111b
    movwf   BAR

   ; incf    BAR,1

    bcf     MEZ1,7
    movf    BAR,0
    movwf   konfi1

    movlw   255
    movwf   Xl

    Btfsc   STATUS,Z
    clrf    Xl
    Btfsc   STATUS,Z
    goto    oto         ;pokud je 0

radekd
;=============================
    bcf	RS_LCD
;Y rádek
    decf    RADEK,1
    movf    RADEK,0
    andlw   00011111b
    ADDLW   10000000b
    call    CL
;X pocátek
    movlw   10000110b
    btfsc   RADEK,5
    addlw   00001000b
    call    CL
    bsf	RS_LCD
;=============================

    btfsc    MEZ1,7
    goto     ffer
    DCFSNZ   konfi1,1
    goto     oto
ffer
    movf    Xl,0
    call    CL
fetzr
    movf    RADEK,1
    BNZ  radekd

   ;návrat
    MOVF	TBLPTRL,0
    movwf	TOSL
    incf	TOSL,1
    MOVF	TBLPTRH,0
    movwf	TOSH
    return

oto
    movf    Xl,0
	call	CL
    bsf     MEZ1,7

    bsf    ADRESH,0
    incf   ADRESH,0
    btfsc   STATUS,Z
    goto    radekd
    clrf   Xl
    goto    radekd

;/////////////////////////////////////////////////////////////////////////////////
;nakrelí Bar graf harizontálně
kresli
; poc.rádek,sírka,vstup,fce
;fce = 0 bar, 1 bod

	MOVFF	TOSL,TBLPTRL
	MOVFF	TOSH,TBLPTRH

	btfsc	Si,0
	decf	TBLPTRL,1
	bsf	Si,0

	TBLRD*+
	MOVF	TABLAT,0
	movwf	RADEK	    ;rádek

	TBLRD*+
	MOVF	TABLAT,0
	movwf	X           ;sírka

	TBLRD*+
	MOVF	TABLAT,0
	movwf	Y	    ;vstup AD

	TBLRD*+
	MOVF	TABLAT,0
	movwf	konfi	    ;Typ grafu

    movlw   3
    movwf   konfi


 ;načtení dat z AD
    decf    RADEK,1
    RLNCF   Y,1
    RLNCF   Y,0
    andlw   01111100b
    movwf   Y

	movlw	00100000b
	movwf	ADCON1

	movlw	00011010b
	movwf	ADCON2

	movlw	00000011b
    addwf   Y,0
	movwf	ADCON0

ddagg	btfsc	ADCON0,1
	goto	ddagg

    RRNCF   ADRESH,0
    movwf   BAR
    bcf     BAR,7

radekdm
;=============================
	bcf	RS_LCD

;Y řádek
	incf    RADEK,1
    movf   RADEK,0
    andlw   00011111b
	ADDLW	10000000b
	call	CL

;X počátek
	movlw   10000000b
    btfsc   RADEK,5
    addlw	00001000b
	call	CL

	bsf	RS_LCD
;=============================
    bcf     MEZ1,7
    movf  BAR,0
    movwf    konfi1
    movlw   0
    btfss   konfi,0
    movlw   255
    movwf   Xl

	movlw	16
	movwf	CAR
dal
    btfsc    MEZ1,7
    goto    fetz
    movlw   8
    subwf   konfi1,1
    btfsc   STATUS,N
    goto    otoc
    btfss   konfi,1
    goto    fetz
    btfsc   STATUS,Z
    bsf     Xl,0
fetz
    movf    Xl,0
	call	CL
qwt
    decfsz CAR,1
    goto    dal

    decfsz  X,1
    goto    radekdm

;návrat
    MOVF	TBLPTRL,0
	movwf	TOSL
    incf    TOSL,1
	MOVF	TBLPTRH,0
	movwf	TOSH
	return

otoc
;-----------------------------
    btfss   konfi,0
    goto    htr

    clrf    Xl
    btfsc   konfi,1
    bsf  STATUS,C

    bsf     Xl,0
    negf    konfi1
    btfsc   konfi,1
    bsf  STATUS,C
posnz
   RLCF Xl,1
   bcf  STATUS,C
   decfsz konfi1,1
   goto posnz

;-----------------------------
   btfsc   konfi,0
   goto dsf

htr
   setf    Xl
   negf    konfi1
posunn
   bcf  STATUS,C
   RLCF Xl,1
   decfsz konfi1,1
   goto posunn
;-----------------------------
dsf
    movf Xl,0
	call	CL

    clrf    Xl
    bsf     MEZ1,7
    goto qwt
;-------------------------------------------------------------------------------------



;/////////////////////////////////////////////////////////////////////////////////
;načtení obrázku na LCD 128x64
obrazek
	movwf	TBLPTRH
	CLRF	TBLPTRL

	movlw	16
	movwf	obrR

	bcf	RS_LCD

    movlw   00000000b
	call	CL
    movlw   00010000b
	call	CL

    movlw   10111111b
	call	CL

	bsf	RS_LCD

znow
	movlw	240
	movwf	obrC

este
	TBLRD*+
;negace
    movlb 0
    btfss   obrmenu,0,1
    goto    BEZneg

    btfsc   Menur,0,1
    goto    spodek

    movf    obrR,0
    sublw   8
    BTFSS   STATUS,N
    GOTO    BEZneg
    goto    pokr
spodek
    movf    obrR,0
    sublw   8
    BTFSC   STATUS,N
    GOTO    BEZneg
pokr
    movf    obrC,0
    subwf   Menuh,0,1
    BTFSS   STATUS,C
    GOTO    BEZneg

    movf    obrC,0
    subwf   Menul,0,1
    BTFSC   STATUS,C
    GOTO    BEZneg

    comf    TABLAT,0
	call	CL
    goto    Sneg
;
BEZneg
	MOVF	TABLAT,0
	call	CL

Sneg
	decfsz	obrC,1
	goto	este

	decfsz	obrR,1
	goto	znow

	return
;------------------------
carka_1	
    call	PISM
    de		1,5,39,252  ;carka

    call	PISM
    de		1,10,39," "  ;carka
    call	PISM
    de		1,6,39," "  ;carka
    call	PISM
    de		1,7,39," "  ;carka
    call	PISM
    de		1,8,39," "  ;carka
    call	PISM
    de		1,9,39," "  ;carka
    call	PISM
;    nop
    return
    
carka_2	
    call	PISM
    de		1,5,79,252  ;carka

    call	PISM
    de		1,10,79," "  ;carka
    call	PISM
    de		1,6,79," "  ;carka
    call	PISM
    de		1,7,79," "  ;carka
    call	PISM
    de		1,8,79," "  ;carka
    call	PISM
    de		1,9,79," "  ;carka

    return
    
carka_3
    call	PISM
    de		1,5,118,252  ;carka
    
    call	PISM
    de		1,6,118," "  ;carka
    call	PISM
    de		1,7,118," "  ;carka
    call	PISM
    de		1,8,118," "  ;carka
    call	PISM
    de		1,9,118," "  ;carka
    call	PISM
    de		1,10,118," "  ;carka

    return
    
cisla
    call    covert
    
    movf    digit3,0
    call    cislo

    btfsc   VERTIZES,6
    call    carka_1	
    btfsc   VERTIZES,7
    call    carka_1		
    btfsc   VERTIZES2,0
    call    carka_1	

    movlw   39
    btfsc   VERTIZES,6
    addlw   6
    btfsc   VERTIZES,7
    addlw   6	
    btfsc   VERTIZES2,0
    addlw   6
    addwf   X2,1,1
    movf	digit2,0
    call	cislo
    
    btfsc   VERTIZES,0
    call    carka_2	
    btfsc   VERTIZES,1
    call    carka_2		
    btfsc   VERTIZES,2
    call    carka_2
    btfsc   VERTIZES2,3
    call    carka_2	
    btfsc   VERTIZES2,1
    call    carka_2		
    btfsc   VERTIZES2,2
    call    carka_2
    
    movlw   39
    btfsc   VERTIZES2,1
    addlw   6
    btfsc   VERTIZES2,2
    addlw   6	
    btfsc   VERTIZES2,3
    addlw   6
    btfsc   VERTIZES,1
    addlw   6
    btfsc   VERTIZES,2
    addlw   6	
    btfsc   VERTIZES,0
    addlw   6
    addwf   X2,1,1
    movf	digit1,0
    call	cislo
    
    btfsc   VERTIZES,3
    call    carka_3	
    btfsc   VERTIZES,4
    call    carka_3		
    btfsc   VERTIZES,5
    call    carka_3
    
    movlw   39
    btfsc   VERTIZES,3
    addlw   6
    btfsc   VERTIZES,4
    addlw   6	
    btfsc   VERTIZES,5
    addlw   6
    addwf   X2,1,1
    movf	digit0,0
    call	cislo
    
    movf    VERTIZES,0
    andlw   00111111b
    BTFSC   STATUS,Z
    goto    vecko
    
    movlw   39
    addwf   X2,1,1
    movlw   11
    call    cislo
    
vecko   
    movlw   38
    addwf   X2,1,1
    movlw   10
    call    cislo
    
    movf    VERTIZES,0
    andlw   00111111b
    BTFSS   STATUS,Z
    return
    
    movlw   40
    addwf   X2,1,1
    movlw   12
    call    cislo
    
    return
cislo	
 ;org 0x5500 / 48(8x8)*40
    movwf	TBLPTRL
    movlw	0x55	
    movwf	TBLPTRH

    movf	TBLPTRL,0
    mullw	240
    movf	PRODL,0
    movwf	TBLPTRL
    movf	PRODH,0
    addwf	TBLPTRH,1
    
    movlw	6   ;POCET RADKŮ
    movwf	obrR
    
jednuu
    bcf	    RS_LCD
    
    movf    X2,0,1
    andlw   00001111b
    call	CL

    swapf   X2,0,1
    andlw   00001111b
    addlw   00010000b
    call	CL
   
    decf    obrR,0
    addwf   RADEK2,0,1
    andlw   00001111b
    addlw   10110000b
    call	CL

    bsf	RS_LCD

    movlw	40  ;POČET SLOUPCU
    movwf	obrC

dall
	TBLRD*+
	MOVF	TABLAT,0
	call	CL

	decfsz	obrC,1
	goto	dall

	decfsz	obrR,1
	goto	jednuu
	    
    return
;--------------------------	
malyobr
    movlw   0x85
    movwf	TBLPTRH
    CLRF	TBLPTRL

	movlw	12
	movwf	obrR
jednuu1
    bcf	RS_LCD

    movlw   00000000b
    call	CL
    movlw   00010111b
    call	CL

    decf   obrR,0
    andlw   00001111b
    addlw   10110000b
    call	CL

    bsf	RS_LCD

    movlw	126
    movwf	obrC

dall1
	TBLRD*+
	MOVF	TABLAT,0
	call	CL

	decfsz	obrC,1
	goto	dall1

	decfsz	obrR,1
	goto	jednuu1

    return
;/////////////////////////////////////////////////////////////////////////////////

ROT
	BCF	RS_LCD

	movlw	64
	CPFSLT	POS
	clrf	POS

	movlw	11000000b
	addwf	POS,0
	call	CL

	incf	POS
	bsf	RS_LCD

	call	smycka
	call	smycka
	call	smycka
	RETURN


;////////////////////////////////////////////////////////////
;-------------------- P?EVODN?KY NA TEXT --------------------
;////////////////////////////////////////////////////////////


;--------------------------------------------------------------------------------
;znak pro   UC1608 / KS0108 6x8
;--------------------------------------------------------------------------------
PISM
    MOVFF	TOSL,TBLPTRL
    MOVFF	TOSH,TBLPTRH

    bsf	Si,0
	TBLRD*+

	MOVF	TABLAT,0
	movwf	MEZ
	btfsc	MEZ,0   ;test sudosti
	bsf		Si,1

	TBLRD*+

	MOVF	TABLAT,0
	movwf	RADEK   ;0-15
	TBLRD*+

	MOVF	TABLAT,0
	movwf	X       ;0-239

;=============================
	bcf	RS_LCD

	movf    X,0
	andlw   00001111b
	call	CL

	swapf    X,0
	andlw   00001111b
	addlw   00010000b
	call	CL

	movf	RADEK,0
	andlw   00001111b
	addlw   10110000b
	call	CL

	bsf	RS_LCD
;===============================

	MOVF	TBLPTRL,0
	movwf	PLICH
	MOVF	TBLPTRH,0
	movwf	STACKH

    ;kdyz je 0 PÍSMEN
    movf    MEZ,1
    btfsc   STATUS,Z
    goto    navratna

dalsi
	MOVf	PLICH,0
	movwf	TBLPTRL

	MOVF	STACKH,0
	MOVWF	TBLPTRH
	TBLRD*+

	MOVF	TBLPTRL,0
	movwf	PLICH
	MOVF	TBLPTRH,0
	movwf	STACKH

	Decf	MEZ,1
	movf	TABLAT,0
;??????????????????????????????????
PI
	MULWF	PET ; znak *6
	movlw	0x48
	addwf	PRODH,1	;(znak *6)+0x48

	MOVFF	PRODL,TBLPTRL
	MOVFF	PRODH,TBLPTRH

	MOVLW	6
	MOVWF	RCOUNT ; nahraj cítac

B6	TBLRD* 	; nacti bajt tabulky, na ktery ukazuje TBLPTR

	MOVFF	TABLAT,LCD_DATA ; posli to do Portu B

	btfsc	Si,7
	comf	LCD_DATA    ;negace

	btfsc   nastav0,5
	call    otocit	    ;rotace o 180°

	call	CLK
	incf	POZI,1
	INCF	TBLPTRL,F ; inkrementuj ukazatel na dalsi znak
	btfsc	STATUS,C
	incf	TBLPTRH,1

	DECF	RCOUNT, F ; dekrementuj citac
	BNZ		B6 ; opakuj, dokud citac nema hodnotu nula
;
	movf	MEZ,1
	BNZ dalsi
	BCF	STAT,0

	BTFSS	Si,0
	return

navratna
	MOVf	PLICH,0
	movwf	TOSL
	btfsS	Si,1
	    incf	TOSL,1
	MOVF	STACKH,0
	movwf	TOSH
	bcf	Si,0
	bcf	Si,1
	return

otocit
    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,1

    rrcf    LCD_DATA,1
    RLCF    bayt,0
    movwf   LCD_DATA
    return

;/////////////////////////////////////////////////
PODTRHNI   ;start,rádek,dékla,typ
    MOVFF	TOSL,TBLPTRL
    MOVFF	TOSH,TBLPTRH

    bsf	Si,0
    TBLRD*+

    MOVF	TABLAT,0
    movwf	MEZ
    TBLRD*+

    MOVF	TABLAT,0
    movwf	RADEK   ;0-15
    TBLRD*+

    MOVF	TABLAT,0
    movwf	X       ;0-239
    TBLRD*+

    MOVF	TABLAT,0
    movwf	CRAD    ;1,2...
;=============================
    bcf	RS_LCD
	movf    X,0
	andlw   00001111b
	call    CL

	swapf    X,0
	andlw   00001111b
	addlw   00010000b
	call	CL

	movf	RADEK,0
	andlw   00001111b
	addlw   10110000b
	call	CL
    bsf	RS_LCD
;===============================
    MOVF	TBLPTRL,0
    movwf	PLICH
    MOVF	TBLPTRH,0
    movwf	STACKH
dalsil
    movf    CRAD,0
    call    CL
    decfsz  MEZ,1
    goto    dalsil
;
    MOVf    PLICH,0
    movwf   TOSL
    MOVF    STACKH,0
    movwf   TOSH
    bcf	Si,0
    bcf	Si,1
    return

;mapíse text výska 16b Arial
PISARI
    MOVFF	TOSL,TBLPTRL
    MOVFF	TOSH,TBLPTRH

    bsf	Si,0
    TBLRD*+

    MOVF	TABLAT,0
    movwf	MEZ
    movwf	CRAD
    btfsc	MEZ,0   ;test sudosti
    bsf		Si,1

    TBLRD*+

    MOVF	TABLAT,0
    movwf	RADEK   ;0-15
    TBLRD*+

    MOVF	TABLAT,0
    movwf	X       ;0-239

    MOVF	TBLPTRL,0
    movwf	PLICH
    movwf	PLICHP
    MOVF	TBLPTRH,0
    movwf	STACKH
    movwf	STACKHP

druhyradek
;=============================
    bcf	RS_LCD

    movf    X,0
    andlw   00001111b
    call	CL

    swapf    X,0
    andlw   00001111b
    addlw   00010000b
    call	CL

    btfss    Si,5
    goto    drad

    btfss   nastav0,5
    decf    RADEK
    btfsc   nastav0,5
    incf RADEK,1
drad
    movf	RADEK,0
    andlw   00001111b
    addlw   10110000b
    call	CL

    bsf	RS_LCD
;===============================

dalsih
	MOVf	PLICH,0
	movwf	TBLPTRL

	MOVF	STACKH,0
	MOVWF	TBLPTRH
	TBLRD*+

	MOVF	TBLPTRL,0
	movwf	PLICH
	MOVF	TBLPTRH,0
	movwf	STACKH

	Decf	MEZ,1
;----------
    movlw   0x4E
    movwf   TBLPTRH
    movlw   32
    subwf   TABLAT,0

    movwf   TBLPTRL
    BCF     STATUS,C
    RLCF    TBLPTRL,1
    btfsc   STATUS,C
    incf    TBLPTRH,1

    TBLRD*+
    movf    TABLAT,0
    movwf   G
    TBLRD*+
    movf    TABLAT,0
    movwf   H

    TBLRD*+
    TBLRD*
    subwf   TABLAT,0
;    MOVLW   8
    MOVWF	RCOUNT ; nahraj čítač

    movf    H,0
    addlw   184 ;184
    movwf   TBLPTRL
    btfsc   STATUS,C
    incf    TBLPTRH,1
    movf    G,0
    addwf   TBLPTRH,1

     btfss   Si,5
     goto   B6h
     movlw   188
     addwf   TBLPTRL,1
     btfsc   STATUS,C
     incf    TBLPTRH,1
     movlw   2
     addwf   TBLPTRH,1

B6h	TBLRD* 	; čti bajt tabulky, na kter? ukazuje TBLPTR

    MOVFF	TABLAT,LCD_DATA ; po?li to do Portu B

    btfsc   nastav0,5
    call    otocit

    call	CLK

    INCF	TBLPTRL,F ; inkrementuj ukazatel na dal?? znak
    btfsc	STATUS,C
    incf	TBLPTRH,1

    DECF	RCOUNT, F ; dekrementuj ??ta?
    BNZ		B6h ; opakuj, dokud ??ta? nem? hodnotu nula

    clrf    LCD_DATA
    call	CLK
    call	CLK

    movf	MEZ,1
    BNZ dalsih
;	BCF	STAT,0

    ;druhý řádek
    btfsc    Si,5
    goto    pokra

    movf  CRAD,0
    movwf	MEZ

	MOVf	PLICHP,0
    movwf	PLICH

	MOVF	STACKHP,0
	MOVWF	STACKH

    bsf     Si,5
    goto    druhyradek
pokra
    bcf Si,5

	MOVf	PLICH,0
	movwf	TOSL
	btfsS	Si,1
	incf	TOSL,1
	MOVF	STACKH,0
	movwf	TOSH
	bcf	Si,0
	bcf	Si,1

	return
;////////////////////////////////////////////

CL
    movwf	LCD_DATA
    call	CLK
    return

;++++++++++++++++++++++++++++++++++
VYCISTIT

	bsf	RS_LCD
	movlw	16
	movwf	poc
	clrf	LCD_DATA
wwe
	movlw	240
	MOVWF	u
dd
	call	CLK
	DECF u,1
	BNZ dd

	decfsz	poc,1
	GOTO	wwe
	
	bcf	RS_LCD
	movlw	10000001b	;8b set Gain and Potentiometer
	call	CL
;kompenzace kontrastu ()
	movlw	8
	subwf	CONTRAST,0
	call	CL
	bsf	RS_LCD

	RETURN

LCD
	bcf	RS_LCD
	bcf	RW_LCD

	movlw	10101111b	;zapne LCD
	call	CL

	movlw	10001101b	;set increment
	call	CL

	movlw	01000000b	;StART line 0
	call	CL

	movlw	11101010b	;8b set BIAS 12 V
	call	CL


	movlw	10000001b	;8b set Gain and Potentiometer
	call	CL
;+
	movf    CONTRAST,0
;	movlw	10010111b	;8b set Gain and Potentiometer
	call	CL

	movlw	11001101b	;8b ;se mirorors
	call	CL
	
	movlw	00101111b	;8b ; Capacity load 60-90nF
	call	CL
	
	movlw	00100110b	;8b ; tempature compensation 0.1 %/°C
	call	CL

	movlw	10101111b	;zapne LCD
	call	CL

	movlw	10101111b	;zapne LCD
	call	CL

	bsf	RS_LCD
;	bsf	RW_LCD

	return
	
;casovací obvod lcd clk
CLK
;	bcf	RW_LCD
;	clrf TRISE
	;bcf TRISB,5
	;hold time
	movlw	40		;10/30
	movwf	ckl

mmk	decf	ckl,1
	BNZ mmk

	BcF	CLK_LCD
	movlw	8		;10/25
	movwf	ckl

nmk	decf	ckl,1
	BNZ nmk
	;rising edge
	BsF	CLK_LCD
	nop
;;	nop
	;bsf TRISB,5
;	setf TRISE
;	movlw	40		;100/10
;	movwf	ckl
;
;xxs	decf	ckl,1
;	BNZ xxs
;	
;	bsf	RW_LCD
	return

smycka
 	clrf G
Sf
	clrf	H
iiu	DECF H,1
	BNZ iiu
 	DECF G,1
	BNZ	Sf
	return

smyckaS
	clrf	H
mpk	DECF H,1
	BNZ mpk
	return

smyckaL             ;16Mhz 20.48mS
	movlw	5
	movwf	Je
SD
 	clrf G
SA
	clrf	H
uzt	DECF H,1
	BNZ uzt
 	DECF G,1
	BNZ	SA
	DECF Je,1
	BNZ	SD
	return

smyckaLL
	movlw	50
	movwf	Je
SDs
 	clrf G
SAs
	clrf	H
uzi	DECF H,1
	BNZ uzi
 	DECF G,1
	BNZ	SAs
	DECF Je,1
	BNZ	SDs
	return

smyckaL5
	movlw	38
	movwf	Je
SDsc
 	clrf G
SAsc
	clrf	H
uzic	DECF H,1
	BNZ uzic
 	DECF G,1
	BNZ	SAsc
	DECF Je,1
	BNZ	SDsc
	return
;IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

;odmonina
;
;----------------------------------------------------------
;;sqrt
;;
;; The purpose of this routine is take the square root of a 16 bit
;;unsigned integer.
;;Inputs:  N_hi - High byte of the 16 bit number to be square rooted
;;         N_lo - Low byte     "                  "             "
;;Outputs: W register returned with the 8 bit result
;;
;;Memory used:
;;  mask
;;  30 Instructions
;;  104 Cycles best case, 109 average, 122 worst case
;
;sqrt
;        MOVLW   0xc0   ;192        ;Initialize value for mask
;        MOVWF   mask
;        MOVLW   0x40   ;64         ;Initial value for the root
;
;sq1     SUBWF   N_hi,F          ;Subtract the root developed so far
;
;        BTFSS   STATUS,C        ;If it is larger than N_hi
;        goto  sq5             ;then go restore the subtraction
;
;sq2     IORWF   mask,W          ;Set the current bit
;sq3     RLCF     N_lo,F         ;Shift N left one position
;        RLCF     N_hi,F
;        RRCF     mask,F         ;Shift the mask right, and pick up msb of N
;        BTFSC   mask,7          ;If msb of N is set, then unconditionally
;        goto  sq6             ;set the next bit (because subtracting the
;                                ;root is guranteed not to cause a borrow)
;
;        XORWF   mask,W          ;Append "01" to the root developed so far
;
;        BTFSS   STATUS,C        ;If the lsb of mask was shifted into the carry
;        goto  sq1             ;then we're done. Otherwise, loop again.
;
;   ;We are almost done. In the last iteration, we have 7 bits of the root. When
;   ;"01" is appended to it, we will have a 9-bit number that must be subtracted
;   ;from N.
;
;        SUBWF   N_hi,F          ;
;        BTFSS   STATUS,C        ;If the upper 7 bits cause a borrow, then
;        RETURN                ;the appended "01" will as well: We're done.
;
;        BTFSC   STATUS,Z       ;If the result of the subtraction is zero
;        BTFSC N_lo,7           ;AND the msb of N_lo is set then the LSB of the
;                               ;root is zero.
;        XORLW  1               ;Otherwise, it is one.
;
;        RETURN
;
;sq6     BTFSC   STATUS,C        ;Need to unconditionally set the current bit of the root.
;        RETURN                  ;However, if we're through iterating, then leave. Note,
;                                ;C is set by shifting the mask right and the LSB of root
;                                ;was set by IORWF at sq2.
;
;        BCF     mask,7          ;Clear the MSB of N that got shifted into the mask.
;        XORWF   mask,W          ;Append "01" to the root developed so far.
;        SUBWF   N_hi,F          ;Subtract
;        goto    sq2             ;Go unconditionally set the current bit.
;
;sq5     ADDWF   N_hi,F          ;Restore N_hi by reversing the SUBWF with a ADDWF
;        goto    sq3             ;Don't set the current bit




        END