Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006 The Microchip ® PIC ucontrollers http://www.microchip.com Characteristics types; speeds; I/O pins; Analog to Digital Converters; Capture/Compare modules Programming (MPLab) Instruction set
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
(*Note: not all PICs have internal oscillators)
5/6 Programming pins
8 A/D channels
2 Oscillator Inputs
2 RS-232 inputs
33 I/O ports
Using the PIC12F683 as a 2-state switch
Using the PICs A/D converters for Pulse Width Modulation
1. Configure the A/D module:
• Configure analog pins/voltage reference and digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set PEIE bit
• Set GIE bit
3. Wait the required acquisition time.
4. Start conversion:
• Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
(with interrupts enabled); OR
• Waiting for the A/D interrupt
6. Read A/D result register pair
(ADRESH:ADRESL), clear bit ADIF if required.
7. For the next conversion, go to step 1 or step 2, as required. The A/D conversion time per bit is defined as TAD. A minimum wait of 2TAD is required before the next acquisition starts.
offers samples of PICs (maximum 5) that are sent to you for free.
Please e-mail me at firstname.lastname@example.org if you have any questions.
bsf STATUS,RP0 ;Bank 1
movlw b'01110010' ; 0x00
movwf OSCCON ; 0x01
goto START ; 0x02
COUNTER EQU 0x21
TEMP EQU 0x22
BCF STATUS,RP0 ;Bank 0
CLRF GPIO ;Init GPIO
MOVLW 07h ;Set GP<2:0> to
MOVWF CMCON0 ;digital I/O
BSF STATUS,RP0 ;Bank 1
CLRF ANSEL ;digital I/O
MOVLW 28h ;Set GP<5> and GP<3> as inputs
MOVWF TRISIO ;and set GP<4,2:0> as outputs
BCF STATUS,RP0 ;Bank 0
BTFSS GPIO,5 ; skip if button NOT pressed
GOTO CLEAR_ROUTINE ; otherwise
INCF COUNTER,1 ; increment the counter
MOVLW 0x01 ; w=1
ANDWF COUNTER,0 ; counter AND w => ; w = 0x01
MOVWF TEMP ; TEMP = 0x01
BTFSC TEMP,0 ; skip if TEMP is 0
BCF GPIO,0 ; otherwise, clear GPIO<0>
BSF GPIO,0 ; if it's 1, then set it.