PIC12C508 microcontroller lighting control system source program
The above program uses PIC12C508 microcontroller with internal 4MHZ clock, 50HZ pulse signal input on pin 4, and output ports on pins 7, 6 and 3 (GP0, GP1, GP4 ports). The fading part of it is to make the light slowly brighten (or go out). I don’t know if there are any mistakes in the microcontroller light control system program, please give more comments if there are mistakes. Thank you!
;The program is as follows.
GPI0 EQU 6
COUNT1 EQU 11
COUNT2 EQU 12
COUNT3 EQU 13
COUNT4 EQU 14
COUNT5 EQU 15
POINTER EQU 16
POINTER1 EQU 17
ORG 00H
MOVLW 07H ;Set clock parameter 1: 256 divisions
OPTION
MOVLW 2CH ;Output port setting 0, 1, 4 output, 3 input 50HZ
TRIS 6
;——————————-
START.
;Scan for port 3 Scan 0 low potential
MOVF GPI0, W
MOVWF COUNT1
BTFSC COUNT1, 3
GOTO START
NEXT: ;Scan for port 3 Scan 1 high
MOVF GPI0, W
MOVWF COUNT1
BTFSS COUNT1, 3
GOTO NEXT
INCF COUNT2
MOVLW 100
DECFSZ COUNT2, 1
GOTO START ;—— external 50HZ signal, scan 100 times, delay 2 seconds
;——————- single-chip lighting control system —————————————-
JB.
CLRF TMR0
MOVLW 250
MOVWF COUNT4
MOVWF COUNT5
INCF POINTER, F
MOVF POINTER, 0
MOVWF POINTER1
MOVLW TABLE
ADDWF POINTER, 0
CALL AA
MOVWF 6 ;return, output —– light
CHANGE.
MOVF TMR0, 0
MOVWF COUNT3
SUBWF COUNT4, 1
BTFSS STATUS, Z ;TMR0=250? ‘N’ empty cycle TMR0 times ‘Y’ jump out to restart fade
GOTO NOPDELAY1
GOTO OUT
NOPDELAY1.
NOP
DECFSZ COUNT3, 1
GOTO NOPDELAY1
DECF POINTER1, F ; 《—Single-chip light control system ——-|
MOVLW TABLE ; |
ADDWF POINTER1,0 ; |
CALL AA ; |
MOVWF 6 ; return last display data, output to GP port — extinguish 《–|
NOPDELAY2.
NOP
DECFSZ COUNT4, 1
GOTO NOPDELAY2
GOTO CHANGE
;—– gradual —– change ———— monolithic lighting control system ———————————–
OUT.
MOVLW 9 ;Take the table 9 times
SUBWF POINTER,0
BTFSS STATUS,Z
GOTO JB
GOTO START
AA: MOVWF 2
TABLE:RETLW 2CH
RETLW 3CH
RETLW 2DH
RETLW 2EH
RETLW 2FH
RETLW 3DH
RETLW 3EH
RETLW 2CH
RETLW 3FH
ORG 1FFH
MOVWF OSCCAL
END
Related posts:
- Making flameless electronic candles with simple electronics and LEDs
- How will the LED full color large screen develop? Detailed description of the development trend and composition profile
- itc HD LED display gives the scene event space a wonderful visual experience
- Graphene to be used as OLED water-oxygen barrier layer