[Menu]>[Circuits Gallery]>[Light controller]
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 | ;******************************************************** ; ; The light control processing ; ; Device : PIC16F873 ; Author : Seiichi Inoue ;******************************************************** list p=pic16f873 include p16f873.inc __config _hs_osc & _wdt_off & _pwrte_on & _cp_off ;**************** Program Start *********************** org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto int ;**************** Initial Process ********************* init ;*** Port initialization bsf status,rp0 ;Change to Bank1 movlw b'00000001' ;AN0 to input mode movwf trisa ;Set TRISA register clrf trisc ;Set TRISC to output mode bcf status,rp0 ;Change to Bank0 ;*** A/D converter initialization movlw b'10000001' ;ADCS=10 CHS=AN0 ADON=ON movwf adcon0 ;Set ADCON0 register bsf status,rp0 ;Change to Bank1 movlw b'00001110' ;ADFM=0 PCFG=1110 movwf adcon1 ;Set ADCON1 register bcf status,rp0 ;Change to Bank0 ;*** PWM initialization clrf tmr2 ;Clear TMR2 register clrf ccpr1l ;Clear CCPR1L register bsf status,rp0 ;Change to Bank1 movlw d'255' ;Period=1638.4usec(610Hz) movwf pr2 ;Set PR2 register bcf status,rp0 ;Change to Bank0 movlw b'00000110' ;Pst=1:1 TMR2=ON Pre=1:16 movwf t2con ;Set T2CON register movlw b'00001100' ;CCP1XY=0 CCP1M=1100(PWM) movwf ccp1con ;Set CCP1CON register ;*** Compare mode initialization clrf tmr1h ;Clear TMR1H register clrf tmr1l ;Clear TMR1L register movlw h'09' ;H'9C4'=2500 movwf ccpr2h ;Set CCPR2H register movlw h'c4' ;2500*0.4usec = 1msec movwf ccpr2l ;Set CCPR2L register movlw b'00000001' ;Pre=1:1 TMR1=Int TMR1=ON movwf t1con ;Set T1CON register movlw b'00001011' ;CCP2M=1011(Compare) movwf ccp2con ;Set CCP2CON register ;*** Interruption control bsf status,rp0 ;Change to Bank1 movlw b'00000001' ;CCP2IE=Enable movwf pie2 ;Set PIE2 register bcf status,rp0 ;Change to Bank0 movlw b'11000000' ;GIE=ON PEIE=ON movwf intcon ;Set INTCON register wait goto $ ;Interruption wait ;*************** Interruption Process ***************** int clrf pir2 ;Clear interruption flag ad_check btfsc adcon0,go ;A/D convert end ? goto ad_check ;No. Again movf adresh,w ;Read ADRESH register movwf ccpr1l ;Set Duty cycle of PWM ;************ END of Interruption Process ************** retfie ;******************************************************** ; END of light control processing ;******************************************************** end |
MPASM 02.50.02 Intermediate LIGHT2.ASM 11-11-2000 21:52:47 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;******************************************************** 00002 ; 00003 ; The light control processing 00004 ; 00005 ; Device : PIC16F873 00006 ; Author : Seiichi Inoue 00007 ;******************************************************** 00008 00009 LIST P=PIC16F873 00010 INCLUDE P16F873.INC 00001 LIST 00002 ; P16F873.INC Standard Header File, Version 1.00 00358 LIST 2007 3FF2 00011 __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF 00012 00013 ;**************** Program Start *********************** 0000 00014 ORG 0 ;Reset Vector 0000 2805 00015 GOTO INIT 0004 00016 ORG 4 ;Interrupt Vector 0004 282B 00017 GOTO INT 00018 00019 ;**************** Initial Process ********************* 0005 00020 INIT 00021 00022 ;*** Port initialization 0005 1683 00023 BSF STATUS,RP0 ;Change to Bank1 0006 3001 00024 MOVLW B'00000001' ;AN0 to input mode 0007 0085 00025 MOVWF TRISA ;Set TRISA register 0008 0187 00026 CLRF TRISC ;Set TRISC to output mode 0009 1283 00027 BCF STATUS,RP0 ;Change to Bank0 00028 00029 ;*** A/D converter initialization 000A 3081 00030 MOVLW B'10000001' ;ADCS=10 CHS=AN0 ADON=ON 000B 009F 00031 MOVWF ADCON0 ;Set ADCON0 register 000C 1683 00032 BSF STATUS,RP0 ;Change to Bank1 000D 300E 00033 MOVLW B'00001110' ;ADFM=0 PCFG=1110 000E 009F 00034 MOVWF ADCON1 ;Set ADCON1 register 000F 1283 00035 BCF STATUS,RP0 ;Change to Bank0 00036 00037 ;*** PWM initialization 0010 0191 00038 CLRF TMR2 ;Clear TMR2 register 0011 0195 00039 CLRF CCPR1L ;Clear CCPR1L register 0012 1683 00040 BSF STATUS,RP0 ;Change to Bank1 0013 30FF 00041 MOVLW D'255' ;Period=1.64msec(610Hz) 0014 0092 00042 MOVWF PR2 ;Set PR2 register 0015 1283 00043 BCF STATUS,RP0 ;Change to Bank0 0016 3006 00044 MOVLW B'00000110' ;Pst=1:1 TMR2=ON Pre=1:16 0017 0092 00045 MOVWF T2CON ;Set T2CON register 0018 300C 00046 MOVLW B'00001100' ;CCP1XY=0 CCP1M=1100(PWM) 0019 0097 00047 MOVWF CCP1CON ;Set CCP1CON register 00048 00049 ;*** Compare mode initialization 001A 018F 00050 CLRF TMR1H ;Clear TMR1H register MPASM 02.50.02 Intermediate LIGHT2.ASM 11-11-2000 21:52:47 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 001B 018E 00051 CLRF TMR1L ;Clear TMR1L register 001C 3009 00052 MOVLW H'09' ;H'9C4'=2500 001D 009C 00053 MOVWF CCPR2H ;Set CCPR2H register 001E 30C4 00054 MOVLW H'c4' ;2500*0.4usec = 1msec 001F 009B 00055 MOVWF CCPR2L ;Set CCPR2L register 0020 3001 00056 MOVLW B'00000001' ;Pre=1:1 TMR1=Int TMR1=ON 0021 0090 00057 MOVWF T1CON ;Set T1CON register 0022 300B 00058 MOVLW B'00001011' ;CCP2M=1011(Compare) 0023 009D 00059 MOVWF CCP2CON ;Set CCP2CON register 00060 00061 ;*** Interruption control 0024 1683 00062 BSF STATUS,RP0 ;Change to Bank1 0025 3001 00063 MOVLW B'00000001' ;CCP2IE=Enable 0026 008D 00064 MOVWF PIE2 ;Set PIE2 register 0027 1283 00065 BCF STATUS,RP0 ;Change to Bank0 0028 30C0 00066 MOVLW B'11000000' ;GIE=ON PEIE=ON 0029 008B 00067 MOVWF INTCON ;Set INTCON register 00068 002A 00069 WAIT 002A 282A 00070 GOTO $ ;Interruption wait 00071 00072 ;*************** Interruption Process ***************** 002B 00073 INT 002B 018D 00074 CLRF PIR2 ;Clear interruption flag 002C 00075 AD_CHECK 002C 191F 00076 BTFSC ADCON0,GO ;A/D convert end ? 002D 282C 00077 GOTO AD_CHECK ;No. Again 002E 081E 00078 MOVF ADRESH,W ;Read ADRESH register 002F 0095 00079 MOVWF CCPR1L ;Set Duty cycle of PWM 00080 00081 ;************ END of Interruption Process ************** 0030 0009 00082 RETFIE 00083 00084 ;******************************************************** 00085 ; END of light control processing 00086 ;******************************************************** 00087 00088 END MPASM 02.50.02 Intermediate LIGHT2.ASM 11-11-2000 21:52:47 PAGE 3 The label list has been deleted. MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X--------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 46 Program Memory Words Free: 4050 Errors : 0 Warnings : 0 reported, 0 suppressed Messages : 0 reported, 0 suppressed |
light2_source.zip light2_hex.zip |