[Menu]>[Circuits Gallery]>[Light controller]
Title ;******************************************************** ; ; The light control processing ; ; Divice : PIC16F873 ; Author : Seiichi Inoue ;********************************************************
LIST and INCLUDE directive list p=pic16f873 include p16f873.inc
The standard label definition of PIC16F873 is referred by the INCLUDE directive. In the standard label definition, the warning messages are displayed by the definition except bank 0. There are no influence in the operation but I corrected. As for the change of the standard label definition, refer to "Processing explanation of signboard". Or you can use ERRORLEVEL directive to suppress the Warning messages. Configuration Word
__config _hs_osc & _wdt_off & _pwrte_on & _cp_off
The item except the above is included in Configuration Word of PIC16F873. Generally, it is to be OK in above-mentioned directive. Program start ;**************** Program Start *********************** Instruction is executed from Zero addresses of the program memory when making the power ON of the PIC. When there is interruption processing, processing is begun from the addresse 4. It makes each processing jump with the GOTO instruction. Initialization process ;**************** Initial Process *********************
The initialization process is ended above. After this, the program waits for the interruption only. As the main process, it repeats the execution of the same address. '$' with operand means its address. '$+1' means an next address from its address. Interruption process ;*************** Interruption Process ***************** The interruption occurs every millisecond with CCP2. It clears the interruption flag of CCP2 first. When not executing this, the following interruption occurs without waiting desired time. The conversion of the A/D converter has started simultaneously with interruption of CCP2. So, it waits until change completion.(The GO bit of ADCON0 becomes '0') This time, because the analog channel is only 0 channel, it is not need to wait until the input taking-in (the about 20 microseconds). When A/D converting while switching more than one channel, after channel selecting, the waiting time must be provided before start the A/D conversion. If the conversion ends, it sets the higher byte of the conversion result to the duty counter of CCP1 (the PWM mode). The conversion result comes out by 10 bits but this circuit is using only a higher byte. So, the resolution is 256. When the input voltage is 0 V, the conversion result becomes 00h and the duty is 0%. In this case, the output pulse doesn't become H level. When the input voltage rises, the conversion result becomes a big value with it. The duty becomes big and the output pulse duration increases. When the input voltage becomes a maximum, the conversion result becomes FFh and the duty becomes by nearly 100%. Strictly, it doesn't become 100% because it doesn't use lower 2 bits of converted result (10bits). In case of practical use, there is no problem. In this circuit, the W and STATUS registers are not used in the main process. So, these registers are not saved when the interruption occurs. When using some registers which are used in main process and interrupt process by the sharing, those registers must be saved. Interruption ending process ;************ END of Interruption Process ************** The RETFIE instruction is executed at end of the interruption process. With this, it becomes the interruption possible condition. In this circuit, because there is no saving registers in case of interruption, there is no need to resave. Ending of coding ;******************************************************** ; END of signboard control processing ;******************************************************** end
|