Kod: Zaznacz cały
#define F_CPU 4000000
#define UART_BAUD 9600
const char ADR[2] = "AA";
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "uart.c"
#include "MB.c"
FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
char buff[100];
int d = 10;
SIGNAL (SIG_UART_RECV){
int ret = MB_Read(buff);
switch (ret){
case 4:
sscanf(buff, "%X", &d);
printf("delay changed to %d\n", d);
break;
}
printf("*** funkcja: %d , dane: %s\n", ret, buff);
}
int main(void)
{
uart_init();
sei();
stdout = stdin = &uart_str;
DDRB = 0xFF;
DDRD = 0xFF;
DDRC = 0x00;
PORTC = 0x00;
TCCR1A = _BV(COM1A1)|_BV(COM1A0)|_BV(WGM10)|_BV(WGM11);
TCCR1B = _BV(CS00);
OCR1A = 1023;
printf("\nHello world!\n");
while(1){
sbi(PORTD, 7);
for(int i = d; i>0; i--) _delay_ms(10);
cbi(PORTD, 7);
for(int i = d; i>0; i--) _delay_ms(10);
//printf("%d", d);
}
return(0);
}
Przy okazji jeszcze jedno pytanie. Korzystam z funkcji _delay_ms(), jeśli podam jako argument stałą liczbę (np. 10 tak jak w programie) to jest ok, ale jak podam jako argument zmienną to wszystko ładnie się kompiluje ale objętość programu wzrasta dwukrotnie i nie mieści się już w pamięci. Dlaczego tak się dzieje?