1 / 25

Introduction to pic programming

Introduction to pic programming . By : Sherif Harhash. Contents . 1- what are micro controllers ? 2-how to use them ? 3- MC main criteria (I/O ports , timers , interrupts). 4- C-programming ( Mikro C pro for PIC). 5- Examples . 6- Questions . what are micro controllers ?.

gala
Download Presentation

Introduction to pic programming

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to pic programming By : SherifHarhash

  2. Contents • 1- what are micro controllers ? • 2-how to use them ? • 3- MC main criteria (I/O ports , timers , interrupts). • 4- C-programming ( Mikro C pro for PIC). • 5- Examples . • 6- Questions .

  3. what are micro controllers ? • Micro-controllers are the most generic device used in many applications . • Simply its an IC that can perform any wanted function-( according to its features) -.

  4. what are micro controllers ? • A microcontroller has a processor and many peripherals integrated with it on the same chip, like a flash memory, RAM, I/O ports, serial communication ports, ADC …Etc.

  5. what are micro controllers ? • A timer module to allow the MCU to perform tasks for certain time periods. • A serial I/O port to allow data to flow between the MCU and other devices such as a PC or another MCU. • An ADC to allow the MCU to accept analog inputs for processing.

  6. PIC Micro-controllers

  7. OSCILLATORS • Crystal oscillator: • A crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to establish oscillation. • Used for high precession timing requirements. • The capacitors are chosen according to the frequency and the preferred values in the datasheet of the used device.

  8. OSILLATOR SELECT • T0CS_bit: Clock Source Select bit • 1 = Transition on T0CKI pin • 0 = Internal instruction cycle clock (CLKO) • T0SE_bit: Source Edge Select bit • 1 = Increment on high-to-low transition on T0CKI pin • 0 = Increment on low-to-high transition on T0CKI pin

  9. C PROGRAMMINGLANGUAGE

  10. OPERATORS • + addition • -subtraction • * multiplication • / division • % modulus • a*=b is the same as a=a*b • a/=b a=a/b • a+=b a=a+b • a-=b a=a-b • a%=b a=a%b • a<<=b a=a<<b • a>>=b a=a>>b • a&=b a=a&b • a|=b a=a|b • a^=b a=a^b

  11. OPERATORS • Relational operators: • >,<,<=,>=,==,!= • Logical operators: • &&,||,! • Bitwise operators: • &, |, ^ (XOR), <<,>>,~ • Precedence: • 1.Casting • 2.Parentheses • 3.Negative • 4.Multiplication and division • 5.Addition and subtraction

  12. CONDITIONALSTATEMENTS • If statement: • if (expression) • { • statement(s); • } • If-else statement: • if (expression1) • { • statement(s) • } • else if(expression2) • { • statement(s) • } • else • { • statement(s) • }

  13. FOR LOOP • for( initialization ; conditional_test; increment ) • Example : • void main(void) • { • Int i; • for(i=0; i<10; i++) • printf(“%d “,i); • printf(“done”); • }

  14. ARRAYS • type array_name[size] = {value list}; • Ex. • inti[5] = {1,2,3,4,5}; • Multidimensional arrays: • intnum[3][3]={ 1,2,3, • 4,5,6, • 7,8,9};FUNCTIONS

  15. Functions • main() is the first function called when the program is executed. The other functions, function1() and function2(), can be called by any function in the program. • main() • { • Function1 • } • function1(inta,intb ) • { • Return() • } • function2() • { • }

  16. BREAK 10 mins. only break 

  17. I/O PORTS • Reading a port: • Means reading the status (voltage level) present on the pin. • Writing to a port: • Means writing to the port latches. • You have to determine the direction of the I/O pin before using it, this is done by changing the value of the TRIS register.

  18. I/O PORTS • The I/O pin direction is controlled by a register called TRIS. PORT<x> is controlled by the register TRIS<x>. • If you write ‘1’ in a bit in TRIS<x> register, this means that the corresponding bit in PORT<x> is input. • A ‘0’ means -> output.

  19. I/O PORTS • HOW to state data direction ? • TRIS A=0b 011001011 -> set pins (0 ,3,4,6) as o/p set pins (1,2,5,7) as i/p “ IN PORT A “ • PORT A=1; -> perform 1 as o/p for all port A pins • PORT A.f0=1; -> perform 1 as o/p for pin(0) in port A

  20. SWITCHES • We use switches to give an order to the MCU to do something by changing the voltage level applied on an I/O pin (input).

  21. SWITCHES • 1-Using RC circuit: • -We use it as a LPF, as the ripples • happen very fast (high frequency). • 2-By software: • By reading the value of the pin more than one time in small time intervals to make sure of the real value on the pin. • This done by testing the value, wait for some time (1~10 ms) and test again if the value is the same, so it’s the true value

  22. EXAMPLE 1 • Write a program outputs high on RC0, if RB0 is low using switches and leds.

  23. INTERRUPT • Definition: • An interrupt is an asynchronous signalindicate for an eventwhich needs processor’s attention immediately regardless to the instruction it executes at this moment. • It’s like a Doorbell.

  24. INTERRUPTDEFINITIONS • Interrupt Flag (IF): • A bit that is automatically set if the interrupt source (event) happens. • Global Interrupt Enable (GIE): • Enables (if set) all un-masked interrupts (interrupts with IE=1) or disables (if cleared) all interrupts. • Interrupt Enable (IE): • If the GIE was ‘1’, this bit forces the CPU to respond to the interrupt signal when IF=1 when the waited event happens.

  25. INTERRUPTDEFINITIONS • When the event (interrupt source) happens, the following steps happen: • 1-The corresponding interrupt flag (IF) will equal ‘1’. • 2-If the interrupt enable (IE)was ‘1’, and the global interrupt enable (GIE)was ‘1’ also, the GIE is cleared by hardware to disable any further interrupt to avoid responding to further interrupts. • 3-The return address is pushed into the stack and the PC is loaded with 0004h (the interrupt vector.

More Related