 |
www.elektronik.si Forum o elektrotehniki in računalništvu
|
Poglej prejšnjo temo :: Poglej naslednjo temo |
Avtor |
Sporočilo |
sonyx Član


Pridružen-a: Sob 06 Okt 2007 10:27 Prispevkov: 453 Aktiv.: 2.10 Kraj: Sevnica
|
|
Nazaj na vrh |
|
 |
japina Član


Pridružen-a: Čet 02 Jun 2011 15:30 Prispevkov: 90 Aktiv.: 0.53 Kraj: Šentrupert na Dolenjskem
|
Objavljeno: Sre Jan 08, 2014 7:30 am Naslov sporočila: |
|
|
Najlažje bi bilo, če ne rabiš točno 60 sekund ampak približek.
Potem dodaš primerno številko zank in bo to dovolj. Nekaj takega:
i=0;
while(i<65000){
i++;
}
In to nekajkrat ponoviš (če je potrebno).
Sicer pa si poglej programiranje timerja.
|
|
Nazaj na vrh |
|
 |
forest70 Član


Pridružen-a: Ned 20 Jul 2008 1:00 Prispevkov: 588 Aktiv.: 2.86 Kraj: Koper
|
Objavljeno: Sre Jan 08, 2014 10:30 am Naslov sporočila: |
|
|
Sicer je ta koda za Code vision AVR, vendar boš dobil idejo kako to rešit!
Koda: |
#include <mega8.h>
// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1H=0x85EE >> 8;
TCNT1L=0x85EE & 0xff;
// Place your code here
timer60s++;
}
// Declare your global variables here
unsigned char timer60s=0;
void main(void)
{
// Declare your local variables here
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x20;
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 31,250 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x04;
TCNT1H=0x85;
TCNT1L=0xEE;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x05;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Global enable interrupts
#asm("sei")
#define LED PORTC.5;
#define Senzor PINB.2;
while (1)
{
if (Senzor & !LED)
{
timer60s=0;
LED = 1;
}
if (!Senzor)
{
LED=0;
}
if (timer60s >60 & Senzor)
{
LED=0;
}
if (timer60s >60 & !Senzor)
{
timer60s=0;
}
}
} |
|
|
Nazaj na vrh |
|
 |
|
|
Ne, ne moreš dodajati novih tem v tem forumu Ne, ne moreš odgovarjati na teme v tem forumu Ne, ne moreš urejati svojih prispevkov v tem forumu Ne, ne moreš brisati svojih prispevkov v tem forumu Ne ne moreš glasovati v anketi v tem forumu Ne, ne moreš pripeti datotek v tem forumu Ne, ne moreš povleči datotek v tem forumu
|
Uptime: 493 dni
Powered by phpBB © 2001, 2005 phpBB Group
|