TA的每日心情 | 开心 2014-8-28 01:37 |
---|
签到天数: 13 天 [LV.3]偶尔看看II
|
楼主 |
发表于 2007-5-16 00:39
|
显示全部楼层
呵呵,程序终于完成了
<p><font size="5">程序功能:</font></p><p><font size="5"> 高亮-50%-10%-暴闪,采用软件PWM模式调节亮度,单片机GPIO0端子作为控制输出端子。</font></p><p><font size="5">切换方式:</font></p><p><font size="5"> 每次打开电源后,如果2秒内关闭,则下次再开电源将改变模式;如果持续时间高于2秒,则下次打开电源按照上次模式点亮。持续2秒后会有个低频闪烁作为模式记忆提示。</font></p><p>#include "P12F629.INC"</p><p>EEADDRA EQU 20H ;定义EEPROM A地址<br />EEADDRB EQU 21H ;定义EEPROM B地址<br />TEMP EQU 22H ;定义临时变量<br />EEREADA EQU 23H ;定义EEPROM A预写<br />EEREADB EQU 24H ;定义EEPROM B预写<br />DELY1 EQU 25H ;定义延时变量1<br />DELY2 EQU 26H ;定义延时变量2<br />DELY3 EQU 27H ;定义延时变量3<br />TEMP1 EQU 28H ;定义临时变量1<br />AA EQU 29H ;定义PWM低电平时间常数<br />BB EQU 2AH ;定义PWM低电平时间常数<br />COUNT0 EQU 2BH ;定义定时器延时常数</p><p> ORG 00H ;复位向量地址<br /> GOTO STAR ;转向主程序</p><p> ORG 04H ;中断向量地址<br /> GOTO T0INT</p><p> ORG 06H ;主程序起始地址<br />STAR<br /> BCF STATUS,RP0 ;体选择BANK0<br /> MOVLW 01H<br /> MOVWF EEADDRA ;初始化EEPROM A地址<br /> MOVLW 02H<br /> MOVWF EEADDRB ;初始化EEPROM B地址<br /> MOVLW 1EH<br /> MOVWF COUNT0 ;初始化定时器延时常数</p><p> CLRF GPIO ;清GPIO寄存器<br /> CLRF TMR0 ;清Timer0</p><p> MOVLW 07H<br /> MOVWF CMCON ;关闭比较器19H</p><p> BSF STATUS,RP0 ;体选择BANK1<br /> <br /> MOVLW 87H<br /> MOVWF OPTION_REG ;禁止上拉,预分频系数256<br /> MOVLW 20H<br /> MOVWF INTCON ;关全局中断,允许Timer0中断,中断标志清零</p><p> ;CLRF ANSEL ;清9FH模拟选择寄存器</p><p> MOVLW 08H<br /> MOVWF TRISIO ;除GPIO3外,其他管脚都是输出</p><p> BCF STATUS,RP0<br /> CALL DELAY1 ;延时<br /> ;CALL DELAY1</p><p> CALL EEREAD_A ;读取EEPROM A数据<br /> CALL EEREAD_B ;读取EEPROM B数据</p><p> MOVF EEREADB,W<br /> XORLW 01H ;EEPROM A数据跟01比较<br /> BTFSS STATUS,Z<br /> GOTO A4 ;不相等,跳转A3执行<br /> GOTO A_A ;相等,跳转A_A执行<br /> <br />A4 ;判断EEPROM A数据是否超过4<br /> BCF STATUS,RP0<br /> INCF EEREADA<br /> MOVF EEREADA,W<br /> XORLW 05H<br /> BTFSS STATUS,Z<br /> GOTO WRA<br /> <br />A_1 ;EEPROM A数据超过3,则令其为1<br /> MOVLW 01H<br /> MOVWF EEREADA</p><p>WRA<br /> MOVF EEREADA,W<br /> MOVWF TEMP<br /> CALL WREEA</p><p> BSF STATUS,RP0<br /> BSF INTCON,GIE ;开全局中断<br /> <br />A_A<br /> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> XORLW 01H<br /> BTFSS STATUS,Z<br /> GOTO AA2</p><p> BCF STATUS,RP0<br /> MOVLW 00H<br /> MOVWF TEMP<br /> CALL WREEB ;EEPROM B写入0</p><p> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> MOVWF TEMP<br /> CALL WREEA ;重写EEPROM A</p><p>FINISH BCF STATUS,RP0<br /> BSF GPIO,00H ;GP0输出高电平,对应全亮</p><p><br /> NOP<br /> GOTO FINISH</p><p>T0INT ;Timer0中断程序<br /> BSF STATUS,RP0<br /> BCF INTCON,T0IF ;清Timer0中断标志</p><p> BCF STATUS,RP0<br /> DECFSZ COUNT0,F<br /> RETFIE ;中断返回<br /> BSF STATUS,RP0<br /> BCF INTCON,GIE ;关闭全局中断<br /> BCF INTCON,T0IE ;关闭Timer0中断</p><p> BCF STATUS,RP0<br /> MOVLW 01H<br /> MOVWF TEMP<br /> CALL WREEB ;EEPROM B写入1</p><p>LIGHTA BCF STATUS,RP0 ;闪烁<br /> CLRF GPIO<br /> CALL DELAY1<br /> CALL DELAY1<br /> CALL DELAY1<br /> COMF GPIO<br /> CALL DELAY1<br /> CALL DELAY1<br /> CALL DELAY1<br /> BCF STATUS,RP0<br /> RETFIE ;中断返回</p><p>AA2<br /> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> XORLW 02H<br /> BTFSS STATUS,Z<br /> GOTO AA3</p><p> BCF STATUS,RP0<br /> MOVLW 00H<br /> MOVWF TEMP<br /> CALL WREEB ;EEPROM B写入0</p><p> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> MOVWF TEMP<br /> CALL WREEA ;重写EEPROM A</p><p> BCF STATUS,RP0<br /> MOVLW 01FH<br /> MOVWF AA<br /> MOVWF BB ;50%占空比<br />LIGHT1 BCF STATUS,RP0<br /> CLRF GPIO<br /> CALL DEYA<br /> COMF GPIO<br /> CALL DEYB<br /> GOTO LIGHT1</p><p>AA3<br /> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> XORLW 03H<br /> BTFSS STATUS,Z<br /> GOTO AA4<br /> BCF STATUS,RP0<br /> MOVLW 00H<br /> MOVWF TEMP<br /> CALL WREEB ;EEPROM B写入0</p><p> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> MOVWF TEMP<br /> CALL WREEA ;重写EEPROM A</p><p> BCF STATUS,RP0<br /> MOVLW 05H<br /> MOVWF AA<br /> MOVLW 2DH<br /> MOVWF BB ;10%占空比<br />LIGHT2 BCF STATUS,RP0<br /> CLRF GPIO<br /> CALL DEYA<br /> COMF GPIO<br /> CALL DEYB<br /> GOTO LIGHT2</p><p>AA4<br /> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> XORLW 04H<br /> BTFSS STATUS,Z<br /> GOTO AA1<br /> BCF STATUS,RP0<br /> MOVLW 00H<br /> MOVWF TEMP<br /> CALL WREEB ;EEPROM B写入0</p><p> BCF STATUS,RP0<br /> MOVF EEREADA,W<br /> MOVWF TEMP<br /> CALL WREEA ;重写EEPROM A</p><p>LIGHT3 BCF STATUS,RP0 ;闪烁<br /> CLRF GPIO<br /> CALL DELAY1<br /> COMF GPIO<br /> CALL DELAY1<br /> GOTO LIGHT3</p><p>AA1<br /> MOVLW 01H<br /> MOVWF EEREADA<br /> GOTO WRA<br /> <br />EEREAD_A ;读取EEPROM A<br /> BCF STATUS,RP0<br /> MOVF EEADDRA,W<br /> BSF STATUS,RP0<br /> MOVWF EEADR<br /> BSF EECON1,RD<br /> NOP<br /> MOVF EEDATA,W<br /> BCF STATUS,RP0<br /> MOVWF EEREADA<br /> RETURN</p><p>EEREAD_B ;读取EEPROM B<br /> BCF STATUS,RP0<br /> MOVF EEADDRB,W<br /> BSF STATUS,RP0<br /> MOVWF EEADR<br /> BSF EECON1,RD<br /> NOP<br /> MOVF EEDATA,W<br /> BCF STATUS,RP0<br /> MOVWF EEREADB<br /> RETURN<br /> <br />WREEA ;写EEPROM A,TEMP传送写入数据<br /> BCF STATUS,RP0 ;取BANK0<br /> MOVF EEADDRA,W ;取A地址<br /> BSF STATUS,RP0 ;取BANK1<br /> MOVWF EEADR ;A地址进入EEADR<br /> BCF STATUS,RP0 ;取BANK0<br /> MOVF TEMP,W ;取写入数据<br /> BSF STATUS,RP0 ;取BANK1<br /> MOVWF EEDATA ;待写数据进入EEDATA<br /> BSF EECON1,WREN<br /> BCF INTCON,GIE<br /> MOVLW 55H<br /> MOVWF EECON2<br /> MOVLW 0AAH<br /> MOVWF EECON2<br /> BSF EECON1,WR<br /> BSF STATUS,RP0<br /> BSF INTCON,GIE<br /> RETURN</p><p>WREEB ;写EEPROM B,TEMP传送写入数据<br /> BCF STATUS,RP0 ;取BANK0<br /> MOVF EEADDRB,W ;取B地址<br /> BSF STATUS,RP0 ;取BANK1<br /> MOVWF EEADR ;B地址进入EEADR<br /> BCF STATUS,RP0 ;取BANK0<br /> MOVF TEMP,W ;取写入数据<br /> BSF STATUS,RP0 ;取BANK1<br /> MOVWF EEDATA ;待写数据进入EEDATA<br /> BSF EECON1,WREN<br /> BCF INTCON,GIE<br /> MOVLW 55H<br /> MOVWF EECON2<br /> MOVLW 0AAH<br /> MOVWF EECON2<br /> BSF EECON1,WR<br /> BSF STATUS,RP0<br /> BSF INTCON,GIE<br /> RETURN</p><p>DELAY1 MOVLW 4FH ;外循环常数<br /> MOVWF DELY1 ;外循环寄存器<br />LOOP0 MOVLW 0FFH ;中循环常数<br /> MOVWF DELY2 ;中循环寄存器<br />LOOP1 DECFSZ DELY2 ;中循环寄存器递减<br /> GOTO LOOP1 ;继续中循环<br /> DECFSZ DELY1 ;外循环寄存器递减<br /> GOTO LOOP0 ;继续外循环<br /> RETURN</p><p>DEYA MOVF AA,W<br /> MOVWF TEMP<br />D1 DECFSZ TEMP<br /> GOTO D1<br /> RETURN</p><p>DEYB MOVF BB,W<br /> MOVWF TEMP<br />D2 DECFSZ TEMP<br /> GOTO D2<br /> RETURN</p><p>END</p> |
|