CHAPTER -3 PROGRAMS & REFERENCES

Page | 33

INC> RLF PORTB.1 CALL DELAY DECFSZ GOTO $-3 GOTO $-8 COUNT.PROGRAMS:PROGRAM FOR LED BLINKING:LISTP=PIC16F877A # INCLUDE<P16F877A.1 $-5 BANKSEL TRISB CLRF TRISB BANKSEL PORTB MOVLW MOVWF BSF 0X04 COUNT PROGRAM FOR SEVEN SEGMENT DISPLAY LIST P = PIC16F877A PORTB.1 $-1 DEL1.1 _CONFIG_CP_OFF&WDT_OFF&_PWRTE_ ON&_XT_OSC CBLOCK DEL1 DEL2 COUNT ENDC ORG 0x00 GOTO START START: CLRF PORTB 0x20 DELAY: MOVLW MOVWF MOVLW MOVWF DECFSZ GOTO DECFSZ GOTO RETURN END 0XFF DEL1 0XFF DEL2 DEL2.INC> CALL DELAY Page | 34 .0 #INCLUDE<P16F877A.

3 PORTB.INC> ORG 0x00 GOTO START START: CLRF PORTB CLRF PORTA CLRF PORTD CLRF ADCON0 CLRF ADRESH BANKSEL TRISA CLRF TRISB Page | 35 .2 0XF3 PORTC PORTB.3 LOOP CLRF PORTC MOVLW MOVWF LOOP MOVLW MOVWF BCF BSF MOVLW MOVWF BCF BSF MOVLW MOVWF 0X49 PORTC PORTB.0 PORTB.2 PORTB.1 0X49 PORTC 0X0F PORTB PROGRAM FOR ANALOG TO DIGITAL CONVERTER LIST P = PIC16F877A #INCLUDE<P16F877A.ORG 0x00 GOTO START START: CLRF PORTB BANKSEL TRISB CLRF TRISB CLRF TRISC BANKSEL PORTC BCF BSF MOVLW MOVWF BCF BSF GOTO END PORTB.0 0XF3 PORTC PORTB.1 PORTB.

0 PROGRAM FOR PWM LIST P=PIC16F877A #INCLUDE<P16F877A.W BANKSEL MOVWF PORTD PORTD .W MOVWF BANKSEL PORTB ADRESL ADCON0.2 ADCON0.6 CONVERT CLRF ADRESL BANKSEL PORTA BSF NOP NOP GOTO CONVERT ADCON0.2 CLRF T2CON BANKSEL CLRF TRISC BANKSEL MOVLW MOVWF BANKSEL MOVLW MOVWF MOVLW PR2 .13 CCPR1L 0X0C Page | 36 TRISC MOVF ADRESL.INC> ORG 0x00 GOTO START START: CLRF PORTC CONVERT BSF BTFSC GOTO $-1 MOVF ADRESH.40 PR2 CCPR1L .CLRF TRISD MOVLW MOVWF MOVLW MOVWF 0XFF TRISA 0XFE ADCON1 BCF GOTO END PIR1.

W XORWF MOTOR1.0 Page | 37 .INC> INT BANKSEL MOVLW MOVWF PORTC 0XFD MOTOR1 0XFB MOTOR2 0XF9 MOTOR3 0XF7 MOTOR4 0XFA MOTOR5 CBLOCK MOTOR1 MOTOR2 MOTOR3 MOTOR4 MOTOR5 ENDC ORG 0x00 0x20 MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF RETURN SCAN GOTO START START: CLRF PORTC CLRF PORTD MOVF PORTC.TMR2ON BANKSEL TRISD CLRF TRISD MOVLW MOVWF CALL INT GOTO SCAN 0XFF TRISC PROGRAM USING RETLW LIST P = PIC16F877A #INCLUDE<P16F877A.MOVWF BSF GOTO $ END CCP1CON T2CON.

W XORWF MOTOR3.2 GOTO M3 MOVLW 0X01 M5 CALL TABLE MOVWF GOTO SCAN M3 MOVF PORTC.0 BTFSSSTATUS.0 BTFSSSTATUS.2 GOTO M2 MOVLW 0X00 M4 MOVWF GOTO SCAN PORTD CALL TABLE MOVWF GOTO SCAN M2 MOVF PORTC.0 PORTD MOVF PORTC.2 GOTO M5 MOVLW 0X03 CALL TABLE MOVWF GOTO SCAN PORTD BTFSSSTATUS.0 PORTD MOVF PORTC.BTFSSSTATUS.W XORWF MOTOR5.2 GOTO M4 MOVLW 0X02 CALL TABLE TABLE Page | 38 .W XORWF MOTOR4.W XORWF MOTOR2.2 GOTO SCAN MOVLW 0X04 CALL TABLE MOVWF GOTO SCAN PORTD BTFSSSTATUS.

0 CALL CLOCKWISE PROGRAM FOR STEPPER MOTOR LIST P = PIC16F877A #INCLUDE<P16F877A.INC> CBLOCK DEL1 DEL2 ENDC ORG 0x00 GOTO START START: CLRF PORTB BANKSEL TRISB CLRF TRISB 0x20 CALL ANTICLOCK CLOCKWISE: MOVLW MOVWF 0x10 PORTD CALL DELAY MOVLW MOVWF 0X20 PORTD CALL DELAY MOVLW MOVWF 0X40 PORTD CALL DELAY MOVLW MOVWF 0X80 PORTD Page | 39 .ADDWF RETLW RETLW RETLW RETLW RETLW END PCL.1 BANKSEL TRISD CLRF TRISD BANKSEL PORTD CLRF PORTD BANKSEL BTFSC PORTB PORTB.0 TRISB.F 0X89 0X85 0X8A 0X86 0X00 BSF BCF TRISB.

1 ENDC ORG 0X2100 CH_TBL DE "ESTC WELCOMES U ORG 0X00 GOTO START " Page | 40 .1 $-5 CALL DELAY MOVLW MOVWF 0X40 PORTD LIST P=PIC16F877 INCLUDE "P16F877.CALL DELAY GOTO START ANTICLOCK: MOVLW MOVWF 0x80 PORTD GOTO DECFSZ GOTO RETURN END $-1 DEL1.INC" CBLOCK 0X20 TEMP COUNT DEL1 DEL2 PROGRAM FOR LCD DISPLAY CALL DELAY MOVLW MOVWF 0X20 PORTD CALL DELAY MOVLW MOVWF 0X10 PORTD CALL DELAY GOTO START DELAY: MOVLW MOVWF MOVLW MOVWF DECFSZ 0X45 DEL1 0X45 DEL2 DEL2.

F=0 5X7 MATRIX MOVWF TEMP TRISD. CLEAR MOVLW 0X28 .INBANK 0 CLRF PORTA CLEAR PORTA LATCHES CLRF PORTD CLEAR PORT D LATCHES BANKSEL ADCON1 MOVLW B'00001110' MOVWF ADCON1 .CURSOR NOT BLINKING MOVWF TEMP CALL WRITE MOVLW 0X01 CLEAR DISPLAY SCREEN MOVWF TEMP CALL WRITE MOVLW 0X06 .SHIFT IT TO RIGHT MOVWF TEMP CALL WRITE MOVLW 0X80 . .FUNCTION SET SETTIN (DL-0 4BIT DATA. ALL PINS ARE OUTPUT PINS BANKSEL PORTA .IN DISPLAY BANKSEL TEMP TRISA.N-1 2LINES. CALL WRITE MOVLW 0X0E . A0 IS . For DISPLAY ON .FORCE CURSER TO THE BEGINNING OF THE Page | 41 .INCREMENT CURSER . CLEAR . ALL PINS ARE OUTPUT PINS CLRF TRISD .START BANKSEL TRISA BANK1 CLRF TRISA .FOR ANALOG INPUT A1-A5 DIGITAL PINS BANKSEL PORTA . .INBANK 0 BANKSEL EEADR MOVLW 0X00 MOVWF EEADR .

W MOVWF PORTD CALL ENABLE CALL DELAY RETURN BANKSEL PORTA BSF PORTA.0 MOVWF PORTD CALL ENABLE MOVF TEMP.RD BANKSEL EEDATA ENABLE MOVF EEDATA.1 NOP NOP NOP NOP NOP NOP .3 READ BANKSEL EECON1 BCF EECON1.1 MOVWF TEMP CALL WRITE BANKSEL PORTA BSF PORTA.W BANKSEL TEMP MOVWF TEMP NOP BANKSEL PORTA CALL WRITE CALL DELAY BANKSEL EEADR Page | 42 GOTO READ WRITE BANKSEL PORTA SWAPF TEMP.EEPGD BSF EECON1.FIRST LINE INCF EEADR.

.1 CALL DELAY RETURN DELAY MOVLW 0XFF MOVWF DEL1 MOVLW 0XFF MOVWF DEL2 DECFSZ DEL2.F GOTO $-1 DECFSZ DEL1.BCF PORTA.4 0X08 PORTB TIMER PORTA.4 SCALE 0X20 . MOVLW MOVWF GLOW LED BLINKING PROGRAM WITH VARIABLE TIMING LIST P=PIC16F877 #INCLUDE<P16F877.4 PORTB T1CON TMR1H TMR1L 0X00 T1CON BANKSEL CLRF CLRF BSF BANKSEL CLRF CLRF CLRF .F GOTO $-5 RETURN END GOTO START CLRF CLRF START PORTA PORTB TRISB TRISB TRISA TRISA.INC> CBLOCK COUNT1 ENDC ORG 0X00 Page | 43 BCF MOVLW MOVWF CALL BTFSS CALL MOVLW 0X01 PORTA.

.4 SCALE . MOVLW MOVWF BSF BTFSS GOTO 0XFA TMR1L T1CON.TMR1ON PIR1.F T1CON.TMR1ON PIR1.INC> CBLOCK COUNT 0X20 CLRF TMR1H CLRF TMR1L .4 .31 COUNT1 END PROGRAM FOR FINDING AVERAGE LIST P = PIC16F877 #INCLUDE<P16F877.1 T1CON.4 SCALE BCF BCF DECFSZ GOTO RETURN MOVWF CALL BTFSS CALL GOTO TIMER MOVLW MOVWF PORTB TIMER PORTA.0 COUNT1.0 $-1 T1CON.1 $-8 MOVWF CALL BTFSS CALL MOVLW 0X02 PORTB TIMER PORTA.F PORTA.4 SCALE GLOW SCALE SWAPF INCF SWAPF BCF RETURN T1CON.MOVWF CALL BTFSS CALL MOVLW 0X04 PORTB TIMER PORTA. . MOVLW MOVWF 0XFE TMR1H Page | 44 .

1 SUM MOVLW 0X00 Page | 45 .68 INDF 0X23 FSR 0X04 COUNT NUMBER .1 MOVLW MOVWF .F COUNT.1 MOVLW MOVWF MOVLW MOVWF PORTB 0X00 STATUS MOVLW MOVWF MOVWF .52 INDF INCF NUMBER.1 MOVLW MOVWF INCF FSR.W ADDWF DECFSZ GOTO $-4 INCF COUNT.40 INDF AVG .12 INDF 0X23 FSR .W MOVWF INCF FSR.1 MOVF INDF.1 MOVF INDF.SUM NUMBER ENDC ORG 0X00 INCF FSR.1 SUM.73 INDF GOTO START START BANKSEL TRISB CLRF TRISB BANKSEL MOVLW MOVWF CLRF PORTB MOVLW MOVWF MOVLW MOVWF INCF FSR.1 MOVLW MOVWF INCF FSR.

0 CLRF PORTB MOVLW MOVWF MOVLW MOVWF INCF FSR.88 INDF Page | 46 .W STATUS.W MOVWF NOP GOTO $-1 END PORTB SUM.27 INDF .W SUBWF SUM.1 SUBWF BTFSC GOTO $-5 MOVF COUNT.1 INCF COUNT.1 MOVLW MOVWF .55 INDF .INC> CBLOCK MAX COUNT ENDC ORG 0X00 0X20 MOVLW MOVWF INCF FSR.1 MOVLW MOVWF INCF FSR.67 INDF PROGRAM FOR FINDING LARGEST NUMBER LIST P = PIC16F877 #INCLUDE<P16F877.1 0X22 FSR .MOVWF COUNT GOTO START START BANKSEL TRISB CLRF TRISB BANKSEL MOVLW MOVWF PORTB 0X00 STATUS MOVF NUMBER.

1 MOVLW MOVWF MOVLW MOVWF .1 MOVF INDF.W MAX 0X04 COUNT BTFSSSTATUS.87 INDF 0X22 FSR MOVWF RETURN END MAX MOVF INDF.W PORTB COUNT.W MOVWF MOVLW MOVWF INCF FSR.W MOVWF NOP GOTO $-1 CHANGE MOVF INDF.1 Page | 47 .0 CALL CHANGE DECFSZ GOTO $-6 MOVF MAX.INCF FSR.W SUBWF MAX.

Sign up to vote on this title
UsefulNot useful