1 / 24

Advanced Microcontrollers A practical approach

Advanced Microcontrollers A practical approach. Microcontrollers A practical approach. Goals Responsibilities Topics. Goals. Some more advanced knowledge of microcontrollers Reading and using data-sheets Building, programming and documenting a little microcontroller system.

radha
Download Presentation

Advanced Microcontrollers A practical approach

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. Advanced MicrocontrollersA practical approach

  2. MicrocontrollersA practical approach • Goals • Responsibilities • Topics

  3. Goals • Some more advanced knowledge of microcontrollers • Reading and using data-sheets • Building, programming and documenting a little microcontroller system.

  4. Responsibilities • The student is responsible for the hard-en software, there are more groups who must use it • Defects must be reported immediately

  5. MicrocontrollersA practical approach Topics • PIC family • Architecture PIC18F2580 • Interrupts • Serial communication • LCD • Assembly • A very little microcontroller

  6. MicrocontrollersA practical approach Topics • PIC family • Architecture PIC18F2580 • Interrupts • Serial communication • LCD • Assembly • A very little microcontroller

  7. PIC18F2580 Device

  8. PIC18F2580 pinout

  9. Block diagram

  10. Programming • Header • Functions • Initialisation … • Main program • Initialisation (function call) • Program with function calls in infinite loop

  11. Program header // Project name // Author // Date of creation // Revision number #include <p18f2580.h> #define off 0 #define on1

  12. Initialisation function Digital pin configuration void init(void) { PORTB = 0; // All OFF TRISA = 0b11111111; // All inputs TRISC = 0b11111111; // All inputs TRISB = 0b00111111; // RB6, RB7 output }

  13. Write Output function void LED2(char in) { PORTBbits.RB6 = in; // LED2 = in }

  14. Main Program void main(void) { init(); // initialisation while(1) { // infinite loop if (PORTAbits.RA4 == 1) LED2(ON); else LED2(OFF); } }

  15. Interruptssources • • External Interrupt RA2/INT • • TMR0 Overflow Interrupt • • PORTA Change Interrupts • • 2 Comparator Interrupts • • A/D Interrupt • • Timer1 Overflow Interrupt • • Timer2 Match Interrupt • • EEPROM Data Write Interrupt • • Fail-Safe Clock Monitor Interrupt • • Enhanced CCP Interrupt

  16. Interrupts(chapter 10 datasheet)sources

  17. Timer 0 • 8-bit/16-bit timer/counter • Readable and writeable • 3-bit software programmable prescaler (2-4-8-…-256) • Internal or external clock select • Edge select for external clock • Interrupt on overflow from 0xFF to 0x00

  18. Timer 0 T0CON

  19. Timer 0 ( interrupt example) /*********************** pic18f2580 **************************\ | Testprogram_1 MPlab C18-compiler | |21 juli 2013 J.S.D. Stokkink | +----------------------------------------------------------------------+ | USES: TIMER0 , High-interrupt priority | +---------------------------------------------------------------------+| || TIMER0 gives interrupt each 1sec (internal inerrupt)| | De Xtalfrequentie is 20MHz | | after each interrupt 1 second a binairy increase on led |\*************************************************************/ #include <p18F2580.h> #pragma config OSC = HS // HS oscillator 20 Mhz #pragma config WDT = OFF // Watchdog Timer disabled #pragma config LVP = OFF // Low Voltage ICSP disabled #pragma config PBADEN = OFF // PortB<4:0> configured as digital I/O

  20. Timer 0 ( interrupt example (2)) // Function-declarations: void InterruptHandlerHigh(void); void InitTimer0(void); void EnableHighInterrupts(void); // Global variables: unsigned int count=0;

  21. Timer 0 ( interrupt example (3)) #pragma code void main (void) { TRISC=0; //led's output PORTC=0; //led off InitTimer0(); EnableHighInterrupts(); // run forever: while(1) { // do nothing wait on interrupt } }

  22. Timer 0 ( interrupt example (4)) #pragma code void InitTimer0(void) { // init timer 0: INTCONbits.GIE = 0; // disable global interrupt INTCON2bits.TMR0IP = 1; // Timer 0 high priority interrupt RCONbits.IPEN = 1; // enable priority levels INTCONbits.PEIE = 1; // enable high priority interrupt T0CONbits.T0CS = 0; // internal instuction cycle clock (CLKO) T0CONbits.PSA = 0; // prescaler is assigned T0CONbits.T0PS2 = 1; // prescale value bit 2 T0CONbits.T0PS1 = 1; // prescale value bit 1 T0CONbits.T0PS0 = 1; // prescale value bit 0 ==> 1:256 T0CONbits.T08BIT = 0; // 16-bits timer TMR0H = 72; // set timer TMR0L = 229; // set timer ==> ca 1 sec INTCONbits.TMR0IE = 1; // Timer 0 interrupt enabled T0CONbits.TMR0ON = 1; // enable Timer 0 INTCONbits.GIE = 1; // enable global interrupt }

  23. Timer 0 ( interrupt example (5)) #pragma code void EnableHighInterrupts(void) { RCONbits.IPEN = 1; // enable interrupt priority levels INTCONbits.GIEH = 1; // enable all high priority iterrupts } // High priority interrupt vextor: #pragma code high_vector = 0x08 void high_interrupt(void) { _asmgotoInterruptHandlerHigh _endasm } #pragma code #pragma interrupt InterruptHandlerHigh void InterruptHandlerHigh(void) { if(INTCONbits.TMR0IF) // check for TMR0 overflow { INTCONbits.TMR0IF = 0; // clear interrupt flag TMR0H = 72; // reload timer TMR0L = 229; // reload timer PORTC++; // increase value on led } }

  24. Assignments lesson 1 • Make the exampleworking • Change the programm, let the counting do every 2 seconds • Reset the counting on the LED with • a RB0 interrupt

More Related