-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
168 lines (132 loc) · 5.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
Generated Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC16F1705
Driver Version : 2.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
FOR A PARTICULAR PURPOSE.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
SOFTWARE.
*/
#include "mcc_generated_files/mcc.h"
#include <stdlib.h>
#include "lib/OLED.h"
#define NUMBER_OF_ARRAY 64
// 0-9
const unsigned char myASCII[][8] = {
{0b11111110, 0b11000010, 0b10100010, 0b10010010, 0b10001010, 0b10000110, 0b11111110, 0b00000000}, // 0
{0b10000010, 0b10000010, 0b10000010, 0b11111110, 0b10000000, 0b10000000, 0b10000000, 0b00000000}, // 1
{0b11110010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10011110, 0b00000000}, // 2
{0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b11111110, 0b00000000}, // 3
{0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b11111110, 0b00000000}, // 4
{0b10011110, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b11110010, 0b00000000}, // 5
{0b11111110, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b11110010, 0b00000000}, // 6
{0b00000010, 0b00000010, 0b00000010, 0b11110010, 0b00001010, 0b00000110, 0b00000010, 0b00000000}, // 7
{0b11111110, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b11111110, 0b00000000}, // 8
{0b10011110, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b10010010, 0b11111110, 0b00000000}, // 9
};
uint8_t getNewWaitTime (uint8_t wait) {
uint8_t newWait = 0;
if (wait > 4) {
newWait = rand() % 4;
} else {
uint8_t randNum = rand() % 100;
if (randNum == 0) {
newWait = rand() % 255;
} else if (randNum < 5) {
newWait = rand() % 192;
} else {
newWait = rand() % 32;
}
}
newWait += 1;
return newWait;
}
/*
Main application
*/
void main(void)
{
// initialize the device
SYSTEM_Initialize();
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
// My settings
TMR2_StopTimer();
// Lazy seed to replace from time(NULL) because it returns always 0 without RTCC
srand((unsigned int) rand());
__delay_ms(1000);
OLED_Init();
OLED_Clear();
__delay_ms(1000);
TMR2_StartTimer();
uint8_t wait = 0;
int i = 0;
int j = 0;
int tmpNum = 0;
// Maximum number of array: 80
// Initialize number, current, time
uint8_t numbers[NUMBER_OF_ARRAY] = {0};
uint8_t currents[NUMBER_OF_ARRAY] = {0};
uint8_t waits[NUMBER_OF_ARRAY] = {0};
for (i = 0; i < sizeof(numbers); i++) {
wait = (rand() % 10 == 1) ? rand() % 4 + 1 : rand() % 96 + 1;
numbers[i] = rand() % 10;
currents[i] = wait;
waits[i] = wait;
}
// Display and count down numbers
while (1)
{
tmpNum = 0;
OLED_SelectPage(0);
for (i = 0; i < sizeof(numbers); i++) {
for (j = 0; j < 8; j++) {
tmpNum = numbers[i];
OLED_Data(myASCII[tmpNum][j]);
}
currents[i]--;
if (currents[i] <= 0) {
tmpNum--;
if (tmpNum == 0) {
waits[i] = getNewWaitTime(waits[i]);
} else if (tmpNum < 0) {
tmpNum = 9;
}
currents[i] = waits[i];
}
numbers[i] = (uint8_t) tmpNum;
}
}
}
/**
End of File
*/