hc6811, trying to make lights flash

Discussion in 'The Projects Forum' started by fortune2k, Mar 18, 2009.

  1. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    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 ( (Unknown Language)):
    1.  
    2.         DDRA = 0xff;
    3.         mask = 1;    //reset mask to one before each iteration
    4.         for (i = 0; i < 6; i++)  // 6 lights soo loop 6 times
    5.         {
    6.             if(port & mask)
    7.             {
    8.             PORTA ^= mask;
    9.             }
    10.  
    11.             else //if port=0 turn the lights off
    12.             {
    13.             PORTA = 0x00;
    14.             }
    15.             mask <<=1;    //check next bit
    16.      
    17.         }
    18.        

    thankyou
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    I don't know the exact instructions for AVRs but you can say:

    turn on lights
    delay(x)
    turn off lights
    delay (x)

    The (x) can be a variable as to be able to vary the delay by reading a value from a port.
     
  3. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    yea ive tryed using delay.h and delay() it doesnt seem to work however thats the way i want to do it . i also heard you can use a hardware timer but i havent found any material on them . Im really stuck and need these lights to flash :(:(
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    You can use the internal timers of the uC and fire interrupts at the flashing rate you want. However this is more complicated if you are new to this subject.
    I can't help you because I have never used AVRs. From the code I think you are using an AVR, aren't you?
     
  5. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0

    lol whats a AVR, and yes im extremely new
     
  6. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Which microcontroller are you using?
     
  7. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    im using the motorola hc6811 board with a i/o box for switches and lights
     
  8. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    oh i also use a bat file called CRAM to compile it soo i can upload it to the board
     
  9. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    i have heard i can use a hardware timer and came across this code
    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <stdio.h>     /*standard i/o functions*/
    4.  
    5. void timer(void);
    6.  
    7. int hours, mins, secs, ticks, times;    /*Global Variables for returning values*/
    8. unsigned char *padr,*paddr, *tflg2, *pact1, *tmsk2;
    9.  
    10. void main(void)
    11. {
    12.     padr=(unsigned char*)0x0;
    13.     paddr=(unsigned char*)0x1;
    14.     tmsk2=(unsigned char*)0x24;
    15.     tflg2=(unsigned char*)0x25;
    16.     pact1=(unsigned char*)0x26;
    17.    
    18.     *paddr=0xff;
    19.     *pact1=0x03;
    20.     *tmsk2=0x40;
    21.  
    22.     for(;;)
    23.     {
    24.         if (ticks==0 && times==0){        /*print out once a sec*?*/
    25.        
    26.             printf("%2i:%2i:%2i\r", hours, mins, secs);
    27.             times=1;
    28.             }
    29.         if (ticks==1) times=0;
    30.     }
    31. }
    32.  
    33. @interrupt void timer(void){
    34.         ticks++;
    35.         if (ticks==30){
    36.             ticks=0;
    37.             secs++;
    38.             if(*padr==0){
    39.                 *padr=0xff;
    40.             }
    41.             else *padr=0x0;        /* Flash Lights */
    42.         }
    43.             if (secs==60){
    44.                 secs=0;
    45.                 mins++;
    46.             }
    47.             if (mins==60){
    48.                 mins=0;
    49.                 hours++;
    50.             }
    51.             if (hours==24){
    52.                 hours=0;
    53.             }
    54.             *tflg2=0x40;        /*reset RTI flag**/
    55.  
    56.         }
    57.  

    i dont understand what this piece of code does and i cant get it running but apparently thats a timer and that may be a way to do it
     
  10. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    Code ( (Unknown Language)):
    1.  
    2. #include <mega16.h>
    3. #include <delay.h>
    4.  
    5.  void main(void)
    6.  {
    7.     // DDRA=0x01;
    8.     while(1)
    9.     {
    10.       printf("port1 1");//PORTA=0x01;
    11.       delay_ms(500);
    12.       printf("port1 0");//PORTA=0x00;
    13.       delay_ms(500);
    14.     }
    15.  }
    16.  
    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?
     
  11. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    I am not the one who can help you, I have never used this thing.
     
  12. fortune2k

    Thread Starter Member

    Mar 18, 2009
    19
    0
    well is there anyone on here that can offer me a little help please i am grateful for every bit of help i am struggling badly here.
     
Loading...