Subversion Repositories group.electronics

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 pfowler 1
#include <avr/io.h>
2
#include <avr/wdt.h>
3
#include <avr/interrupt.h>
4
#include <string.h>
5
#include <util/delay.h>
6
#include <stdlib.h>
7
 
8
#include "config.h"
9
#include "avrutil.h"
10
#include "hc595.h"
11
#include "twires.h"
12
 
13
 
14
#ifndef NULL
15
#define NULL    ((void *)0)
16
#endif
17
 
18
 
19
void writeSegment(uint8_t digit, uint8_t value);
20
void pcInterrupt(void);
21
void receiveEvent(uint8_t bytes);
22
 
23
/* ------------------------------------------------------------------------- */
24
 
25
 
26
 
27
volatile uint8_t user_debug = 0;
28
volatile uint8_t tmr0_ovf = 0;
29
 
30
int main(void) {
31
 
32
  /*
33
  DDR : 1 = Output, 0 = Input
34
  PORT: 1 = Pullup for Input, otherwise set output
35
  PIN : Read input pin
36
 
132 pfowler 37
	PB0     -
38
	PB1     - 		- USB D- Low Speed
39
	PB2     -		- USB D+ 
40
	PB3     - 		- SDA i2c bb
41
	PB4	-		- SCL i2c bb
42
	PB5	-
130 pfowler 43
  */
44
  DDRB          = 0B00000000;
132 pfowler 45
  PORTB         = 0B00000000;
130 pfowler 46
 
47
    systime = 0;
48
    sysclockInit();
49
 
50
    wdt_enable(WDTO_1S);	// Watchdog for 1 sec
131 pfowler 51
    sei();			// Enable interrupts
130 pfowler 52
 
53
    for(;;){
54
    	 wdt_reset();
55
 
56
    	if (user_debug) {
132 pfowler 57
 
130 pfowler 58
    	}
59
 
60
    }
61
    return 0;
62
}
63
 
132 pfowler 64
ISR(TIM0_OVF_vect) {
130 pfowler 65
 
132 pfowler 66
	tmr0_ovf++;
130 pfowler 67
 
68
	// Clk/1 TCCR0B = (1<< CS00);
69
	//20.0Mhz, 1ms = 78ovf
70
	//16.5Mhz, 1ms = 64ovf
71
	//16.0Mhz, 1ms = 62ovf
72
	//12.0Mhz, 1ms = 46ovf
73
	// 8.0Mhz, 1ms = 31ovf
131 pfowler 74
	// 8.0Mhz, .5ms = 15ovf, 160r
130 pfowler 75
 
132 pfowler 76
	if (tmr0_ovf>=64) {
130 pfowler 77
			systime++;
78
			tmr0_ovf = 0;
79
	}
80
 
81
}