Job Recruitment Website - Job seeking and recruitment - PIC MCU programming problem just learned.
PIC MCU programming problem just learned.
; ? *********************************************************************
; ? * ? GPIO0-V? GPIO 1-I? GPIO2-LED 1? GPIO4-LED2? GPIO5-OUT? *
; ? * ? GPIO3- 10K *
; ? *********************************************************************
? List? P= 12F675
? Including? “P 12F675。 INC”? ; ? Contains MPLAB predefined header files.
? _ _ CONFIG(0x3fc 4); ? 1 1? - 1? 1 100? 1000? Set configuration word information
? ; ? _CPD_OFF? & amp? _CP_OFF? & amp? _ Borden _ Weng? & amp? _MCLRE_OFF?
? ; ? Off-code data protection, power-off reset enable, internal reset,
? ; ? _PWRTE_ON? & amp? _ WDT _ off? & amp? _INTRC_OSC_NOCLKOUT
? ; ? Power-on reset delay enabled, watchdog off, internal oscillation without clock output.
; ? *************************************************
; ? *? Register definition and RAM allocation *
; ? *************************************************
? Error level? -302 ; ? Do not display messages in the compiled output.
? cblock? 0x20? The definition of universal variables starts from this address.
? W _ TEMP? Is the interrupt service program used to temporarily save W and state?
? State _ temperature
? Flag? ; ? Status flag register to be used by the program
? PWM _ HIGH:2; ? New PWM high time, two bytes reserved.
? PWM_LOW:2? ; ? New PWM low time, two bytes reserved.
? PWM _ HIGH _ CURRENT:2; ? High level time latch of current PWM
? PWM _ LOW _ current: 2? ; ? Current PWM low level time latch
? Counter; ? Advertising sampling count
? adsum:2; ? 16 AD accumulation result, used for average operation, two bytes.
? Temperature: 2; ? Temporary variable for mathematical operation, two bytes.
? endc? ; ? End cblock variable definition
? Count EQU 38H
? The result? EQU 39H
; ************************************************
; I/O pin initialization? *
; And then what? A/D? Initialize *
; ************************************************
; GP0? =? Analog voltage input
; GP 1? =? Unused
; GP2? =? Unused
; GP3? =? It can only be used as an input to ground the 10K pull-down resistor, and this pin will be used for ICSP recording.
; GP4? =? PWM 1? Output pin
; GP5? =? PWM2? Output pin
? ; ? /? ***? ***? ***? ***? ***? /Replace definition
# Definition? PWM _ output? GPIO,2? ; ? GPIO,4
# Definition? LOAD_PWM flag, 0
# Definition? CALCULATE_AD flag, 1
# Definition? PWM_TICKS? . 1024 ; ? The number of PWM time slices, if the resolution of PWM is 10 bits,
# Definition? TEST_PWM_HIGH? .5 12 ; ? 50% duty cycle is used for testing, and the high level time is equal to half of PWM time slice.
# Definition? TEST _ PWM _ LOW PWM _ TICKS-TEST _ PWM _ HIGH? ; ? The low level time is equal to the low level time of PWM time slice.
# Definition? ISR_DELAY? . 16 ? ; ? The delay from the overflow of the timer 1 to the value of the interrupt overload timer 1,
; ? This value can be determined by software simulation.
# Definition? Quantity _ Advertisement _ Sample? . 16 ? ; ? Advertising sampling time
# Definition? AD _ TIME _ interval? . 10 ; ? 0xFF? -? (245) ad time interval, 10 period.
? ; ? /? ***? ***? ***? ***? ***? /Defines a macro that subtracts a variable from a two-byte constant.
? ; ? const_input? -? Input? =? output
sub_const_ 16? Macro? Const_input, input,? output
? Movlw low? Constant _ input; ? W? =? Low? Double-byte constant l
? Movwf temperature
? Is movlw tall? const_input? ; ? W? =? Tall? Double byte constant? H
? Movwf temperature+1
? Movf input, w; ? W? =? invest
? Subbass temperature, w; ? W? =? Temporary workers? -? W?
? Movwf output; ? Output? =? W
? Movf input+1, w? ; ? W? =? Enter+1
? Btfss status, c? ; ? c? =? 1? -& gt;
? Incf input+1, w? ; ? W? =? Enter+1? +? 1
? Subwoofer temperature+1, w? ; ? W? =? temp+ 1? -? W?
? Movwf output+1? ; ? Output+1? =? W
? endm
? ; ? /? ***? ***? ***? ***? ***? /Macro that defines double-byte constant plus variable
? ; ? const_input? +? Input? =? output
add_const_ 16? Macro? Const_input, input,? output
? Movlw low? Constant _ input; ? W? =? Low? Double-byte constant l
? Movwf temperature
? Is movlw tall? const_input? ; ? W? =? Tall? Double byte constant? H
? Movwf temperature+1
? Movf input, w; ? W? =? invest
? Addwf temperature, w; ? W? =? Temporary workers? +? W?
? Movwf output; ? Output? =? W
? Movf input+1, w? ; ? W? =? Enter+1
? Btfsc status, c? ; ? c? =? 0? -& gt;
? Incf input+1, w? ; ? W? =? Enter+1? +? 1
? addwf temp+ 1,w? ; ? W? =? temp+ 1? +? W?
? Movwf output+1? ; ? Output+1? =? W
? endm
? ; ? /? ***? ***? ***? ***? ***? /program start
? ; ? /? ***? ***? ***? ***? ***? /
? org? 0000H? ; ? Chip reset entry address 0x00
? Go to MAIN000? main program
? ; ? /? ***? ***? ***? ***? ***? /interrupt service subroutine
? ; ? /? ***? ***? ***? ***? ***? /
? ; ? INTCON,T0IF - TMR0? Overflow intcon, intf-GP2/int external interrupt
? ; ? INTCON,GPIF - GP5-GP0? Pin level has changed.
? ; ? PIR 1,EEIF - EEPROM? Write operation completed? PIR 1, ADIF-modulus? Conversion complete
? ; ? Pir 1, CMIF- comparator input has been changed. PIR 1,TMR 1IF-TMR 1? spill over
? org? 0004h? ; ? Interrupt entry address 0x0004
INTCON00? movwf W _ TEMP? W_TEMP? =? W? protect
? Swapf status, w? ; ? Status _ Temperature? =? condition
? Movwf state _ temperature
? bcf? Status, RP0;; ? Choose a bank? 0
INTCON02? movlw b ' 00000 100 '; ? Put the fourth place of w high, and everything else is zero.
? xorwf GPIO,F; ? And GPIO xor, that is, invert the level of the PWM output pin.
; ? Judging the interrupt type
INTCON03? bcf? PIR 1,TMR 1IF; ? Qing? T 1? Interrupt sign? Timer 1? pause
? Is movlw tall? 3CAFH? Timer 1? =? 50? mS? C350H
? movwf TMR 1H? ; ? FFFFH? -? C350H? =? 3CAFH
? Movlw low? 3CAFH
? movwf TMR 1L
? bsf? Calculation _AD? ; ? Settings? A/D? Conversion mark
? bsf? LOAD_PWM? ; ? Settings? PWM? symbol
INTCON08? Swapf status _ temperature, w? ; ? Recovery status register
? Movwf state
? swapf W_TEMP,F? ; ? Restore w register
? Swapf temperature, w
? retfie? Return from interrupt
? ; ? /? ***? ***? ***? ***? ***? /main program
? ; ? /? ***? ***? ***? ***? ***? /
MAIN000 clrf GPIO? ; ? Initialize the GPIO port register to zero.
? bsf? Status,? RP0; ? Choose a bank? 1
? Call 0x3FF? ; ? Read the factory calibration word of internal oscillation, and the return value is in the W register.
? movwf OSCCAL? Internal oscillator calibration
? movlw b ' 1 10000 1 1 '; ? Setting assembly
? movwf TRISIO?
? movlw 0 1h; ? Enable timer 1 interrupt? 0 1h
? movwf PIE 1
? movlw b ' 000 1000 1 '; ? AD adopts FOSC/8? Clock, GP2 is an analog port,
? Muff Ansel? ; ? The other ports are digital IO.
? movlw b ' 0000 1000 '; ? Timer 0 is set to use the internal instruction cycle without prescaling.
? Movwf option _ register
? bcf? Status,? RP0; ? Select Bank0.
? movlw b ' 100000 1 '; ? A/D is right-aligned, based on Vdd, and GP0 is the AD input port.
? movwf ADCON0
? movlw b ' 00000 1 1 1 '; ? Turn off the internal comparator so that the inputs of the comparator are all digital ports.
? movwf CMCON
? movlw 0C0h? ; ? Enable peripheral interrupts and global interrupts.
? movwf INTCON
? movlw b ' 000000 1 '; ? Timer 1 is 1: 1 prescaler, internal clock source,
? movwf T 1CON? ; ? Oscillation frequency /4, without gate control
? movlw . 16; ? AD? Number of times? =? 10
? Movwf counter
MAIN0 10 btfss CALCULATE_AD? ; ? =? 1? -& gt; ? systemic circulation
? Go to MAIN0 10.
? bcf? Calculation _AD? ; ? Qing? A/D? Conversion mark
? bsf? Status, RP0;; ? Select bank 1.
? movf ADRESL,W? ; ? W? =? AD? L
? addwf adsum,F; ? adsum? =? AD? L
? Btfsc status, c? ; ? c? =? 0? -& gt;
? incf adsum+ 1,F? ; ? adsum+ 1? =? adsum+ 1? +? 1
? bcf? Status, RP0;; ? Select Bank0.
? movf ADRESH,W? ; ? W? =? AD? H
? addwf adsum+ 1,F? ; ? adsum+ 1? =? AD? H
? bsf? ADCON0,GO _ DONE? Start? AD? Next conversion
? decfsz? Counter, f? ; ? Conversion? Counter? -? 1? =? 0? -& gt;
? goto main 0 10; ? spread
? movfw adsum
? Movwf results; ? The result? =? w
? Dial LED000
? movfw adsum+ 1
? Movwf results; ? The result? =? w
? Dial LED000
? movlw . 16; ? AD? Number of times? =? 10
? Movwf counter
? clrf adsum? ; ? Qing? A/D? Cumulative sum? /? General? register
? clrf adsum+ 1
? Go to MAIN0 10.
? ; ? /? ***? ***? ***? ***? ***? /serial output
LED000 movlw 8? ; ? Serial output? 8? Bit? W? =? eight
Movwf count? ; ? Count? =? w
LED00 1 bcf? Tricio, 4? ; ? clear
Btfsc result, 0? ; ? result.7=0? -& gt;
bsf? Tricio, 4? ; ? 00 10? 0000
bsf? Tricio, 5 years old? ; ? Generate a clock pulse? GP4? =? 1
bcf? Tricio, 5 years old? ; ? GP4? =? 0
RRF? Results, 1? ; ? Move to the left to get the next result bit.
decfsz? Count, 1? ; ? -? 1
goto led 00 1; ? & lt& gt? 0 cycle low
Return? ; ? =? 0
? ; ? /? ***? ***? ***? ***? ***? /
? End; ? Program terminator
- Previous article:How about Kunshan Libin coming to the plastic factory?
- Next article:What about Hefei Senchao Household Products Co., Ltd.?
- Related articles
- How much does it cost for first-tier cities to join KFC?
- Do you know Tengnan Hospital of Zaozhuang Mining Group?
- How many stars does Novotel Suzhou Taihu Hot Spring have?
- Shanghai Tongtai Graphic Design and Production Co., Ltd. Recruitment information, how about Shanghai Tongtai Graphic Design and Production Co., Ltd.
- Why does Kale Optoelectronics Huawei mobile phone flash back?
- How does Tongliang Haichen battery h 1 work?
- What are the academic qualifications of teachers and counselors in Taiyuan, Shanxi?
- Please fall in love with me
- How about Lu 'an Xingrui gearbox?
- China Zhentai Company, how long does it take for the social security personnel who have been detained to resign to enter?