Electronics Design Lab TUTORIAL PIC Microcontrollers - PowerPoint PPT Presentation

Loading...

PPT – Electronics Design Lab TUTORIAL PIC Microcontrollers PowerPoint presentation | free to download - id: 48d1e8-NTc5Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Electronics Design Lab TUTORIAL PIC Microcontrollers

Description:

Title: Electronics Design Lab short course on: PIC Microcontrollers Author: fra Created Date: 2/8/2006 10:00:25 PM Document presentation format – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 20
Provided by: Fra14
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Electronics Design Lab TUTORIAL PIC Microcontrollers


1
Electronics Design LabTUTORIALPIC
Microcontrollers
  • Francesco Tenore
  • 2/10/2006

2
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
  • Implementations and Examples

3
Characteristics
  • RISC CPUs
  • 8-bit
  • 16-bit
  • Number of I/O pins 4-70
  • Memory types and sizes
  • Flash OTP ROM
  • 0.5k 256k

4
Speeds
  • All PICs require oscillators to execute
    instructions
  • Internal (low speeds, up to 8 MHz)
  • External (high speeds, up to 40 MHz)
  • Instructions are executed at least at ¼
    oscillator speed (4 clocks/instruction)
  • (Note not all PICs have internal oscillators)

5
A/D converters and C/C modules
  • All PICs have between 0 and 16 A/D converters
    with 8/10-bit resolution
  • 8-16 bit Timers/Counters
  • Comparator Modules (0-2)

6
Example PIC16F877A
  • 5/6 Programming pins
  • 8 A/D channels
  • 2 Oscillator Inputs
  • 2 RS-232 inputs
  • 33 I/O ports

7
Programming MPLab and Assembly
8
MPLab
  • Download _at_ http//microchip.com
  • Assembly compiler for programming PICs
  • Based on specific PIC instruction set
  • To upload the program
  • Compile Project?Build All (CtrlF10)
  • Erase the device Programmer? Erase Flash Device
  • Program Programmer? Program

9
Instruction Set
  • 35 single word instructions
  • Byte oriented file register operations
  • Bit oriented file register operations
  • Literal and control operations

10
Example 1
  • Using the PIC12F683 as a 2-state switch

11
Giving memory to a pushbutton
12
Giving memory to a pushbutton
  • In this example we
  • Store the state of the LED and
  • Turn off if on and
  • Turn on if off

13
Example 2
  • Using the PICs A/D converters for Pulse Width
    Modulation

14
(No Transcript)
15
Pulse Width Modulation (PWM)
  • 1-2 ms pulse used to control servomotors
  • In this example, we
  • ACQUIRE an analog 0-5V signal
  • CONVERT it into a 1-2 ms pulse that depends on
    the analog voltage and output the result on an
    output pin
  • REPEAT

16
Steps for Analog-to-Digital Conversion
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 (ADRESHADRESL), 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.
  • 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.

17
ADC on PIC 16F877
  • Configuration
  • ADCON0, ADCON1
  • Result
  • ADRESH, ADRESL
  • (See handout)

18
Samples
  • The microchip website www.microchip.com
  • offers samples of PICs (maximum 5) that are
    sent to you for free.
  • Please e-mail me at fra_at_jhu.edu if you have any
    questions.

19
EDL_test1.asm blinks an LED when pushbutton is
pressed. INCLUDE "P12F683.INC" ORG
0x000000 bsf STATUS,RP0 Bank 1
movlw b'01110010' 0x00 movwf OSCCON
0x01 goto START 0x02
ORG 0x000020 START COUNTER EQU
0x21 TEMP EQU 0x22 BCF STATUS,RP0 Bank
0 CLRF GPIO Init GPIO MOVLW 07h Set
GPlt20gt to MOVWF CMCON0 digital I/O BSF
STATUS,RP0 Bank 1 CLRF ANSEL digital I/O
MOVLW 28h Set GPlt5gt and GPlt3gt as inputs
MOVWF TRISIO and set GPlt4,20gt as outputs
BCF STATUS,RP0 Bank 0 BSF GPIO,0
LOOP BTFSS GPIO,5 skip if
button NOT pressed GOTO CLEAR_ROUTINE
otherwise GOTO LOOP CLEAR_ROUTINE
INCF COUNTER,1 increment the
counter MOVLW 0x01 w1
ANDWF COUNTER,0 counter AND w gt
w 0x01 MOVWF TEMP
TEMP 0x01 BTFSC TEMP,0
skip if TEMP is 0 BCF GPIO,0
otherwise, clear GPIOlt0gt BTFSS TEMP,0
BSF GPIO,0 if it's 1, then
set it. LOOP2 BTFSC GPIO,5 GOTO
LOOP GOTO LOOP2 END
About PowerShow.com