-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.c
106 lines (100 loc) · 2.96 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define F_CPU 16000000UL //16mhz
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "TouchScreen.h"
#include "TFT.h"
#include "config.h"
#include "twicam.h"
#include "camregdef.h"
#include "gammaedit.h"
#include "selections.h"
void menu(void);
//OV7670 undocumented register 1F is called LAEC this means exposures less than one line
#ifdef haveSDcard
#include "ff.h" /* Declarations of FatFs API */
#include "mmc.h"
//volatile uint16_t Timer; /* Performance timer (100Hz increment) */
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC2 */
/*---------------------------------------------------------*/
ISR(TIMER2_COMPA_vect){
//PORTG|=1<<5;
//++Timer; /* Performance counter for this module */
disk_timerproc(); /* Drive timer procedure of low level disk I/O module */
//PORTG&=~(1<<5);
}
/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from */
/* FatFs module. Any valid time must be returned even if */
/* the system does not support a real time clock. */
/* This is not required in read-only configuration. */
uint32_t get_fattime(void){
/*RTC rtc;
if (!RtcOk) return 0;
// Get local time
rtc_gettime(&rtc);*/
/* Pack date and time into a DWORD variable */
return ((uint32_t)(2013 - 1980) << 25)
| ((uint32_t)10 << 21)
| ((uint32_t)27 << 16)
| ((uint32_t)11 << 11)
| ((uint32_t)0 << 5)
| ((uint32_t)0 >> 1);
}
#endif
void main(void){
DDRL|=8;
ASSR &= (uint8_t)~(_BV(EXCLK) | _BV(AS2));
//generate 8mhz clock
TCCR5A=67;
TCCR5B=17;
DDRC=0;//set ov7670 pins to input
#ifdef MT9D111
OCR5A=2;//Formula for output clock is F_CPU/(2(x+1))
#else
OCR5A=0;
#endif
DDRC=0;
DDRG|=1<<5;
UBRR0H=0;
UCSR0A|=2;//double speed aysnc
UBRR0L=3;//0 = 2m 1= 1m 3 = 0.5M 2M baud rate = 0 7 = 250k 207 is 9600 baud rate
UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter
UCSR0C=6;//async 1 stop bit 8bit char no parity bits
ADCSRA=(1<<ADEN)|(1<<ADPS2);//enable ADC
uint8_t error;
tft_init();//init TFT library
tft_setDisplayDirect(DOWN2UP);
#ifdef haveSDcard
OCR2A = 155;//F_CPU / 1024 / 100 - 1;
TCCR2A=2;//CTC mode
TCCR2B=7;//F_CPU/1024
TIMSK2 |= (1<<OCIE2A);
disk_timerproc();
#endif
sei();
TWSR&=(uint8_t)~3;//disable prescaler for TWI
TWBR=72;//set to 100khz
#ifdef ov7670
configSel();
#else
initCam();
#endif
//try writing to sd card
#ifdef haveSDcard
tft_drawStringP(PSTR("About to initialize"),24,320,1,WHITE);
//UINT bw;
disk_initialize(0);
tft_drawStringP(PSTR("Initialized"),32,320,1,WHITE);
f_mount(&FatFs, "0:", 0); /* Give a work area to the default drive */
tft_drawStringP(PSTR("Mounted"),40,320,1,WHITE);
#endif
menu();
}