SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
CENTRE OF DIPLOMA STUDIES



COMPUTER ADDED DESIGN LABORATORY



   LABORATORY INSTRUCTION SHEET



                        DEK 3133
Subject Code and Name
                        MICROCONTROLLER

  Experiment Code       03

                        Introduction to functions, conditions and
   Experiment Title     Hardware Timer using TMR0

    Course Code         DET/DEE/DEX
Document Reference
                         No.                     RPP-05                 Page. Number            Page |1
                                                                        Edition                   1
                                                   LABORATORY           Revision No.               4
                            Document Title
                                                    PRACTICUM           Effective Date          27/7/2010
                                                                        Amendment Date          27/7/2010

                                        SUBJECT INFORMATION

SUBJECT         : DEK 3133 MICROCONTROLLER

TOPIC           : Lab 3 – Introduction to functions, conditions and Hardware Timer using TMR0

AIM             : Learn the further programming technique using C language



1       OBJECTIVES

         1.1   To understand the concept of programming in C using functions and conditions

         1.2   To learn how to use TMR0 as a hardware timer


2       EQUIPMENT


         2.1   PIC Development Board – PICDEV

         2.2   MPLAB IDE Program

         2.3   Mikro C

         2.4   Proteus

         2.5   The PIC Development Board User manual

         2.6   Power supply 9V
Document Reference
                         No.                        RPP-05                  Page. Number               Page |2
                                                                            Edition                      1
                                                      LABORATORY            Revision No.                      4
                              Document Title
                                                       PRACTICUM            Effective Date             27/7/2010
                                                                            Amendment Date             27/7/2010

3       THEORY

          3.1   Functions




          3.2   Conditions




          3.3 Using TMR0
         The special file register 01, Timer Zero (TMR0), which can be used as a counter or timer which, once
         started, run independently of the program execution. This mean it can count inputs or clock pulses
Document Reference
                          No.                       RPP-05                 Page. Number               Page |3
                                                                           Edition                      1
                                                      LABORATORY           Revision No.                     4
                              Document Title
                                                       PRACTICUM           Effective Date              27/7/2010
                                                                           Amendment Date              27/7/2010

        concurrently with the program. The counter/timer can also be set up to generate an interrupt when it has
        reached its maximum value, so that the main program does not have to keep checking it to see if a
        particular count has been reached.

         3.4       REGISTERS ASSOCIATED WITH TIMER0




    •    TMR0
           o 8 bit TMR0 Module Register
           o Count from 0 to 255 (00h to FFh)

    •    INTCON
               o GIE - Global Interrupt Enable bit - controls all possible interrupt sources
                 simultaneously.
                        1 - Enables all unmasked interrupts.
                        0 - Disables all interrupts.
               o    T0IE - TMR0 Overflow Interrupt Enable bit controls interrupt enabled by TMR0 overflow.
                            1 - Enables the TMR0 interrupt.
                            0 - Disables the TMR0 interrupt.
               o    T0IF - TMR0 Overflow Interrupt Flag bit registers the timer TMR0 register overflow, when
                    counting starts from zero.
                            1 - TMR0 register has overflowed (bit must be cleared in software).
                            0 - TMR0 register has not overflowed.
Document Reference
                      No.                         RPP-05                  Page. Number     Page |4
                                                                          Edition            1
                                                    LABORATORY            Revision No.        4
                           Document Title
                                                     PRACTICUM            Effective Date   27/7/2010
                                                                          Amendment Date   27/7/2010




    •   OPTION
          o TOCS – Clock Select bit (Bit 5)
                  1 – Pulses are brought to TMR0 timer/counter input through the RA4 pin
                  0 – Internal cycle clock (Fosc/4)

           o   TOSE – Source Edge Select bit (Bit 4)
                      1 – Increment on high to low transition on TMR0 pin
                      0 – increment on low to high transition on TMR0 pin
           o   PSA – Prescaler Assignment bit (Bit 3)
                      1 – Prescaler is assigned to the WDT
                      0 – Prescaler is assigned to the TMR0 timer/counter
           o   PS2 (Bit 2), PS1(Bit 1), PS0 (Bit 0) – Prescaler Rate Select bit

               PS2              PS1               PS0            TMR0             WDT
                0                 0                0                1:2             1:1
                0                 0                1                1:4             1:2
                0                 1                0                1:8             1:4
                0                 1                1               1:16             1:8
                1                 0                0               1:32            1:16
                1                 0                1               1:64            1:32
                1                 1                0              1:128            1:64
                1                 1                1              1:256           1:128




 Prepared By:                                               Approved by: 
                                                            
Signature :                                                Signature: 
Name: Mohamad Bin Md. Som                                  Name: Shamsul B. Mohamad 
Date: 27 July 2010                                         Date: 27 July 2010 
Document Reference
                         No.                       RPP-05                  Page. Number              Page |5
                                                                           Edition                     1
                                                      LABORATORY           Revision No.                   4
                             Document Title
                                                       PRACTICUM           Effective Date            27/7/2010
                                                                           Amendment Date            27/7/2010

4       ATTENTION

         4.1      Do not move any IC or device inside the board without any order from your instructor.



5       EXPERIMENT PROCEDURE

         5.1     Functions and Conditions

         5.1.1    Base on the circuit below (circuit 1), key in the given C code and simulate it using 
                  Proteus. Write your observations. 




                                                    Circuit 1
Document Reference
                        No.                       RPP-05                  Page. Number              Page |6
                                                                          Edition                     1
                                                    LABORATORY            Revision No.                   4
                           Document Title
                                                     PRACTICUM            Effective Date            27/7/2010
                                                                          Amendment Date            27/7/2010

#define       BUTTON1   PORTA.F0
#define       BUTTON2   PORTA.F1
#define       BUTTON3   PORTA.F2
#define       BUTTON4   PORTA.F3

void pattern1(void)             //function for pattern 1
{
  PORTB = 0b11111111;
}
void pattern2(void)             //function for pattern 2
{
  PORTB = 0b10101010;
}
void pattern3(void)             //function for pattern 3
{
  PORTB = 0b11110000;
}
void pattern4(void)             //function for pattern 4
{
  PORTB = 0b00001111;
}

void main(void)
{
     ADCON1 = 0b00000110; //Set ADCON1 for Port A as a digital input
     TRISA = 0b11111111; //Port A as input port
     TRISB = 0b00000000; //Port B as output port
     PORTB = 0b00000000; //Clear PORTB at start up

     while(1) //endless loop
     {
        if (BUTTON1 == 1) //Test button at PORTA bit 0 if pressed.
             pattern1();   //call function pattern1
        else if (BUTTON2 == 1)
             pattern2();   //call function pattern2
        else if (BUTTON3 == 1)
             pattern3();   //call function pattern3
        else if (BUTTON4 == 1)
             pattern4();   //call function pattern4
        else
             PORTB = 0b00000000; //All LED off if no button pressed
     } //end of while (endless loop)
}//end of main func

        5.2    Assignment 1.


Base on the Circuit 1, Modify the C code so that each button have a different pattern of animated LEDs. Use 1
second delay for each changing pattern. Test your result in Proteus and put your modifying code in the report.
Document Reference
                   No.                       RPP-05                Page. Number             Page |7
                                                                   Edition                    1
                                               LABORATORY          Revision No.                  4
                        Document Title
                                                PRACTICUM          Effective Date            27/7/2010
                                                                   Amendment Date            27/7/2010

    5.3     Using TMR0 as a Hardware Timer




                                             Circuit 2

    5.3.1    Base on the figure above (Circuit 2), the PIC use 4Mhz for its clock speed. Write the 
             program to blink the LED every one second by using TMR0. The code is shown below. 

    #define   LED1 PORTB.F0
    #define   TOCS OPTION_REG.F5
    #define   TOSE OPTION_REG.F4
    #define   PSA OPTION_REG.F3
    #define   PS2 OPTION_REG.F2
    #define   PS1 OPTION_REG.F1
    #define   PS0 OPTION_REG.F0

    #define GIE INTCON.F7
    #define TMR0IE INTCON.F5
    #define TMR0IF INTCON.F2

    //Public Variable
    unsigned int overflow;
    void interrupt(void)   //Interrupt subroutine
    {
      if (TMR0IE == 1 && TMR0IF == 1) //TMR0 made interrupt
Document Reference
                    No.                       RPP-05                Page. Number              Page |8
                                                                    Edition                     1
                                                LABORATORY          Revision No.                   4
                          Document Title
                                                 PRACTICUM          Effective Date            27/7/2010
                                                                    Amendment Date            27/7/2010

        {
            overflow++;
            TMR0IF = 0;       //clear interrupt flag
            TMR0IE = 0;       //Disable TMR0 interrupt

            if (overflow == 15) //TMR0 is overflow about 15 times ~~ 1 second.
            {
               LED1 = ~LED1;
               overflow = 0;   //reset overflow to 0
            }
            TMR0IE = 1;    //enable TMR0 interrupt
            TMR0 = 0;      //restart TMR0 value to 0
        }

    }

    void main(void)
    {
      overflow = 0;
      //port setup
      TRISB = 0; //port B is output
      PORTB = 0; //initial value for PORTB is 0

        //TMR0 setup
        TOCS = 0; //Internal cycle clock (Fosc/4)
        PSA = 0;   //Prescaler is assinged to the TMR0 timer
        PS2 = 1;
        PS1 = 1;
        PS0 = 1;   //Prescaler rate is selected to 1:256
        TMR0 = 0; //Initial value for TMR0 is 0

        //Interrupt Setup
        GIE = 1;    //Enable all interrupt
        TMR0IE = 1; //Enable the TMR0 interrupt

        while(1);    //infinite loop

    }

    5.3.2    Burn the *.hex file into PIC and test the PIC at the development board. Write your 
             observation in the report. 

    5.4     Assignment 2

    5.4.1    Write a C program so that the LED is blinking using hardware delay which is blinking 
             every 1 second. Assume PIC clock speed is 1MHz and prescaler used is 1:256. Simulate 
             your result using Proteus. 
Document Reference
                             No.                       RPP-05             Page. Number               Page |9
                                                                          Edition                      1
                                                         LABORATORY       Revision No.                  4
                                Document Title
                                                          PRACTICUM       Effective Date             27/7/2010
                                                                          Amendment Date             27/7/2010




6       REPORT PREPARATION AND SCHEMA.


(1)       2 persons for 1 report.

(2)       Due date to send report is 1 weeks after lab date.

(3)       Report schema following below requirements:

        • Lab report cover sheet for 1st page.
        • Objective, theory, equipments for the 2nd page. (5)                              (5M)
        • Observations. (20)
           1. Observations from 5.1.1 (Proteus Simulation)                                 (10 M)
           2. Observations from 5.3.2 (TMR0 run on development board)                      (10 M )
        • Result. (35)
                 1. Assignment 1 source code & Flow Chart                ( 15 M )
                 2. Assignment 2 source code & Proteus Simulation        ( 20 M )
        • Discussion. (25)
            1. List the Registers related to TMR0 and describes the procedure to setup the TMR0 (15M)
            2. If the PIC is supplied with 1 MHz clock speed, calculate time taken for TMR0 to
               overflow. Assume that a prescaler 1:256 is used. Show the calculation in your report
                                                                                           (10 M)



        • Conclusions. (15)

Contenu connexe

En vedette

Performance of dc motors experiment 2
Performance of dc motors experiment 2Performance of dc motors experiment 2
Performance of dc motors experiment 2Karimi LordRamza
 
Projek rekabentuk
Projek rekabentukProjek rekabentuk
Projek rekabentukmkazree
 
Projek rekabentuk1
Projek rekabentuk1Projek rekabentuk1
Projek rekabentuk1mkazree
 
rekabentruk berbantu komputer Lab 4
rekabentruk berbantu komputer Lab 4rekabentruk berbantu komputer Lab 4
rekabentruk berbantu komputer Lab 4mkazree
 
Introduction to pic
Introduction to picIntroduction to pic
Introduction to picPRADEEP
 
19199406 embedded-c-tutorial-8051
19199406 embedded-c-tutorial-805119199406 embedded-c-tutorial-8051
19199406 embedded-c-tutorial-8051PRADEEP
 
Chapter 4 synchronous machine
Chapter 4 synchronous machineChapter 4 synchronous machine
Chapter 4 synchronous machinemkazree
 
Tutorial 2 amplitude modulation
Tutorial 2 amplitude  modulationTutorial 2 amplitude  modulation
Tutorial 2 amplitude modulationmkazree
 
120102011
120102011120102011
120102011mkazree
 
Tutorial chapter 3 robotic
Tutorial chapter 3 roboticTutorial chapter 3 robotic
Tutorial chapter 3 roboticmkazree
 
ADC Interfacing with pic Microcontrollert
ADC Interfacing with pic MicrocontrollertADC Interfacing with pic Microcontrollert
ADC Interfacing with pic Microcontrollertleapshare007
 
Tutorial chapter 2 robotic
Tutorial chapter 2 roboticTutorial chapter 2 robotic
Tutorial chapter 2 roboticmkazree
 
8-bit PIC Microcontrollers
8-bit PIC Microcontrollers8-bit PIC Microcontrollers
8-bit PIC MicrocontrollersPremier Farnell
 
Unit 3 tables and data structures
Unit 3 tables and data structuresUnit 3 tables and data structures
Unit 3 tables and data structuresPRADEEP
 
The Electronic Hobby Kit
The Electronic Hobby KitThe Electronic Hobby Kit
The Electronic Hobby Kitmkazree
 
Foster-seely and Ratio Detector (Discriminator )
Foster-seely and Ratio Detector (Discriminator )Foster-seely and Ratio Detector (Discriminator )
Foster-seely and Ratio Detector (Discriminator )mkazree
 

En vedette (18)

Performance of dc motors experiment 2
Performance of dc motors experiment 2Performance of dc motors experiment 2
Performance of dc motors experiment 2
 
Projek rekabentuk
Projek rekabentukProjek rekabentuk
Projek rekabentuk
 
Projek rekabentuk1
Projek rekabentuk1Projek rekabentuk1
Projek rekabentuk1
 
rekabentruk berbantu komputer Lab 4
rekabentruk berbantu komputer Lab 4rekabentruk berbantu komputer Lab 4
rekabentruk berbantu komputer Lab 4
 
Mp lab
Mp labMp lab
Mp lab
 
Introduction to pic
Introduction to picIntroduction to pic
Introduction to pic
 
19199406 embedded-c-tutorial-8051
19199406 embedded-c-tutorial-805119199406 embedded-c-tutorial-8051
19199406 embedded-c-tutorial-8051
 
16f877
16f87716f877
16f877
 
Chapter 4 synchronous machine
Chapter 4 synchronous machineChapter 4 synchronous machine
Chapter 4 synchronous machine
 
Tutorial 2 amplitude modulation
Tutorial 2 amplitude  modulationTutorial 2 amplitude  modulation
Tutorial 2 amplitude modulation
 
120102011
120102011120102011
120102011
 
Tutorial chapter 3 robotic
Tutorial chapter 3 roboticTutorial chapter 3 robotic
Tutorial chapter 3 robotic
 
ADC Interfacing with pic Microcontrollert
ADC Interfacing with pic MicrocontrollertADC Interfacing with pic Microcontrollert
ADC Interfacing with pic Microcontrollert
 
Tutorial chapter 2 robotic
Tutorial chapter 2 roboticTutorial chapter 2 robotic
Tutorial chapter 2 robotic
 
8-bit PIC Microcontrollers
8-bit PIC Microcontrollers8-bit PIC Microcontrollers
8-bit PIC Microcontrollers
 
Unit 3 tables and data structures
Unit 3 tables and data structuresUnit 3 tables and data structures
Unit 3 tables and data structures
 
The Electronic Hobby Kit
The Electronic Hobby KitThe Electronic Hobby Kit
The Electronic Hobby Kit
 
Foster-seely and Ratio Detector (Discriminator )
Foster-seely and Ratio Detector (Discriminator )Foster-seely and Ratio Detector (Discriminator )
Foster-seely and Ratio Detector (Discriminator )
 

Similaire à Lab 3 microcontroller

8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcdabhishek upadhyay
 
Timers done by Priyanga KR
Timers done by Priyanga KRTimers done by Priyanga KR
Timers done by Priyanga KRPriyangaKR1
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsCorrado Santoro
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptHebaEng
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 
Testo 410 datasheet 2012
Testo 410 datasheet 2012Testo 410 datasheet 2012
Testo 410 datasheet 2012Testo Limited
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxnaveen088888
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorialFutura infotech
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
TPOT: The data science assistant
TPOT: The data science assistantTPOT: The data science assistant
TPOT: The data science assistantHoffman Lab
 
Aging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR ProjectAging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR ProjectUkrainian Nuclear Society
 
Open ComRTOS 1.4_tutorial_2o4_presentation
Open ComRTOS 1.4_tutorial_2o4_presentationOpen ComRTOS 1.4_tutorial_2o4_presentation
Open ComRTOS 1.4_tutorial_2o4_presentationEric Verhulst
 

Similaire à Lab 3 microcontroller (20)

8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
Timers done by Priyanga KR
Timers done by Priyanga KRTimers done by Priyanga KR
Timers done by Priyanga KR
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
embeded
embededembeded
embeded
 
Testo 410 datasheet 2012
Testo 410 datasheet 2012Testo 410 datasheet 2012
Testo 410 datasheet 2012
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Timers
TimersTimers
Timers
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorial
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
TPOT: The data science assistant
TPOT: The data science assistantTPOT: The data science assistant
TPOT: The data science assistant
 
Aging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR ProjectAging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR Project
 
Aging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR ProjectAging Management Experience. Status of the IVMR Project
Aging Management Experience. Status of the IVMR Project
 
Open ComRTOS 1.4_tutorial_2o4_presentation
Open ComRTOS 1.4_tutorial_2o4_presentationOpen ComRTOS 1.4_tutorial_2o4_presentation
Open ComRTOS 1.4_tutorial_2o4_presentation
 
8051e
8051e8051e
8051e
 

Plus de mkazree

Coal Fired Power Plant
Coal Fired Power PlantCoal Fired Power Plant
Coal Fired Power Plantmkazree
 
Contoh kertas kerja program
Contoh kertas kerja programContoh kertas kerja program
Contoh kertas kerja programmkazree
 
Communication Engineering - Chapter 6 - Noise
Communication Engineering - Chapter 6 - NoiseCommunication Engineering - Chapter 6 - Noise
Communication Engineering - Chapter 6 - Noisemkazree
 
Chapter 5 fm receivers
Chapter 5  fm receiversChapter 5  fm receivers
Chapter 5 fm receiversmkazree
 
Dek3223 chapter 2 robotic
Dek3223 chapter 2 roboticDek3223 chapter 2 robotic
Dek3223 chapter 2 roboticmkazree
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receiversmkazree
 
Dek3223 chapter 3 industrial robotic
Dek3223 chapter 3 industrial roboticDek3223 chapter 3 industrial robotic
Dek3223 chapter 3 industrial roboticmkazree
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receiversmkazree
 
Comm introduction
Comm introductionComm introduction
Comm introductionmkazree
 
Chapter2 cont
Chapter2 contChapter2 cont
Chapter2 contmkazree
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulationmkazree
 
Chapter5 dek 3143 dae 32303 9 (nota tambahan)
Chapter5 dek 3143 dae 32303 9 (nota tambahan)Chapter5 dek 3143 dae 32303 9 (nota tambahan)
Chapter5 dek 3143 dae 32303 9 (nota tambahan)mkazree
 
Ii20102011
Ii20102011Ii20102011
Ii20102011mkazree
 
Chapter 3 induction machine
Chapter 3 induction machineChapter 3 induction machine
Chapter 3 induction machinemkazree
 
Chapter 2 transformer new
Chapter 2 transformer newChapter 2 transformer new
Chapter 2 transformer newmkazree
 
Chapter 1 dc machines new
Chapter 1 dc machines newChapter 1 dc machines new
Chapter 1 dc machines newmkazree
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copymkazree
 
Chp1 68000 microprocessor copy
Chp1 68000 microprocessor   copyChp1 68000 microprocessor   copy
Chp1 68000 microprocessor copymkazree
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copymkazree
 

Plus de mkazree (20)

Coal Fired Power Plant
Coal Fired Power PlantCoal Fired Power Plant
Coal Fired Power Plant
 
Contoh kertas kerja program
Contoh kertas kerja programContoh kertas kerja program
Contoh kertas kerja program
 
Communication Engineering - Chapter 6 - Noise
Communication Engineering - Chapter 6 - NoiseCommunication Engineering - Chapter 6 - Noise
Communication Engineering - Chapter 6 - Noise
 
Chapter 5 fm receivers
Chapter 5  fm receiversChapter 5  fm receivers
Chapter 5 fm receivers
 
Dek3223 chapter 2 robotic
Dek3223 chapter 2 roboticDek3223 chapter 2 robotic
Dek3223 chapter 2 robotic
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receivers
 
Dek3223 chapter 3 industrial robotic
Dek3223 chapter 3 industrial roboticDek3223 chapter 3 industrial robotic
Dek3223 chapter 3 industrial robotic
 
Chapter 3 am receivers
Chapter 3 am receiversChapter 3 am receivers
Chapter 3 am receivers
 
Comm introduction
Comm introductionComm introduction
Comm introduction
 
Chapter2 cont
Chapter2 contChapter2 cont
Chapter2 cont
 
Chapter 2 amplitude_modulation
Chapter 2 amplitude_modulationChapter 2 amplitude_modulation
Chapter 2 amplitude_modulation
 
Chapter5 dek 3143 dae 32303 9 (nota tambahan)
Chapter5 dek 3143 dae 32303 9 (nota tambahan)Chapter5 dek 3143 dae 32303 9 (nota tambahan)
Chapter5 dek 3143 dae 32303 9 (nota tambahan)
 
Ii20102011
Ii20102011Ii20102011
Ii20102011
 
Chapter 3 induction machine
Chapter 3 induction machineChapter 3 induction machine
Chapter 3 induction machine
 
Chapter 2 transformer new
Chapter 2 transformer newChapter 2 transformer new
Chapter 2 transformer new
 
Chapter 1 dc machines new
Chapter 1 dc machines newChapter 1 dc machines new
Chapter 1 dc machines new
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
 
Chp1 68000 microprocessor copy
Chp1 68000 microprocessor   copyChp1 68000 microprocessor   copy
Chp1 68000 microprocessor copy
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copy
 

Dernier

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 

Dernier (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

Lab 3 microcontroller

  • 1. CENTRE OF DIPLOMA STUDIES COMPUTER ADDED DESIGN LABORATORY LABORATORY INSTRUCTION SHEET DEK 3133 Subject Code and Name MICROCONTROLLER Experiment Code 03 Introduction to functions, conditions and Experiment Title Hardware Timer using TMR0 Course Code DET/DEE/DEX
  • 2. Document Reference   No. RPP-05 Page. Number Page |1 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 SUBJECT INFORMATION SUBJECT : DEK 3133 MICROCONTROLLER TOPIC : Lab 3 – Introduction to functions, conditions and Hardware Timer using TMR0 AIM : Learn the further programming technique using C language 1 OBJECTIVES 1.1 To understand the concept of programming in C using functions and conditions 1.2 To learn how to use TMR0 as a hardware timer 2 EQUIPMENT 2.1 PIC Development Board – PICDEV 2.2 MPLAB IDE Program 2.3 Mikro C 2.4 Proteus 2.5 The PIC Development Board User manual 2.6 Power supply 9V
  • 3. Document Reference   No. RPP-05 Page. Number Page |2 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 3 THEORY 3.1 Functions 3.2 Conditions 3.3 Using TMR0 The special file register 01, Timer Zero (TMR0), which can be used as a counter or timer which, once started, run independently of the program execution. This mean it can count inputs or clock pulses
  • 4. Document Reference   No. RPP-05 Page. Number Page |3 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 concurrently with the program. The counter/timer can also be set up to generate an interrupt when it has reached its maximum value, so that the main program does not have to keep checking it to see if a particular count has been reached. 3.4 REGISTERS ASSOCIATED WITH TIMER0 • TMR0 o 8 bit TMR0 Module Register o Count from 0 to 255 (00h to FFh) • INTCON o GIE - Global Interrupt Enable bit - controls all possible interrupt sources simultaneously. 1 - Enables all unmasked interrupts. 0 - Disables all interrupts. o T0IE - TMR0 Overflow Interrupt Enable bit controls interrupt enabled by TMR0 overflow. 1 - Enables the TMR0 interrupt. 0 - Disables the TMR0 interrupt. o T0IF - TMR0 Overflow Interrupt Flag bit registers the timer TMR0 register overflow, when counting starts from zero. 1 - TMR0 register has overflowed (bit must be cleared in software). 0 - TMR0 register has not overflowed.
  • 5. Document Reference   No. RPP-05 Page. Number Page |4 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 • OPTION o TOCS – Clock Select bit (Bit 5) 1 – Pulses are brought to TMR0 timer/counter input through the RA4 pin 0 – Internal cycle clock (Fosc/4) o TOSE – Source Edge Select bit (Bit 4) 1 – Increment on high to low transition on TMR0 pin 0 – increment on low to high transition on TMR0 pin o PSA – Prescaler Assignment bit (Bit 3) 1 – Prescaler is assigned to the WDT 0 – Prescaler is assigned to the TMR0 timer/counter o PS2 (Bit 2), PS1(Bit 1), PS0 (Bit 0) – Prescaler Rate Select bit PS2 PS1 PS0 TMR0 WDT 0 0 0 1:2 1:1 0 0 1 1:4 1:2 0 1 0 1:8 1:4 0 1 1 1:16 1:8 1 0 0 1:32 1:16 1 0 1 1:64 1:32 1 1 0 1:128 1:64 1 1 1 1:256 1:128  Prepared By:   Approved by:      Signature :  Signature:  Name: Mohamad Bin Md. Som  Name: Shamsul B. Mohamad  Date: 27 July 2010  Date: 27 July 2010 
  • 6. Document Reference   No. RPP-05 Page. Number Page |5 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 4 ATTENTION 4.1 Do not move any IC or device inside the board without any order from your instructor. 5 EXPERIMENT PROCEDURE 5.1 Functions and Conditions 5.1.1 Base on the circuit below (circuit 1), key in the given C code and simulate it using  Proteus. Write your observations.  Circuit 1
  • 7. Document Reference   No. RPP-05 Page. Number Page |6 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 #define BUTTON1 PORTA.F0 #define BUTTON2 PORTA.F1 #define BUTTON3 PORTA.F2 #define BUTTON4 PORTA.F3 void pattern1(void) //function for pattern 1 { PORTB = 0b11111111; } void pattern2(void) //function for pattern 2 { PORTB = 0b10101010; } void pattern3(void) //function for pattern 3 { PORTB = 0b11110000; } void pattern4(void) //function for pattern 4 { PORTB = 0b00001111; } void main(void) { ADCON1 = 0b00000110; //Set ADCON1 for Port A as a digital input TRISA = 0b11111111; //Port A as input port TRISB = 0b00000000; //Port B as output port PORTB = 0b00000000; //Clear PORTB at start up while(1) //endless loop { if (BUTTON1 == 1) //Test button at PORTA bit 0 if pressed. pattern1(); //call function pattern1 else if (BUTTON2 == 1) pattern2(); //call function pattern2 else if (BUTTON3 == 1) pattern3(); //call function pattern3 else if (BUTTON4 == 1) pattern4(); //call function pattern4 else PORTB = 0b00000000; //All LED off if no button pressed } //end of while (endless loop) }//end of main func 5.2 Assignment 1. Base on the Circuit 1, Modify the C code so that each button have a different pattern of animated LEDs. Use 1 second delay for each changing pattern. Test your result in Proteus and put your modifying code in the report.
  • 8. Document Reference   No. RPP-05 Page. Number Page |7 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 5.3 Using TMR0 as a Hardware Timer Circuit 2 5.3.1 Base on the figure above (Circuit 2), the PIC use 4Mhz for its clock speed. Write the  program to blink the LED every one second by using TMR0. The code is shown below.  #define LED1 PORTB.F0 #define TOCS OPTION_REG.F5 #define TOSE OPTION_REG.F4 #define PSA OPTION_REG.F3 #define PS2 OPTION_REG.F2 #define PS1 OPTION_REG.F1 #define PS0 OPTION_REG.F0 #define GIE INTCON.F7 #define TMR0IE INTCON.F5 #define TMR0IF INTCON.F2 //Public Variable unsigned int overflow; void interrupt(void) //Interrupt subroutine { if (TMR0IE == 1 && TMR0IF == 1) //TMR0 made interrupt
  • 9. Document Reference   No. RPP-05 Page. Number Page |8 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 { overflow++; TMR0IF = 0; //clear interrupt flag TMR0IE = 0; //Disable TMR0 interrupt if (overflow == 15) //TMR0 is overflow about 15 times ~~ 1 second. { LED1 = ~LED1; overflow = 0; //reset overflow to 0 } TMR0IE = 1; //enable TMR0 interrupt TMR0 = 0; //restart TMR0 value to 0 } } void main(void) { overflow = 0; //port setup TRISB = 0; //port B is output PORTB = 0; //initial value for PORTB is 0 //TMR0 setup TOCS = 0; //Internal cycle clock (Fosc/4) PSA = 0; //Prescaler is assinged to the TMR0 timer PS2 = 1; PS1 = 1; PS0 = 1; //Prescaler rate is selected to 1:256 TMR0 = 0; //Initial value for TMR0 is 0 //Interrupt Setup GIE = 1; //Enable all interrupt TMR0IE = 1; //Enable the TMR0 interrupt while(1); //infinite loop } 5.3.2 Burn the *.hex file into PIC and test the PIC at the development board. Write your  observation in the report.  5.4 Assignment 2 5.4.1 Write a C program so that the LED is blinking using hardware delay which is blinking  every 1 second. Assume PIC clock speed is 1MHz and prescaler used is 1:256. Simulate  your result using Proteus. 
  • 10. Document Reference   No. RPP-05 Page. Number Page |9 Edition 1 LABORATORY Revision No. 4 Document Title PRACTICUM Effective Date 27/7/2010 Amendment Date 27/7/2010 6 REPORT PREPARATION AND SCHEMA. (1) 2 persons for 1 report. (2) Due date to send report is 1 weeks after lab date. (3) Report schema following below requirements: • Lab report cover sheet for 1st page. • Objective, theory, equipments for the 2nd page. (5) (5M) • Observations. (20) 1. Observations from 5.1.1 (Proteus Simulation) (10 M) 2. Observations from 5.3.2 (TMR0 run on development board) (10 M ) • Result. (35) 1. Assignment 1 source code & Flow Chart ( 15 M ) 2. Assignment 2 source code & Proteus Simulation ( 20 M ) • Discussion. (25) 1. List the Registers related to TMR0 and describes the procedure to setup the TMR0 (15M) 2. If the PIC is supplied with 1 MHz clock speed, calculate time taken for TMR0 to overflow. Assume that a prescaler 1:256 is used. Show the calculation in your report (10 M) • Conclusions. (15)