D
david90
Guest
Her er min færdig kode (til mig
<img src="http://www.edaboard.com/images/smiles/icon_neutral.gif" alt="Neutral" border="0" />
) Denne kode er for WINAVR GCC-compiler, og det er for Atmel MCU AT90S2313.
Kode:# include <avr/io.h>
# include <avr/interrupt.h>
# include <avr/signal.h>void delay (void);
void display7seg (void);flygtige uint16_t pulser = 0, km / h = 0, mph_result = 0;
int hun_mi, ten_mi, one_mi, hun_mph, ten_mph, one_mph;
const char segment_table [10] =
(
0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x2, 0x78, 0, 0x10
);int main (void)
(
DDRB = 0xff; / / sæt PORTB som output
DDRD = 0x77;
TCCR0 = 0x03; / / forsinkelse timerTCNT1H = 0xC9;
TCNT1L = 0x85;
TCCR1B = 0x5; / / clk/1024 TCCR1B = 0x5; / / clk/1024
TIMSK = 0x80;MCUCR = 0x08;
SREG = 0x80;
GIMSK = 0x80;
while (1) / / Forever
(
display7seg ();
)
return 0;
)void forsinkelse (void) / / Udarbejdelse af en forsinkelse på 65 ms på 4 MHz
(
TCNT0 = 0x7F;
while (! (TIFR & 0x02));
/ / Vent til timer0 overflow flag, der skal fastsættes
TIFR = 0x02; / / Clear overflow flag
)
void display7seg (void)
(hun_mi = (pulser) / 100;
ten_mi = ((pulser)% 100) / 10;
one_mi = ((pulser)% 100)% 10;hun_mph = (mph_result) / 100;
ten_mph = ((mph_result)% 100) / 10;
one_mph = ((mph_result)% 100)% 10;PORTB = segment_table [hun_mi];
PORTD = 0x7B;
forsinkelse ();
PORTB = segment_table [ten_mi];
PORTD = 0x7D;
forsinkelse ();
PORTB = segment_table [one_mi];
PORTD = 0x7E;
forsinkelse ();PORTB = segment_table [hun_mph];
PORTD = 0x6F;
forsinkelse ();
PORTB = segment_table [ten_mph];
PORTD = 0x5F;
forsinkelse ();
PORTB = segment_table [one_mph];
PORTD = 0x3F;
forsinkelse ();
)Interrupt (SIG_INTERRUPT1)
(
if ( bælgfrugter == 999)
(
pulser = 0;
)
km / h ;
)
Interrupt (SIG_OVERFLOW1)
(
mph_result = km / h *. 08.863;
km / h = 0;
TCNT1H = 0xC9;
TCNT1L = 0x61;
)
<img src="http://www.edaboard.com/images/smiles/icon_neutral.gif" alt="Neutral" border="0" />
) Denne kode er for WINAVR GCC-compiler, og det er for Atmel MCU AT90S2313.
Kode:# include <avr/io.h>
# include <avr/interrupt.h>
# include <avr/signal.h>void delay (void);
void display7seg (void);flygtige uint16_t pulser = 0, km / h = 0, mph_result = 0;
int hun_mi, ten_mi, one_mi, hun_mph, ten_mph, one_mph;
const char segment_table [10] =
(
0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x2, 0x78, 0, 0x10
);int main (void)
(
DDRB = 0xff; / / sæt PORTB som output
DDRD = 0x77;
TCCR0 = 0x03; / / forsinkelse timerTCNT1H = 0xC9;
TCNT1L = 0x85;
TCCR1B = 0x5; / / clk/1024 TCCR1B = 0x5; / / clk/1024
TIMSK = 0x80;MCUCR = 0x08;
SREG = 0x80;
GIMSK = 0x80;
while (1) / / Forever
(
display7seg ();
)
return 0;
)void forsinkelse (void) / / Udarbejdelse af en forsinkelse på 65 ms på 4 MHz
(
TCNT0 = 0x7F;
while (! (TIFR & 0x02));
/ / Vent til timer0 overflow flag, der skal fastsættes
TIFR = 0x02; / / Clear overflow flag
)
void display7seg (void)
(hun_mi = (pulser) / 100;
ten_mi = ((pulser)% 100) / 10;
one_mi = ((pulser)% 100)% 10;hun_mph = (mph_result) / 100;
ten_mph = ((mph_result)% 100) / 10;
one_mph = ((mph_result)% 100)% 10;PORTB = segment_table [hun_mi];
PORTD = 0x7B;
forsinkelse ();
PORTB = segment_table [ten_mi];
PORTD = 0x7D;
forsinkelse ();
PORTB = segment_table [one_mi];
PORTD = 0x7E;
forsinkelse ();PORTB = segment_table [hun_mph];
PORTD = 0x6F;
forsinkelse ();
PORTB = segment_table [ten_mph];
PORTD = 0x5F;
forsinkelse ();
PORTB = segment_table [one_mph];
PORTD = 0x3F;
forsinkelse ();
)Interrupt (SIG_INTERRUPT1)
(
if ( bælgfrugter == 999)
(
pulser = 0;
)
km / h ;
)
Interrupt (SIG_OVERFLOW1)
(
mph_result = km / h *. 08.863;
km / h = 0;
TCNT1H = 0xC9;
TCNT1L = 0x61;
)