;MPU PIC16F887 ;51FLY 大约于2001年11月 ;下面的程序实现如下功能 ;1. PWM调制驱动电机 ;2. 三路A/D 循环采集并显示 ;3. D口并行输出驱动发光二极管 ;4. 记数555振荡器脉冲若干次后使得继电器吸合 list p=16f877 include "p16f877.inc" RE0 EQU 0 RE1 EQU 1 RE2 EQU 2 P_DIN_7219 EQU RE0 P_CLK_7219 EQU RE1 P_CS_7219 EQU RE2 TMR10N EQU 0 TMR1IF EQU 0 RC1 EQU 1 TMR2ON EQU 2 REG EQU 20H REG0 EQU 21H YY EQU 22H ZZ EQU 23H PUSH EQU 24H HL EQU 25H B3 EQU 30H B2 EQU 31H B1 EQU 32H ORG 0x0000 nop Start ;==================PORTD============================= MOVLW 0FFH MOVWF PORTD BSF STATUS,RP0 BCF STATUS,RP1 MOVLW 00H MOVWF TRISD BCF STATUS,RP0 ;D口设置为输出口 BCF STATUS,RP1 ;===================PORTC============================ MOVLW 0FFH MOVWF PORTC BSF STATUS,RP0 BCF STATUS,RP1 MOVLW B'11111001' MOVWF TRISC MOVLW 1AH MOVWF PR2 BCF STATUS,RP0 BCF STATUS,RP1 ;====================A/D============================== ;movlw B'01001001' ;--r ;movlw B'01000001' ;--pt100 ;channel of a/d chose ;movlw B'01010001' ;--ad590 ;===================================================== banksel OPTION_REG movlw B'10000111' ;TMR0 prescaler, 1:256 movwf OPTION_REG movlw B'00001110' ;Left justify,1 analog channel movwf ADCON1 ;VDD and VSS reference ;====================7219 ============================ BCF STATUS,RP1 BSF STATUS,RP0 MOVLW 06H MOVWF ADCON1 BCF STATUS,RP0 MOVLW 0FFH MOVWF PORTE BSF STATUS,RP0 BCF STATUS,RP1 MOVLW 00H MOVWF TRISE ;E口设置为输出口 BCF STATUS,RP0 BCF STATUS,RP1 ;====================DISPLY '------------'=============== MOVLW 08H MOVWF REG0 MOVLW 30H MOVWF FSR ;初始状态,显示单元置为"------" LOOP1 MOVLW 0AH MOVWF INDF INCF FSR,1 DECFSZ REG0,1 GOTO LOOP1 ;====================================================== CALL DISP CALL DELLY CALL PWM MAIN movlw B'01001001' ;--r CALL AD MOVFW ADRESH MOVWF HL CALL BCD MOVLW 01H MOVWF 37H MOVLW 0AH ;显示为"XXX---1" MOVWF 36H MOVWF 35H MOVWF 34H CALL DISP CALL COUNT movlw B'01010001' ;--ad590 CALL AD MOVFW ADRESH MOVWF HL CALL BCD MOVLW 0AH MOVWF 34H ;显示为"XXX---590" MOVLW 5H MOVWF 35H MOVLW 9H MOVWF 36H MOVLW 0H MOVWF 37H CALL DISP CALL COUNT movlw B'01000001' ;--pt100 CALL AD MOVFW ADRESH MOVWF HL CALL BCD MOVLW 0EH MOVWF 34H MOVLW 1H MOVWF 35H MOVLW 0H ;显示为"XXX---P100" MOVWF 36H MOVLW 0H MOVWF 37H CALL DISP CALL COUNT CALL LOOP GOTO MAIN ;=========================================================== PWM MOVLW 00H MOVWF TMR2 MOVLW B'00001100' MOVWF CCP1CON ;启动定时 MOVLW 0CH MOVWF CCPR1L BSF T2CON,TMR2ON RETLW 0 COUNT MOVLW 0F0H MOVWF TMR1L ;1000 TIME MOVLW 0D8H ;(65536-1000)=D8F0H MOVWF TMR1H BCF PIR1,TMR1IF MOVLW B'00000011' MOVWF T1CON TEST BTFSS PIR1,TMR1IF GOTO TEST ;等待记数满溢出 BCF T1CON,TMR1ON BSF PORTC,RC1 ;继电器吸合 CALL DELLY BCF PORTC,RC1 ;继电器释放 CALL DELLY RETLW 0 LOOP MOVLW 00H MOVWF PORTD CALL DELLY MOVLW 0FFH MOVWF PORTD CALL DELLY RETLW 0 DELLY MOVLW 0FFH MOVWF 21H P_DE2 MOVLW 0FFH MOVWF 20H P_DE1 DECFSZ 20H,F GOTO P_DE1 DECFSZ 21H,F GOTO P_DE2 NOP RETLW 0 ;============ HL--------B3B2B1 =========================================== BCD CLRF B3 CLRF B2 CLRF B1 ;十六进制数存HL单元 ;等待转换完毕后存于B3,B2,B1单元 MOVLW H'C8' SUBWF HL,0 BTFSC STATUS,C ;>200 ? GOTO BCD_1 MOVLW H'64' SUBWF HL,0 BTFSC STATUS,C ;>100 ? GOTO BCD_2 BCD_3 MOVLW H'0A' SUBWF HL,0 ;>10 ? BTFSC STATUS,C GOTO BCD_4 MOVF HL,0 ;<10 ? MOVWF B1 RETLW 0 BCD_1 MOVWF HL MOVLW 2 MOVWF B3 GOTO BCD_3 BCD_2 MOVWF HL MOVLW 1 MOVWF B2 GOTO BCD_3 BCD_4 MOVWF HL INCF B2 GOTO BCD_3 ;================================================================== AD movwf ADCON0 btfss INTCON,T0IF ;Wait for Timer0 to timeout goto AD bcf INTCON,T0IF bsf ADCON0,GO ;Start A/D conversion Wait btfss PIR1,ADIF ;Wait for conversion to complete goto Wait movf ADRESH,W ;Write A/D result to ADRESH RETLW 0 ;============================================================== DISP BCF PORTE,RE2 ;P_CS_7219 MOVLW H'0C' CALL SEND MOVLW H'01' CALL SEND BSF PORTE,RE2 ;off shut down mode NOP NOP BCF PORTE,RE2 MOVLW H'0A' CALL SEND MOVLW H'0F' CALL SEND ;set intensity BSF PORTE,RE2 NOP NOP BCF PORTE, RE2 MOVLW H'0B' CALL SEND MOVLW H'07' CALL SEND ;set scan limit BSF PORTE,RE2 NOP NOP BCF PORTE,RE2 MOVLW H'09' CALL SEND MOVLW H'0FF' CALL SEND ;set decode mode BSF PORTE,RE2 NOP NOP BCF PORTE,RE2 MOVLW H'0F' CALL SEND MOVLW H'00' CALL SEND BSF PORTE,RE2 ;off test mode MOVLW 8H MOVWF YY MOVLW H'01' MOVWF ZZ MOVLW 0X30 MOVWF FSR DISPLP BCF PORTE,RE2 MOVF ZZ,0 ;ZZ---W CALL SEND MOVF INDF,0 CALL SEND BSF PORTE,RE2 NOP NOP INCF ZZ ,1 INCF FSR ,1 ;NEXT ONE DECFSZ YY ,1 GOTO DISPLP RETLW 0 SEND MOVWF PUSH MOVLW 0X8 MOVWF REG MOVF PUSH,0 SDLOOP BCF PORTE,RE1 ;clock MOVWF F RLF F,0 BTFSC STATUS,C ;C=0,NEXT ONE GOTO SDHI BCF PORTE,RE0 ;logic low GOTO ONEBIT SDHI BSF PORTE,RE0 ONEBIT BSF PORTE,RE1 NOP NOP DECFSZ REG,1 GOTO SDLOOP ;send eight bits RETLW 0 END
文章评论(0条评论)
登录后参与讨论