       #include <p16f628a.inc>
             LIST        p=16F628A    ; Установка типа микроконтроллера.
            __CONFIG    3F0AH 


Sec         equ         20h
Sec0        equ         21h
shet        equ         22h
w_temp      equ         23h
status_temp equ         24h
var         equ         25h
skvlin      equ         26h
skvlog      equ         27h
skvstep     equ         28h
skv         equ         2Ah

logvar      equ         2Ch
stepvar     equ         2Dh
skvvar      equ         2Eh
varL        equ         2Fh
ost         equ         30h
varxL       equ         31h
varxH       equ         32h
varHdel     equ         33h
varLdel     equ         34h


#define    lin         PORTB,0
#define    log         PORTB,1
#define    step        PORTB,2
#define    sb          PORTA,2



            org         0           ; Начать выполнение программы с адреса 0 PC.
            goto        Start       ; Переход в ПП Start.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;подпограмма обработки прерываний, здесь реализован 3-х канальный ШИМ (8 бит на канал)
;частота ШИМ примерно 330Гц
              
            org         4           
           
inter       movwf       w_temp
            swapf       STATUS,W
            movwf       status_temp

            

            incfsz      var,F
            goto        met10
            bsf         PORTB,0
            bsf         PORTB,1
            bsf         PORTB,2           
met10       movf        var,W
            subwf       skvlin,W
            btfss       STATUS,C ;12                             
            bcf         lin                        
            movf        var,W
            subwf       skvlog,W
            btfss       STATUS,C                                 
            bcf         log
            movf        var,W
            subwf       skvstep,W
            btfss       STATUS,C                           
            bcf         step
            bcf         INTCON,T0IF 
            movlw       .221
            movwf       TMR0  
a1a         swapf       status_temp,W
            movwf       STATUS
            swapf       w_temp,F
            swapf       w_temp,W
            retfie                     ;30 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Start       movlw       b'00000111'
            movwf       CMCON
            movlw       b'00000000'
            movwf       PORTA
            movlw       b'00000111'
            movwf       PORTB
            
            bsf         STATUS,RP0
            movlw       b'11111111'
            movwf       TRISA
            movlw       b'11111000'
            movwf       TRISB
            
            bcf         STATUS,RP0
            
            
            movlw       .255
            movwf       skvlin
            movwf       skvlog
            movwf       skvstep
            

            clrf        var
            
           

            
            bcf         INTCON,T0IF        ;сброс флага переполнения TMR0
            clrf        TMR0               ;очистка таймера TMR0
            bsf         INTCON,T0IE        ;разрешим прерывания TMR0
            bsf         STATUS,RP0 
            bcf         OPTION_REG,T0CS    ;выбор тактового сигнала TMR0
            bcf         STATUS,RP0

            bsf         INTCON,GIE


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            movlw       .255
            movwf       skv
         
a1          incf        skv,F
            movf        skv,W
            movwf       skvvar

            movwf       logvar
            call        logarf
            movwf       logvar
            comf        logvar,F
            movf        skvvar,W
            movwf       stepvar
            call        stepen
            movwf       stepvar
            comf        stepvar,F 
            comf        skvvar,F
            bcf         INTCON,GIE
            movf        skvvar,W
            movwf       skvlin
            movf        logvar,W
            movwf       skvlog
            movf        stepvar,W
            movwf       skvstep
            bsf         INTCON,GIE
            call        pause
       
            btfsc       sb
            goto        a11
a12         call        pausknp
            btfss       sb
            goto        a12
            goto        knop

a11         movlw       .255
            subwf       skv,W
            btfss       STATUS,Z
            goto        a1
         

b1          decf        skv,F
            movf        skv,W
            movwf       skvvar

            movwf       logvar
            call        logarf
            movwf       logvar
            comf        logvar,F
            movf        skvvar,W
            movwf       stepvar
            call        stepen
            movwf       stepvar
            comf        stepvar,F 
            comf        skvvar,F
            bcf         INTCON,GIE
            movf        skvvar,W
            movwf       skvlin
            movf        logvar,W
            movwf       skvlog
            movf        stepvar,W
            movwf       skvstep
            bsf         INTCON,GIE
            call        pause

            btfsc       sb
            goto        b11
b12         call        pausknp
            btfss       sb
            goto        b12
            goto        knop

b11         movlw       .0
            subwf       skv,W
            btfss       STATUS,Z
            goto        b1
cf1         goto        a1





knop        movlw       .255
            movwf       skv
            movwf       skvvar

            movwf       logvar
            call        logarf
            movwf       logvar
            comf        logvar,F
            movf        skvvar,W
            movwf       stepvar
            call        stepen
            movwf       stepvar
            comf        stepvar,F 
            comf        skvvar,F
            bcf         INTCON,GIE
            movf        skvvar,W
            movwf       skvlin
            movf        logvar,W
            movwf       skvlog
            movf        stepvar,W
            movwf       skvstep
            bsf         INTCON,GIE

c1          call        pausknp
            btfsc       sb
            goto        c1
c2          call        pausknp
            btfss       sb
            goto        c2
            

            movlw       .128
            movwf       skv
            movwf       skvvar

            movwf       logvar
            call        logarf
            movwf       logvar
            comf        logvar,F
            movf        skvvar,W
            movwf       stepvar
            call        stepen
            movwf       stepvar
            comf        stepvar,F 
            comf        skvvar,F
            bcf         INTCON,GIE
            movf        skvvar,W
            movwf       skvlin
            movf        logvar,W
            movwf       skvlog
            movf        stepvar,W
            movwf       skvstep
            bsf         INTCON,GIE

c11         call        pausknp
            btfsc       sb
            goto        c11
c22         call        pausknp
            btfss       sb
            goto        c22
            goto        knop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; подпрграмма паузы

pause        movlw       .84
             movwf       Sec0
p2           movlw       .255
             movwf       Sec
p1           decfsz      Sec,F
             goto        p1
             decfsz      Sec0,F
             goto        p2
             return

pausknp      movlw       .32       ;5ms
             movwf       Sec0
pp2          movlw       .255
             movwf       Sec
pp1          decfsz      Sec,F
             goto        pp1
             decfsz      Sec0,F
             goto        pp2
             return          
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                 
logarf      movlw       high text       
            movwf       PCLATH       ;
            movf        logvar,W        ; 
            addlw       low text     ; 
            btfsc       STATUS,C
            incf        PCLATH,F
            movf        logvar,W
            addwf       PCL,F
text        dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01;
            dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01;
            dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01;
            dt 0x01, 0x02, 0x02, 0x02, 0x02, 0x02;
            dt 0x02, 0x02, 0x02, 0x02, 0x02, 0x02;
            dt 0x02, 0x02, 0x02, 0x02, 0x02, 0x02;
            dt 0x02, 0x02, 0x02, 0x02, 0x02, 0x02;
            dt 0x02, 0x03, 0x03, 0x03, 0x03, 0x03;
            dt 0x03, 0x03, 0x03, 0x03, 0x03, 0x03;
            dt 0x03, 0x03, 0x03, 0x03, 0x04, 0x04;
            dt 0x04, 0x04, 0x04, 0x04, 0x04, 0x04;
            dt 0x04, 0x04, 0x04, 0x04, 0x05, 0x05;
            dt 0x05, 0x05, 0x05, 0x05, 0x05, 0x05;
            dt 0x05, 0x06, 0x06, 0x06, 0x06, 0x06;
            dt 0x06, 0x06, 0x06, 0x07, 0x07, 0x07;
            dt 0x07, 0x07, 0x07, 0x08, 0x08, 0x08;
            dt 0x08, 0x08, 0x08, 0x09, 0x09, 0x09;
            dt 0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0A;
            dt 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C;
            dt 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D;
            dt 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F;
            dt 0x0F, 0x10, 0x10, 0x10, 0x11, 0x11;
            dt 0x12, 0x12, 0x12, 0x13, 0x13, 0x14;
            dt 0x14, 0x14, 0x15, 0x15, 0x16, 0x16;
            dt 0x17, 0x17, 0x18, 0x18, 0x19, 0x19;
            dt 0x1A, 0x1B, 0x1B, 0x1C, 0x1C, 0x1D;
            dt 0x1E, 0x1E, 0x1F, 0x20, 0x20, 0x21;
            dt 0x22, 0x23, 0x23, 0x24, 0x25, 0x26;
            dt 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B;
            dt 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31;
            dt 0x32, 0x33, 0x34, 0x35, 0x37, 0x38;
            dt 0x39, 0x3A, 0x3B, 0x3D, 0x3E, 0x3F;
            dt 0x41, 0x42, 0x44, 0x45, 0x47, 0x48;
            dt 0x4A, 0x4C, 0x4D, 0x4F, 0x51, 0x52;
            dt 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E;
            dt 0x60, 0x62, 0x64, 0x66, 0x69, 0x6B;
            dt 0x6D, 0x70, 0x72, 0x75, 0x77, 0x7A;
            dt 0x7C, 0x7F, 0x82, 0x85, 0x88, 0x8B;
            dt 0x8E, 0x91, 0x94, 0x97, 0x9B, 0x9E;
            dt 0xA2, 0xA5, 0xA9, 0xAC, 0xB0, 0xB4;
            dt 0xB8, 0xBC, 0xC0, 0xC4, 0xC9, 0xCD;
            dt 0xD2, 0xD6, 0xDB, 0xE0, 0xE5, 0xEA;
            dt 0xEF, 0xF4, 0xF9, 0xFF;





stepen      movlw       high text1       
            movwf       PCLATH       ;
            movf        stepvar,W        ; 
            addlw       low text1     ; 
            btfsc       STATUS,C
            incf        PCLATH,F
            movf        stepvar,W
            addwf       PCL,F
text1       dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
            dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
            dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
            dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
            dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
            dt 0x00, 0x00, 0x00, 0x01, 0x01, 0x01;
            dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01;
            dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x02;
            dt 0x02, 0x02, 0x02, 0x02, 0x02, 0x02;
            dt 0x02, 0x02, 0x03, 0x03, 0x03, 0x03;
            dt 0x03, 0x03, 0x04, 0x04, 0x04, 0x04;
            dt 0x04, 0x04, 0x05, 0x05, 0x05, 0x05;
            dt 0x06, 0x06, 0x06, 0x06, 0x07, 0x07;
            dt 0x07, 0x07, 0x08, 0x08, 0x08, 0x08;
            dt 0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A;
            dt 0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0D;
            dt 0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F;
            dt 0x10, 0x10, 0x11, 0x11, 0x12, 0x12;
            dt 0x13, 0x13, 0x14, 0x14, 0x15, 0x16;
            dt 0x16, 0x17, 0x17, 0x18, 0x19, 0x19;
            dt 0x1A, 0x1B, 0x1B, 0x1C, 0x1D, 0x1D;
            dt 0x1E, 0x1F, 0x20, 0x20, 0x21, 0x22;
            dt 0x23, 0x23, 0x24, 0x25, 0x26, 0x27;
            dt 0x28, 0x29, 0x29, 0x2A, 0x2B, 0x2C;
            dt 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32;
            dt 0x33, 0x34, 0x35, 0x36, 0x37, 0x38;
            dt 0x39, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F;
            dt 0x40, 0x42, 0x43, 0x44, 0x45, 0x47;
            dt 0x48, 0x49, 0x4B, 0x4C, 0x4D, 0x4F;
            dt 0x50, 0x51, 0x53, 0x54, 0x56, 0x57;
            dt 0x59, 0x5A, 0x5C, 0x5D, 0x5F, 0x60;
            dt 0x62, 0x64, 0x65, 0x67, 0x68, 0x6A;
            dt 0x6C, 0x6E, 0x6F, 0x71, 0x73, 0x75;
            dt 0x76, 0x78, 0x7A, 0x7C, 0x7E, 0x80;
            dt 0x82, 0x84, 0x85, 0x87, 0x89, 0x8B;
            dt 0x8E, 0x90, 0x92, 0x94, 0x96, 0x98;
            dt 0x9A, 0x9C, 0x9E, 0xA1, 0xA3, 0xA5;
            dt 0xA7, 0xAA, 0xAC, 0xAE, 0xB1, 0xB3;
            dt 0xB6, 0xB8, 0xBA, 0xBD, 0xBF, 0xC2;
            dt 0xC4, 0xC7, 0xCA, 0xCC, 0xCF, 0xD1;
            dt 0xD4, 0xD7, 0xD9, 0xDC, 0xDF, 0xE2;
            dt 0xE5, 0xE7, 0xEA, 0xED, 0xF0, 0xF3;
            dt 0xF6, 0xF9, 0xFC, 0xFF;

             end 


