Having Trouble with Timer (8051) - any help appreciated

This is a discussion on Having Trouble with Timer (8051) - any help appreciated within the C Programming forums, part of the General Programming Boards category; I am working on a program that takes an input from a switch (connected to P0.0) and causes 4 LEDs ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    1

    Having Trouble with Timer (8051) - any help appreciated

    I am working on a program that takes an input from a switch (connected to P0.0) and causes 4 LEDs to blink. I am using an Atmel 8051 microcontroller. The idea is that if P0.0 is one then the LEDs will blink from lowest to highest with a .25 second delay between blinks. Only one LED will be on at a time. If P0.0 is zero then the LEDs will blink from highest to lowest with a .25 seconds delay. Only one LED will be on at a time.

    The LEDs are connected to P1.0, P1.1, P1.2, P1.3.

    I have written a program in C that does exactly what the above states. I used a continuos loop that had 2 if statements in it. if(P0_0 ==0) and if(P0_0 ==1) to check the input from the switch. Each of these if statments then had code to turn a specific port on/off and delay a certain amount of time.

    My question is how would i write the code to use one of the controllers onboard timers to set the blinking delay to .25 seconds. Would i be in Timer mode 0 or 1? Would i have the clock single or double clocked?

    The crystal speed we are using is 28.2076 MHz

    Any information would be extremely helpful. Thanks in advance

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,905
    I suggest you consult your documentation for your development board and the micro-controller you are using. Check the manufacture's web site. Quite often there are some very good sample programs you can take and modify for your usage.

    Jim

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,500
    Read section 2.9 of this - http://www.atmel.com/Images/doc4316.pdf

    Don't forget to Google - Atmel 8051 timer interrupt tutorial c language

    avrfreaks is a good website for Atmel development
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 8051 micro controller programming
    By vineeth v s in forum C Programming
    Replies: 4
    Last Post: 07-19-2011, 11:08 AM
  2. 8051 tacho
    By CoCo in forum C Programming
    Replies: 7
    Last Post: 04-05-2011, 10:31 AM
  3. Replies: 4
    Last Post: 12-20-2007, 07:55 PM
  4. Timer trouble.
    By antex in forum C# Programming
    Replies: 4
    Last Post: 06-23-2006, 10:22 AM
  5. 8051 microcontrollers
    By ygfperson in forum Tech Board
    Replies: 5
    Last Post: 12-02-2002, 12:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21