Thread: 1 flash per second , micocontrollers, while loop

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by fortune2k View Post
    well that code doesnt run sooo i cant see how its working whats missing then i can play around with it and maybe get somewhere
    Right, this is embedded programming. We can not tell you what is or isn't there if we haven't got specs for the same compiler and board as you are using. Because these things are not part of the STANDARD C language and libraries, and it's not Windows or Linux which we would know how to help with.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    agh well scrap that idea then sorry.
    well i need to make a function to delay my program by 0.5 seconds i tried adaks idea using :
    #include <dos.h> that seems what i need but i dont have the dos.h file and i dont know where to get it / where to install it . i havent got any idea of how to approach this now lol

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right. dos.h is a "MS-DOS" file for Turbo C. Since you are (highly unlikely at least) not using MS-DOS or a derivative and not using Turbo C, trying to get that file to your machine will not work.

    Do you have a tutor that can help you with regards to how to get an interrupt going, perhaps? That is really the RIGHT solution, in my mind.
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Quote Originally Posted by matsp View Post
    Right. dos.h is a "MS-DOS" file for Turbo C. Since you are (highly unlikely at least) not using MS-DOS or a derivative and not using Turbo C, trying to get that file to your machine will not work.

    Do you have a tutor that can help you with regards to how to get an interrupt going, perhaps? That is really the RIGHT solution, in my mind.
    --
    Mats
    unfortunately my tutor is away and i have no 1 and my hand in date is on friday all i remember in the past is someone mentioning using the hardware timer, or tweaking a while look . but my while loop is bad it messes up and i cant find anything on hardware timers soo i dont know

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In your post #13 of this thread, you had code that looked "close".

    I did not see a call in main to the function timer, however.

    If you added that call, inside the for( ;; ) loop, would that help it run?
    Last edited by Adak; 03-17-2009 at 11:48 AM.

  6. #21
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Quote Originally Posted by Adak View Post
    In your post #13 of this thread, you had code that looked "close".

    I did not see a call in main to the function timer, however.

    If you added that call, inside the for( ;; ) loop, would that help it run?
    i pulled that code off the net and dont have a clue yea it looks kinda what im after but i need to find some reading material on it sooo i can implement it into my code anyone got any links? i think thats a timer
    thanks
    Last edited by fortune2k; 03-17-2009 at 11:54 AM.

  7. #22
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I was just about to Google your board and see what's out there.

    I don't know anything about CRAM or that board, so I'm stuffed.

  8. #23
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    its a motorola hc6811 i may of mis typed it . yea im trying to find info about hardware timers

  9. #24
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I found an example of a timer program for that microcontroller. As I read the program, I noticed that it had the header:

    #include <timer.h>

    If you compiler has that file, delay() may be in it?

    Anyway, the link, and the program can be found here:
    http://www.gnu.org/software/m68hc11/...#smallExamples

    Hope that helps, they have several example programs.

  10. #25
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Quote Originally Posted by Adak View Post
    I found an example of a timer program for that microcontroller. As I read the program, I noticed that it had the header:

    #include <timer.h>

    If you compiler has that file, delay() may be in it?

    Anyway, the link, and the program can be found here:
    http://www.gnu.org/software/m68hc11/...#smallExamples

    Hope that helps, they have several example programs.
    i shall have a look and test it out, cheers

  11. #26
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    right my compiler doesnt use timer.h next option any more ideas?

  12. #27
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    hi
    Code:
    int hours, mins, secs, ticks, times;	/*Global Variables for returning values*/
    unsigned char *tflg2, *pact1, *tmsk2;
    @interrupt void timer(void){
    		ticks++;
    		if (ticks==30){
    			ticks=0;
    			secs++;
    			}
    		if (secs==60){
    				secs=0;
    				mins++;
    			}
    			if (mins==60){
    				mins=0;
    				hours++;
    			}
    			if (hours==24){
    				hours=0;
    			}
    			*tflg2=0x40;		/*reset RTI flag**/
    
    		}
    this seems to be what i am looking for but i dont understand what it is doing ? this is all i can find

  13. #28
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'd contact Abachler. He said he's willing to help and has worked with these boards for years. I'd suggest doing that right away.

    I liked the longer version of this program I think, better. The one that looked "close", but didn't seem to call the timer function.

    I would add in the call to the timer function inside the for( ;; ) loop, and see what it can do.

    I'm sure there must be forums or newsgroups dedicated to these popular microcontrollers.

    If all else fails, call a supplier or help desk that sells that board, and tell them you need a bit of help with this.

    Good luck.

  14. #29
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    Hi im working on a project for school and i have got stuck. I am making a burglar alarm which is meant to make the lights at different speeds depending if the zone is armed, or triggerd. what i am trying to do atm is get my lgiths to flash i can get them to come on fine but i cant get them to flash i need to get the lights to be on for 0.5 secounds then off for 0.5 secounds.


    i have 6zones which represented by 6 lights and depending on the value of port it will make them on or off and what im trying to do is make them flash now and i dont know how.

    how can i make them flash, i kinda want like a delay function which i can call upon so i can.

    below is a bit of my code the bit that makes the lights come on

    Code:
            DDRA = 0xff; 
            mask = 1;    //reset mask to one before each iteration 
            for (i = 0; i < 6; i++)  // 6 lights soo loop 6 times
            { 
                if(port & mask) 
                { 
                PORTA ^= mask; 
                } 
    
                else //if port=0 turn the lights off
                { 
                PORTA = 0x00; 
                } 
                mask <<=1;    //check next bit 
         
            }
    thankyou
    hmmmm i have sent a messege nothing back

    what im after is

    while 1
    {
    LIGHT ON
    delay 0.5 secs
    LIGHT OFF
    delay 0.5 secs
    }


    thats an idea of what i want however i dont know how to do it + there is funny header files i dont have n stuff like dos.h and delay.h

    Code:
    #include <mega16.h>
    #include <delay.h>
    
     void main(void)
     {
        // DDRA=0x01;
        while(1)
        {
          printf("port1 1");//PORTA=0x01;
          delay_ms(500);
          printf("port1 0");//PORTA=0x00;
          delay_ms(500);
        }
     }
    that above would be perfect but i dont have half the header files nor do i know how to install them.. if i got the header files and put them where they were needed could i use somthing like this in my prog? and it run on the hc11 board?
    Last edited by fortune2k; 03-18-2009 at 02:32 PM.

  15. #30
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    yeah i got his email, but he has his board settings set to not receive email, so he shoudl probably ask the questions here. In responce to his email, here is my advice.

    The central element of the main timer is the free running 16 bit counter. This counter starts at 0000 on system reset and counts up to FFFF. The timer count register (TCNT) is read using a double byte load operation such as load D (LDD) or load X (LDX)

    so to break ti down, write a value of 3 to $1024 and then read the byte at $100E, if the high order bit is high, sound the beeper, if the high order bit is low, do not soudn it, this assumes a clock rate of 2MHz and will yield a buzz rate of ~250ms on 250ms off, if you want to reduce this further, you need to impliment that code, btu this should get you started using the hardware timer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  3. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM