hc6811, trying to make lights flash

Thread Starter

fortune2k

Joined Mar 18, 2009
19
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

Rich (BB 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
 

mik3

Joined Feb 4, 2008
4,843
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.
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
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.
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 :(:(
 

mik3

Joined Feb 4, 2008
4,843
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?
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
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?

lol whats a AVR, and yes im extremely new
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
i have heard i can use a hardware timer and came across this code
Rich (BB code):
#include <stdio.h>     /*standard i/o functions*/

void timer(void);

int hours, mins, secs, ticks, times;    /*Global Variables for returning values*/
unsigned char *padr,*paddr, *tflg2, *pact1, *tmsk2;

void main(void)
{
    padr=(unsigned char*)0x0;
    paddr=(unsigned char*)0x1;
    tmsk2=(unsigned char*)0x24;
    tflg2=(unsigned char*)0x25;
    pact1=(unsigned char*)0x26;
    
    *paddr=0xff;
    *pact1=0x03;
    *tmsk2=0x40;

    for(;;)
    {
        if (ticks==0 && times==0){        /*print out once a sec*?*/
        
            printf("%2i:%2i:%2i\r", hours, mins, secs);
            times=1;
            }
        if (ticks==1) times=0;
    }
}

@interrupt void timer(void){
        ticks++;
        if (ticks==30){
            ticks=0;
            secs++;
            if(*padr==0){
                *padr=0xff;
            }
            else *padr=0x0;        /* Flash Lights */
        }
            if (secs==60){
                secs=0;
                mins++;
            }
            if (mins==60){
                mins=0;
                hours++;
            }
            if (hours==24){
                hours=0;
            }
            *tflg2=0x40;        /*reset RTI flag**/

        }

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
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
Rich (BB 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?
 

Thread Starter

fortune2k

Joined Mar 18, 2009
19
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.
 
Top