Using PICs 1

Using PICs 1 PowerPoint PPT Presentation


  • 109 Views
  • Uploaded on
  • Presentation posted in: General

Download Presentation

Using PICs 1

An Image/Link below is provided (as is) to download presentation

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.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


1. 1 Using PICs 1 PIC – Programmable Interface (I/O) Controller From Microchip - Flash Programmable devices with: EEPROM and RAM memory Digital I/O 10 bit Analogue input 8/16 bit Timer / Counters, Capture/Compare PWM output UART Other dedicated I/O (– e.g. I2C and USB) In-circuit programming Programmed in assembler or C Cheap!

2. 2 Using PICs 2 Main 8-bit PIC families F = Flash PIC10xx / PIC12Fxx / PIC16Fxx / PIC18Fxx

3. 3 Using PICs 3 PIC – Some devices PIC12C508 - 8-pin device - security systems and remote transmitter/receivers. Price ~ £1.50 PIC16F57 - 18/28-pin device, 72 bytes RAM, 2k Flash, 20 I/O lines. £ 0.88 ! All PICs have Power-on Reset, Watchdog Timer, code-protect and high I/O current ( ± 25mA) capability. Commonly used devices: 18F452 / 18F4520 and 16F877 / 16F887

4. 4 Using PICs 4 PIC16F877/18F452 (both ~ £5)

5. 5 Using PICs 5 Support Free C compiler, MPLAB IDE debugger and simulator Design 1. Chose PIC to suit. Problem - just too many ! 2. Software – Microchip C18 compiler and MPLAB 3. Understand how device works and its registers 4. Design hardware 5. Write your program

6. 6 Using PICs 6 PIC 18F452 32K Flash program memory 1536 bytes RAM 256 bytes EEPROM DC - 40MHz operation 4 timers 2 capture/compare registers (= PWM output = D/A) Serial Port 10-bit A/D Low power modes Watch Dog Timer

7. 7 Using PICs 7 DIP pin-out

8. 8 Using PICs 8 PIC design - simple !

9. 9 Using PICs 9 PIC ports Multi-function Port A - Digital I/O and Analogue Input Port C - PWM / analogue output and USART I/O Port B is the main I/O port Parallel I/O – e.g RC7/Rx/DT/SDO Digital I/O controlled by 3 ports: TRIS register (TRISA/TRISB) – sets direction (1=input) PORT register – set/reads values LAT register – output latch (used for read-modify-write) Compiler knows about these registers (in .H file)

10. 10 Using PICs 10 C code to flash light void main(void) { TRISB=0; // all PORTB as output PORTB=1; // set l.s. bit = 1 while (1) // infinite loop { delay( ); // wait (defined elsewhere) PORTB=0x80; // set m.s. bit delay( ); // wait PORTBbits.RB7 = 0; // can refer to individual bits } // end of while 1 }

11. 11 Using PICs 11 C code to flash light – also need # include <p18f452.h> // holds TRIS and PORT definitions # pragma config WDT = OFF void delay(void) { // software delay - about 50ms @ 20MHz unsigned char temp, chr; chr=139; while (chr>0) { temp=255; while (temp>0) { temp=temp-1; } //loop on temp chr=chr-1; } // loop on chr } // end delay

12. 12 Using PICs 12 Parallel input void main(void) { TRISA=0xFF; // input TRISB=0x0; // output while (1) // infinite loop { // read porta – output on portb PORTB = PORTA; } // end of while 1 }

13. 13 Using PICs 13 Other I/O Need to know how registers control I/O Serial – Set up I/O, baud rate etc. When is data received? When can data be transmitted? Analogue – Set port bit to analogue input. Start conversion, wait, read 10-bit input register Capture / compare registers – set up

14. 14 Using PICs 14 Interrupt programming I/O can interrupt processor 18F452 has 18 interrupt sources ! From: Timers 0 and 1, PORTB<7:4> bit change, Ext. interrupt 0-2, A/D converter, Serial I/O, Capture/Compare registers, EEPROM write, Bus collision, Low voltage detect … Each can be high or low priority, High priority vector at 0x8 and low vector at 0x18 Ten registers control interrupts – if time, we’ll do some interrupt programming

15. 15 Using PICs 15 Other considerations Configuration registers – set up of PIC e.g.: Crystal, RC or internal clock? WDT Power-up timer Power fail (Brown-out) detect Low Voltage programming

  • Login