103 lines
1.5 KiB
C
103 lines
1.5 KiB
C
#include <avr/io.h>
|
|
#include <avr/sleep.h>
|
|
#include <avr/wdt.h>
|
|
#include <avr/interrupt.h>
|
|
#include <avr/power.h>
|
|
#include <avr/pgmspace.h>
|
|
//#include <avr/eeprom.h>
|
|
#include <util/delay.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "defines.h"
|
|
#include "lcd.h"
|
|
#include "spi.h"
|
|
#include "rf24.h"
|
|
|
|
int main (void);
|
|
void setup (void);
|
|
void loop (void);
|
|
void lcdprint( char* ptr);
|
|
|
|
|
|
int main(void)
|
|
{
|
|
setup();
|
|
while (1)
|
|
loop();
|
|
}
|
|
|
|
void setup(void)
|
|
{
|
|
lcd_init(20,4);
|
|
lcd_backlight(1);
|
|
lcd_clear();
|
|
lcd_home();
|
|
lcdprint("Pyro RF ! ");
|
|
|
|
spi_init_master();
|
|
|
|
rf24_init();
|
|
|
|
char st = rf24_read_reg(CONFIG);
|
|
debughex(&st,1);
|
|
|
|
#if defined(__AVR_ATmega32A__)
|
|
// setup Timer1
|
|
TCCR1A = 0;
|
|
TCNT1=0;
|
|
OCR1A = 2000;
|
|
TIMSK = _BV(OCIE1A);
|
|
TCCR1B = _BV(WGM12)|_BV(CS11);
|
|
#elif defined(__AVR_ATmega2560__)
|
|
// setup Timer1
|
|
TCCR1A = 0;
|
|
TCNT1=0;
|
|
OCR1A = 10000;
|
|
TIMSK1 = _BV(OCIE1A);
|
|
TCCR1B = _BV(WGM12)|_BV(CS11);
|
|
#endif
|
|
|
|
sei();
|
|
|
|
}
|
|
|
|
volatile int i=0,j=0;
|
|
volatile int u=0;
|
|
|
|
void loop(void)
|
|
{ if(!u){
|
|
u=20;
|
|
char buf[15];
|
|
lcd_setCursor(0,1);
|
|
snprintf(buf,15,"%d %d ",i,j++);
|
|
lcdprint(buf);
|
|
}
|
|
set_sleep_mode(SLEEP_MODE_IDLE);
|
|
sleep_mode();
|
|
}
|
|
|
|
|
|
ISR(TIMER1_COMPA_vect){
|
|
i+=5;
|
|
if(u)u--;
|
|
}
|
|
|
|
void lcdprint( char* ptr)
|
|
{
|
|
while (*ptr) lcd_write(*ptr++);
|
|
}
|
|
|
|
|
|
void debughex (char* ptr,uint8_t len) {
|
|
while (len--) {
|
|
uint8_t c = *(ptr++);
|
|
uint8_t ch= c>>4;
|
|
c &= 0x0F;
|
|
lcd_write(ch>9?ch+'A'-10:ch+'0');
|
|
lcd_write(c>9?c+'A'-10:c+'0');
|
|
}
|
|
}
|
|
|
|
|